本文整理汇总了Python中buffer.Buffer.get方法的典型用法代码示例。如果您正苦于以下问题:Python Buffer.get方法的具体用法?Python Buffer.get怎么用?Python Buffer.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类buffer.Buffer
的用法示例。
在下文中一共展示了Buffer.get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse
# 需要导入模块: from buffer import Buffer [as 别名]
# 或者: from buffer.Buffer import get [as 别名]
def parse(cls,buffer):
rname = buffer.decode_name()
rtype,rclass,ttl,rdlength = buffer.unpack("!HHIH")
if rtype == QTYPE.OPT:
options = []
option_buffer = Buffer(buffer.get(rdlength))
while option_buffer.remaining() > 4:
code,length = option_buffer.unpack("!HH")
data = option_buffer.get(length)
options.append(EDNSOption(code,data))
rdata = options
else:
rdata = RDMAP.get(QTYPE[rtype],RD).parse(buffer,rdlength)
return cls(rname,rtype,rclass,ttl,rdata)
示例2: __init__
# 需要导入模块: from buffer import Buffer [as 别名]
# 或者: from buffer.Buffer import get [as 别名]
class WoOram:
def __init__(self, backend, sup, drip_rate, drip_time):
self.backend = backend
self.vtable = sup.vtable
self.blocksize = sup.blocksize
self.headerlen = sup.headerlen
self.N = sup.total_blocks
self.K = drip_rate
self.T = drip_time
self.fbsize = sup.fbsize
self.split_maxnum = sup.split_maxnum
self.split_maxsize = sup.split_maxsize
self.buf = Buffer()
self.rlock, self.wlock = get_rw_locks()
self.syncer = Syncer(self, self.T)
self.active = False # is the sync thread running
self.syncing = False # is a sync operation in progress
self.recent = None # set of (vnode, boff) pairs for what has changed during the sync op
def start(self):
if self.T > 0:
self.active = True
self.syncer.start()
else:
print("NOTE: sync thread not actually started...")
def finish(self):
"""Waits until the buffer has been cleared, then stops the syncer and returns."""
if self.active:
self.active = False
print("Waiting for the sync thread to finish...", file=sys.stderr)
self.syncer.join()
def __enter__(self):
self.start()
return self
def __exit__(self, et, ev, tb):
self.finish()
def __len__(self):
"""Returns the number of distinct items stored (i.e., # of vnodes)"""
return len(self.vtable)
def size(self):
"""Returns the total size (in bytes) of all items stored. (Warning: slow)"""
with self.rlock:
return sum(self.get_size(v) for v in self.vtable)
def num_blocks(self, vnode):
"""Returns the number of blocks this file occupies."""
return len(self.vtable.get_info(vnode).inodes)
def get_size(self, vnode):
"""The number of bytes of data stored for the given object."""
return self.vtable.get_size(vnode)
def get_mtime(self, vnode):
"""The last modification time of the given object."""
return self.vtable.get_mtime(vnode)
def set_mtime(self, vnode, when=None):
if when is None:
when = time.time()
self.vtable.set_mtime(vnode, when)
def capacity(self):
"""The total space avaiable (in bytes) in the backend."""
return self.blocksize * self.N
def _make_block(self, b1, b2):
"""Creates a new block with the given contents on either side.
Each should be a Block object.
The block is padded up to self.blocksize.
"""
# TODO make more efficiently indexable storage representation?
block = pickle.dumps((b1.contents, b2.contents))
assert len(block) <= self.blocksize - self.headerlen
return block + b'\0'*(self.blocksize - len(block) - self.headerlen)
def _get_backend(self, ind):
"""Returns a tuple of block objects stored at the given index."""
res = []
try:
raw = self.backend[ind]
except IndexError:
# this could be a normal error, just a new repository
res = None
except:
res = None
print("WARNING: error fetching", ind, "from backend. Maybe wrong key?")
if res is not None:
try:
parts = pickle.loads(raw)
except:
parts = None
if type(parts) is not tuple:
print("WARNING: error unpickling", ind, "from backend")
#.........这里部分代码省略.........