本文整理汇总了Python中storage.Storage.push方法的典型用法代码示例。如果您正苦于以下问题:Python Storage.push方法的具体用法?Python Storage.push怎么用?Python Storage.push使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类storage.Storage
的用法示例。
在下文中一共展示了Storage.push方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Torrent
# 需要导入模块: from storage import Storage [as 别名]
# 或者: from storage.Storage import push [as 别名]
#.........这里部分代码省略.........
self.paused = paused
if paused:
# choke all
for connection in self.torrent.connections.values():
connection.choke()
################################
# Interface
################################
def newConnection(self, connection):
self.connections[connection.peer_id] = connection
print '[Torrent]\ttotal connected peers: ', len(self.connections)
connection.bitfield(self.storage.gen_complete_str())
def lostConnection(self, connection):
if connection.peer_id in self.connections:
del self.connections[connection.peer_id]
self._cleanup_connection(connection)
print '[Torrent]\ttotal connected peers: ', len(self.connections)
################################
# Event
################################
def onRequest(self, connection, block_info):
if self.paused:
return
data = self.storage.get(*block_info)
connection.piece(block_info, data)
def onPiece(self, connection, block_info, block_data):
if self.paused:
return
self.storage.push(block_info[0], block_info[1], block_data)
if self.storage.is_piece_received(block_info[0]):
self.pushHave(block_info[0])
if self.storage.is_all_piece_received():
# save target file
self.storage.save_target_file(self.target_file)
self.onComplete()
request = (connection, block_info)
self.downloading.remove(request)
self._try_download()
print 'push piece', block_info, len(block_data), ', rate:', repr(self.getDownloadRate() / 1000) + 'kb/s, complete:', repr(self.storage.get_downloaded_rate()*100)+'%'
if connection.peer_id not in self.count_received.keys():
self.count_received[connection.peer_id] = 1
else:
self.count_received[connection.peer_id] += 1
def onCancel(self, connection, block_info):
# now nothing to do
pass
def onUnchoked(self, connection):
self._try_download()
def onComplete(self):
if self.completed:
return
time_used = time() - self.start_time
if time_used == 0:
示例2: Storage
# 需要导入模块: from storage import Storage [as 别名]
# 或者: from storage.Storage import push [as 别名]
from storage import Storage
info = {}
info["piece_length"] = 524288
info["length"] = 524288 * 8
st = Storage(info)
print("is all piece received: ", st.is_all_piece_received())
for i in range(8):
for j in range(32):
st.push(i, j*16*1024, "sdfsdfsdf")
print("is all piece received: ", st.gen_priority_list())
print("is all piece received: ", st.is_all_piece_received())