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