本文整理汇总了Python中buffer.Buffer.append方法的典型用法代码示例。如果您正苦于以下问题:Python Buffer.append方法的具体用法?Python Buffer.append怎么用?Python Buffer.append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类buffer.Buffer
的用法示例。
在下文中一共展示了Buffer.append方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TcpConnection
# 需要导入模块: from buffer import Buffer [as 别名]
# 或者: from buffer.Buffer import append [as 别名]
class TcpConnection(object):
def __init__(self, io_loop, iostream, peer_addr):
"""although iostream has read buffer, but provide a buffer object
is more helpful for upper logic
:param
peer_addr (host, prot)
"""
self.io_loop = io_loop
self._iostream = iostream
self._read_buffer = Buffer()
self._peer_addr = peer_addr
self._connection_cb = None
self._write_complete_cb = None
self._message_cb = None
self._iostream.read_until_close(streaming_callback=self._on_message)
self._is_connected = True
self._context = None
def set_connection_callback(self, callback):
self._connection_cb = callback
def set_message_callback(self, callback):
"""callback(connection, buffer)"""
self._message_cb = callback
def _on_message(self, data):
self._read_buffer.append(data)
if self._message_cb:
self._message_cb(self, self._read_buffer)
def set_write_complete_callback(self, callback):
self._write_complete_cb = callback
def set_close_callback(self, callback):
self._iostream.set_close_callback(lambda: callback(self))
def connect_established(self):
print "connect_established", self.name
if self._connection_cb:
self._connection_cb(self)
def send(self, buffer):
self._iostream.write(buffer.retrieve_all(), self._write_complete_cb)
def shut_down(self):
self._iostream.close()
@property
def name(self):
addr = self._peer_addr
name = (addr[0], ':', str(addr[1]))
return ''.join(name)
def connect_destroyed(self):
"""no need to call self._iostream.close()"""
print "connect_destroyed", self.name
self._is_connected = False
if self._connection_cb:
self._connection_cb(self)
@property
def is_connected(self):
return self._is_connected
@property
def context(self):
return self._context
@context.setter
def context(self, value):
self._context = value
示例2: repr
# 需要导入模块: from buffer import Buffer [as 别名]
# 或者: from buffer.Buffer import append [as 别名]
elif req.event == req.EVENT_FIRST_LINE:
if req.is_request():
print 'first-line: ' + repr('%s %s %s'%(req.method, req.uri, req.version))
else:
print 'first-line: ' + repr('%s %s %s'%(req.version, req.status_code, req.status_text))
"""
for chunk_size in range(3, 6):
buf = Buffer()
req = HttpResponse()
req.CHUNK_SIZE = chunk_size
print '---chunk_size[%d]---'%chunk_size
if 0:
for ch in list(text):
buf.append(ch)
print buf
if proc_recv(req, buf) == -1:
exit(0)
print 'error'
break
if req.event == req.EVENT_READY:
print '------'
req = HttpRequest()
req.CHUNK_SIZE = chunk_size
else:
buf.append(text)
while buf.len() > 0:
if proc_recv(req, buf) == -1:
print 'error'
exit(0)