"""Read and write Gtkpod extended info files.""" import os import types # The hashlib module is only available in python >= 2.5, # while the sha module is deprecated in 2.6. try: import hashlib sha1 = hashlib.sha1 except ImportError: import sha sha1 = sha.sha # This file is originally stolen from pypod-0.5.0 # http://superduper.net/index.py?page=pypod # and reworked significantly since then. class ParseError(Exception): """Exception for parse errors.""" pass class SyncError(Exception): """Exception for sync errors.""" pass def sha1_hash(filename): """Return an SHA1 hash on the first 16k of a file.""" import struct # only hash the first 16k hash_len = 4*4096 hash = sha1() size = os.path.getsize(filename) hash.update(struct.pack("