本文整理汇总了Python中File.File.hash方法的典型用法代码示例。如果您正苦于以下问题:Python File.hash方法的具体用法?Python File.hash怎么用?Python File.hash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类File.File
的用法示例。
在下文中一共展示了File.hash方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testInsert
# 需要导入模块: from File import File [as 别名]
# 或者: from File.File import hash [as 别名]
def testInsert(self):
fdao = FileDAO()
file = File()
file.hash = self.hash
file.size = 555555
file.partialSize = 55555
file.bestname = 'nomedoarquivonarede.ext'
fid = fdao.insert(file)
assert fid != -1, 'error inserting file'
示例2: find
# 需要导入模块: from File import File [as 别名]
# 或者: from File.File import hash [as 别名]
def find(self, id):
self.cursor.execute("""SELECT * FROM """+self.tablename+""" WHERE id = %s""", (id,))
rs = self.cursor.fetchall()
if not rs:
return None
file = File()
for row in rs:
file.id = row[0]
file.hash = row[1]
file.size = row[2]
file.partialSize = row[3]
file.bestName = row[4]
return file
示例3: findByHash
# 需要导入模块: from File import File [as 别名]
# 或者: from File.File import hash [as 别名]
def findByHash(self, hash):
query = "SELECT * FROM %s WHERE hash = '%s'" % (self.tablename, hash)
self.cursor.execute(query)
rs = self.cursor.fetchall()
if not rs:
return None
file = File()
for row in rs:
file.id = row[0]
file.hash = row[1]
file.size = row[2]
file.partialSize = row[3]
file.bestName = row[4]
return file
示例4: decode
# 需要导入模块: from File import File [as 别名]
# 或者: from File.File import hash [as 别名]
def decode(self):
# Message: OptionsInfo
# Action: none
if self.msg.opcode is 1:
self.msg.decode_msg_1(self.msg.raw_data)
# Message: FileUpdateAvailability
# Action: update file availability for this source
elif self.msg.opcode is 9:
file_id, source_id, availability = self.msg.decode_msg_9(self.msg.raw_data)
logging.debug("Update Availability: %d (File %d, Source %d)" % (availability, file_id, source_id))
if source_id in self.source_id_hash:
sdao = SourceDAO()
sourceId = sdao.findByHash(self.source_id_hash[source_id]).id
fdao = FileDAO()
fileId = fdao.findByHash(self.file_id_hash[file_id]).id
shfdao = SourceHasFileDAO()
shfdao.insertOrUpdate(sourceId, fileId, availability)
# Message: FileAddSource
# Action: none
elif self.msg.opcode is 10:
file_id, source_id = self.msg.decode_msg_10(self.msg.raw_data)
logging.debug("Add Source: %d (File %d)" % (source_id, file_id))
# Message: ClientInfo
# Action: update and persist session on database
elif self.msg.opcode is 15:
session = self.msg.decode_msg_15(self.msg.raw_data)
source_id = session.source.id #fake
adao = AddressDAO()
addressId = adao.insertOrUpdate(session.address)
logging.debug("File-[Sources]: %s" % (self.file_sources))
logging.debug("File [id-hash]: %s" % (self.file_id_hash))
logging.debug("Source [id-hash]: %s" % (self.source_id_hash))
fileId = None
file_id = 0
for file in self.file_sources:
#logging.debug(file)
if source_id in self.file_sources[file]:
file_id = int(file)
#logging.debug(file_id)
if file_id in self.file_id_hash:
fdao = FileDAO()
fileHash = self.file_id_hash[file_id]
fileId = fdao.findByHash(fileHash).id
#logging.debug("F-HASH: %s, F-ID: %s, ADDR-ID: %s" % (fileHash, fileId ,addressId))
#logging.debug("*****File id***: %d" % (file_id))
#TODO: consider more than one session with the same source
#logging.debug("*****File id: %d" % (file_id))
if session and fileId:
if source_id in self.source_id_hash:
#logging.debug(self.source_id_hash)
#logging.debug("*******Sourcehash: %s" % (self.source_id_hash[source_id]))
srcdao = SourceDAO()
sourceHash = self.source_id_hash[source_id]
session.source.id = srcdao.findByHash(sourceHash).id
session.address.id = addressId
session.file.id = fileId
logging.debug("Source %d, File %d: Uploaded(%d), Donwloaded(%d)" % (source_id, file_id, session.uploaded, session.downloaded))
#logging.debug(session.source.id)
sdao = SessionDAO()
sessionId = sdao.insertOrUpdate(session)
if sessionId is None:
logging.debug("SessionId is null")
else:
logging.debug("****** IP-no-hash: %s",addressId)
# if fileId:
ahf = AddressHasFileDAO()
ahf.insert(addressId, fileId)
# Message: ClientState
# Action: none
elif self.msg.opcode is 16:
self.msg.decode_msg_16(self.msg.raw_data)
# Message: ConsoleMessage
# Action: handle wanted info (commands 'vd' and 'vc')
elif self.msg.opcode is 19:
cmd, id, result = self.msg.decode_msg_19(self.msg.raw_data)
if cmd == "vd": # id = file_id, result = file_sources
self.file_sources[id] = result
logging.debug("File-[Sources]: %s" % (self.file_sources))
for src in result:
if src not in self.source_id_hash:
cmd = "vc %d" % (src)
self.listener.send_cmd(cmd)
if cmd == "vc" and result: # id = source_id, result = (source, address)
source = result[0]
address = result[1]
for file in self.file_sources:
if int(id) in self.file_sources[file]:
if int(file) in self.file_id_hash:
fileHash = self.file_id_hash[int(file)]
fdao = FileDAO()
fileId = fdao.findByHash(fileHash).id
#.........这里部分代码省略.........