package bittorrent tags 585222 + patch thanks On 09-Jun-2010, Sandro Tosi wrote: > One of the changes brought by Python 2.6 is the removal of string > exceptions, so they won't work in Python 2.6 (just a side note: they > were also buggy before, since they were not guaranteed to work > reliable even in <2.6)
The attached patch addresses this bug, by converting each non-standard ‘raise’ statement to use an exception instance correctly. -- \ “I was born by Caesarian section. But not so you'd notice. It's | `\ just that when I leave a house, I go out through the window.” | _o__) —Steven Wright | Ben Finney <b...@benfinney.id.au>
Description: Use standard syntax for ‘raise’ with exception instances. Author: Ben Finney <ben+deb...@benfinney.id.au> Bug-Debian: http://bugs.debian.org/585222 Last-Update: 2010-06-15 === modified file 'BitTorrent/StorageWrapper.py' --- old/BitTorrent/StorageWrapper.py 2010-06-15 08:59:04 +0000 +++ new/BitTorrent/StorageWrapper.py 2010-06-15 09:20:45 +0000 @@ -24,9 +24,9 @@ self.total_length = storage.get_total_length() self.amount_left = self.total_length if self.total_length <= piece_size * (len(hashes) - 1): - raise ValueError, 'bad data from tracker - total too small' + raise ValueError("bad data from tracker - total too small") if self.total_length > piece_size * len(hashes): - raise ValueError, 'bad data from tracker - total too big' + raise ValueError("bad data from tracker - total too big") self.finished = finished self.failed = failed self.numactive = [0] * len(hashes) @@ -383,7 +383,7 @@ try: StorageWrapper(ds, 4, [sha(chr(0xff) * 4).digest(), sha(chr(0xFF) * 4).digest()], 4, ds.finished, None) - raise 'fail' + raise RuntimeError("fail") except ValueError: pass @@ -392,7 +392,7 @@ try: sw = StorageWrapper(ds, 4, [sha('qqqq').digest(), sha(chr(0xFF) * 4).digest()], 4, ds.finished, None) - raise 'fail' + raise RuntimeError("fail") except ValueError: pass === modified file 'BitTorrent/btformats.py' --- old/BitTorrent/btformats.py 2010-06-15 08:59:04 +0000 +++ new/BitTorrent/btformats.py 2010-06-15 09:20:45 +0000 @@ -10,46 +10,47 @@ def check_info(info): if type(info) != DictType: - raise ValueError, 'bad metainfo - not a dictionary' + raise ValueError("bad metainfo - not a dictionary") pieces = info.get('pieces') if type(pieces) != StringType or len(pieces) % 20 != 0: - raise ValueError, 'bad metainfo - bad pieces key' + raise ValueError("bad metainfo - bad pieces key") piecelength = info.get('piece length') if type(piecelength) not in ints or piecelength <= 0: - raise ValueError, 'bad metainfo - illegal piece length' + raise ValueError("bad metainfo - illegal piece length") name = info.get('name') if type(name) != StringType: - raise ValueError, 'bad metainfo - bad name' + raise ValueError("bad metainfo - bad name") if not reg.match(name): - raise ValueError, 'name %s disallowed for security reasons' % name + raise ValueError("name %(name)s disallowed for security reasons" % vars()) if info.has_key('files') == info.has_key('length'): - raise ValueError, 'single/multiple file mix' + raise ValueError("single/multiple file mix") if info.has_key('length'): length = info.get('length') if type(length) not in ints or length < 0: - raise ValueError, 'bad metainfo - bad length' + raise ValueError("bad metainfo - bad length") else: files = info.get('files') if type(files) != ListType: raise ValueError for f in files: if type(f) != DictType: - raise ValueError, 'bad metainfo - bad file value' + raise ValueError("bad metainfo - bad file value") length = f.get('length') if type(length) not in ints or length < 0: - raise ValueError, 'bad metainfo - bad length' + raise ValueError("bad metainfo - bad length") path = f.get('path') if type(path) != ListType or path == []: - raise ValueError, 'bad metainfo - bad path' + raise ValueError("bad metainfo - bad path") for p in path: if type(p) != StringType: - raise ValueError, 'bad metainfo - bad path dir' + raise ValueError("bad metainfo - bad path dir") if not reg.match(p): - raise ValueError, 'path %s disallowed for security reasons' % p + raise ValueError( + "path %(p)s disallowed for security reasons" % vars()) for i in xrange(len(files)): for j in xrange(i): if files[i]['path'] == files[j]['path']: - raise ValueError, 'bad metainfo - duplicate path' + raise ValueError("bad metainfo - duplicate path") def check_message(message): if type(message) != DictType: === modified file 'BitTorrent/download.py' --- old/BitTorrent/download.py 2010-06-15 08:59:04 +0000 +++ new/BitTorrent/download.py 2010-06-15 09:20:45 +0000 @@ -102,13 +102,13 @@ config, args = parseargs(params, defaults, 0, 1) if args: if config.get('responsefile', None) == None: - raise ValueError, 'must have responsefile as arg or parameter, not both' + raise ValueError("must have responsefile as arg or parameter, not both") if path.isfile(args[0]): config['responsefile'] = args[0] else: config['url'] = args[0] if (config['responsefile'] == '') == (config['url'] == ''): - raise ValueError, 'need responsefile or url' + raise ValueError("need responsefile or url") except ValueError, e: errorfunc('error: ' + str(e) + '\nrun with no args for parameter explanations') return === modified file 'BitTorrent/track.py' --- old/BitTorrent/track.py 2010-06-15 08:59:04 +0000 +++ new/BitTorrent/track.py 2010-06-15 09:20:45 +0000 @@ -319,7 +319,7 @@ return (404, 'Not Found', {'Content-Type': 'text/plain', 'Pragma': 'no-cache'}, alas) try: if not params.has_key('info_hash'): - raise ValueError, 'no info hash' + raise ValueError("no info hash") if params.has_key('ip') and not is_valid_ipv4(params['ip']): raise ValueError('DNS name or invalid IP address given for IP') infohash = params['info_hash'] @@ -333,14 +333,14 @@ not self.only_local_override_ip or is_local_ip(ip)): ip_override = 1 if params.has_key('event') and params['event'] not in ['started', 'completed', 'stopped']: - raise ValueError, 'invalid event' + raise ValueError("invalid event") port = long(params.get('port', '')) uploaded = long(params.get('uploaded', '')) downloaded = long(params.get('downloaded', '')) left = long(params.get('left', '')) myid = params.get('peer_id', '') if len(myid) != 20: - raise ValueError, 'id not of length 20' + raise ValueError("id not of length 20") rsize = self.response_size if params.has_key('numwant'): rsize = min(long(params['numwant']), self.max_give) === modified file 'osx/freeze.py' --- old/osx/freeze.py 2010-06-15 08:59:04 +0000 +++ new/osx/freeze.py 2010-06-15 09:20:45 +0000 @@ -30,21 +30,21 @@ except OSError, reason: # ignore errno=17 directory already exists... if reason.errno != 17: - raise OSError, reason + raise OSError(unicode(reason)) try: makedirs(dy) except OSError, reason: # ignore errno=17 directory already exists... if reason.errno != 17: - raise OSError, reason + raise OSError(unicode(reason)) try: makedirs(bt) except OSError, reason: # ignore errno=17 directory already exists... if reason.errno != 17: - raise OSError, reason + raise OSError(unicode(reason)) print "Copying depedent Python modules..."
signature.asc
Description: Digital signature