#============================================================================== # Speed test for http://bugs.python.org/issue1285086 # # Updated to test against the improved urlib.quote in Python >= 2.5. #============================================================================== import re import timeit from urllib import always_safe from urllib import quote _faster_safe_test = always_safe + '/' _faster_safe = dict(zip(_faster_safe_test, _faster_safe_test)) for c in [chr(i) for i in range(256)]: if c not in _faster_safe: _faster_safe[c] = '%%%02X' % ord(c) _must_quote = re.compile(r'[^%s]' % _faster_safe_test) def _my_quote(to_quote): if not to_quote: return to_quote if not _must_quote.search(to_quote): return to_quote return ''.join(map(_faster_safe.get, to_quote)) TO_QUOTE = [ '', 'a', 'ABCDEFGHIJK', 'abcdefghijklmnopqrstuvwxyz', 'abc/def/ghi/jkl/mno', 'abc!@#$%^&*()[]{}\|\;\'";:.>,