def _create(metainfo): # TODO: replace with constructor # raises ValueErrors if not good validTorrentFile(metainfo) t = TorrentDef() t.metainfo = metainfo t.metainfo_valid = True # copy stuff into self.input maketorrent.copy_metainfo_to_input(t.metainfo, t.input) # Two places where infohash calculated, here and in maketorrent.py # Elsewhere: must use TorrentDef.get_infohash() to allow P2PURLs. t.infohash = sha1(bencode(metainfo['info'])).digest() assert isinstance(t.infohash, str), "INFOHASH has invalid type: %s" % type(t.infohash) assert len(t.infohash) == INFOHASH_LENGTH, "INFOHASH has invalid length: %d" % len(t.infohash) return t
def _create(metainfo): # TODO: replace with constructor # raises ValueErrors if not good metainfo_fixed = create_valid_metainfo(metainfo) t = TorrentDef() t.metainfo = metainfo_fixed t.metainfo_valid = True # copy stuff into self.input maketorrent.copy_metainfo_to_input(t.metainfo, t.input) # Two places where infohash calculated, here and in maketorrent.py # Elsewhere: must use TorrentDef.get_infohash() to allow P2PURLs. t.infohash = sha1(bencode(metainfo['info'])).digest() assert isinstance(t.infohash, str), "INFOHASH has invalid type: %s" % type(t.infohash) assert len(t.infohash) == INFOHASH_LENGTH, "INFOHASH has invalid length: %d" % len(t.infohash) return t