From 58da4e434d844da76226fdaceb6952532d68fb1e Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Thu, 21 Oct 2010 19:15:11 +0200 Subject: Make code compatible with Python 3.x; should work with 2.6 and newer. --- pyanidb/hash.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'pyanidb/hash.py') diff --git a/pyanidb/hash.py b/pyanidb/hash.py index 912fc67..489f15a 100644 --- a/pyanidb/hash.py +++ b/pyanidb/hash.py @@ -35,7 +35,7 @@ class Crc32: self.s = binascii.crc32(data, self.s) def hexdigest(self): - return '%08x' % (self.s & 0xffffffff) + return '{0:08x}'.format(self.s & 0xffffffff) hasher_obj = { 'ed2k': Ed2k, @@ -52,7 +52,7 @@ class Hash: update_list.append(h.update) setattr(self, a, h.hexdigest) - f = open(filename) + f = open(filename, 'rb') data = f.read(131072) while data: for u in update_list: @@ -80,7 +80,7 @@ class File: cache = dict([(n[13:], xattr.getxattr(self.name, n)) for n in xattr.listxattr(self.name) if n.startswith('user.pyanidb.')]) if 'mtime' not in cache or str(int(self.mtime)) != cache.pop('mtime'): return - for n, v in cache.iteritems(): + for n, v in cache.items(): setattr(self, n, v) self.cached = True @@ -119,7 +119,7 @@ class Hashthread(threading.Thread): def hash_files(files, cache = False, algorithms = ('ed2k',), num_threads = 1): hashlist = [] threads = [] - for x in xrange(num_threads): + for x in range(num_threads): thread = Hashthread(files, hashlist, algorithms, cache) thread.start() threads.append(thread) -- cgit v1.2.3