*** urllib.py.orig 2005-04-20 00:03:48.000000000 -0400 --- urllib.py 2005-09-08 22:19:41.679149616 -0400 *************** *** 27,32 **** --- 27,33 ---- import os import time import sys + import re from urlparse import urljoin as basejoin __all__ = ["urlopen", "URLopener", "FancyURLopener", "urlretrieve", *************** *** 1051,1070 **** '0123456789' '_.-') _fast_safe_test = always_safe + '/' ! _fast_safe = None ! def _fast_quote(s): ! global _fast_safe ! if _fast_safe is None: ! _fast_safe = {} ! for c in _fast_safe_test: ! _fast_safe[c] = c ! res = list(s) ! for i in range(len(res)): ! c = res[i] ! if not c in _fast_safe: ! res[i] = '%%%02X' % ord(c) ! return ''.join(res) def quote(s, safe = '/'): """quote('abc def') -> 'abc%20def' --- 1052,1063 ---- '0123456789' '_.-') _fast_safe_test = always_safe + '/' ! _fast_safe = dict(zip(_fast_safe_test, _fast_safe_test)) ! _must_quote = re.compile(r'[^%s]' % _fast_safe_test) ! for c in [chr(i) for i in range(256)]: ! if c not in _fast_safe: ! _fast_safe[c] = '%%%02X' % ord(c) def quote(s, safe = '/'): """quote('abc def') -> 'abc%20def' *************** *** 1087,1095 **** called on a path where the existing slash characters are used as reserved characters. """ safe = always_safe + safe - if _fast_safe_test == safe: - return _fast_quote(s) res = list(s) for i in range(len(res)): c = res[i] --- 1080,1090 ---- called on a path where the existing slash characters are used as reserved characters. """ + if safe == '/': # optimize usual case + return (s and (not _must_quote.search(s) + and s or ''.join(map(_fast_safe.get, s)) + )) safe = always_safe + safe res = list(s) for i in range(len(res)): c = res[i]