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