1b2732e9dSimarom"""Dummy Frame object"""
2b2732e9dSimarom
3b2732e9dSimarom# Copyright (C) PyZMQ Developers
4b2732e9dSimarom# Distributed under the terms of the Modified BSD License.
5b2732e9dSimarom
6b2732e9dSimaromfrom ._cffi import ffi, C
7b2732e9dSimarom
8b2732e9dSimaromimport zmq
9b2732e9dSimaromfrom zmq.utils.strtypes import unicode
10b2732e9dSimarom
11b2732e9dSimaromtry:
12b2732e9dSimarom    view = memoryview
13b2732e9dSimaromexcept NameError:
14b2732e9dSimarom    view = buffer
15b2732e9dSimarom
16b2732e9dSimarom_content = lambda x: x.tobytes() if type(x) == memoryview else x
17b2732e9dSimarom
18b2732e9dSimaromclass Frame(object):
19b2732e9dSimarom    _data = None
20b2732e9dSimarom    tracker = None
21b2732e9dSimarom    closed = False
22b2732e9dSimarom    more = False
23b2732e9dSimarom    buffer = None
24b2732e9dSimarom
25b2732e9dSimarom
26b2732e9dSimarom    def __init__(self, data, track=False):
27b2732e9dSimarom        try:
28b2732e9dSimarom            view(data)
29b2732e9dSimarom        except TypeError:
30b2732e9dSimarom            raise
31b2732e9dSimarom
32b2732e9dSimarom        self._data = data
33b2732e9dSimarom
34b2732e9dSimarom        if isinstance(data, unicode):
35b2732e9dSimarom            raise TypeError("Unicode objects not allowed. Only: str/bytes, " +
36b2732e9dSimarom                            "buffer interfaces.")
37b2732e9dSimarom
38b2732e9dSimarom        self.more = False
39b2732e9dSimarom        self.tracker = None
40b2732e9dSimarom        self.closed = False
41b2732e9dSimarom        if track:
42b2732e9dSimarom            self.tracker = zmq.MessageTracker()
43b2732e9dSimarom
44b2732e9dSimarom        self.buffer = view(self.bytes)
45b2732e9dSimarom
46b2732e9dSimarom    @property
47b2732e9dSimarom    def bytes(self):
48b2732e9dSimarom        data = _content(self._data)
49b2732e9dSimarom        return data
50b2732e9dSimarom
51b2732e9dSimarom    def __len__(self):
52b2732e9dSimarom        return len(self.bytes)
53b2732e9dSimarom
54b2732e9dSimarom    def __eq__(self, other):
55b2732e9dSimarom        return self.bytes == _content(other)
56b2732e9dSimarom
57b2732e9dSimarom    def __str__(self):
58b2732e9dSimarom        if str is unicode:
59b2732e9dSimarom            return self.bytes.decode()
60b2732e9dSimarom        else:
61b2732e9dSimarom            return self.bytes
62b2732e9dSimarom
63b2732e9dSimarom    @property
64b2732e9dSimarom    def done(self):
65b2732e9dSimarom        return True
66b2732e9dSimarom
67b2732e9dSimaromMessage = Frame
68b2732e9dSimarom
69b2732e9dSimarom__all__ = ['Frame', 'Message']
70