import timeit FASTER_SETUP = """\ from urllib import always_safe import re _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) """ exec FASTER_SETUP # Use triple quotes to avoid having to figure out quoting in TO_QUOTE. FASTER_STMT_TEMPLATE = """\ '''%(to_quote)s''' and ( (not _must_quote.search('''%(to_quote)s''')) and '''%(to_quote)s''' or ''.join(map(_faster_safe.get, '''%(to_quote)s''')) ) """ FAST_SETUP = """\ from urllib import _fast_quote """ exec FAST_SETUP FAST_STMT_TEMPLATE = """\ _fast_quote('''%(to_quote)s''') """ TO_QUOTE = [ '', 'a', 'ABCDEFGHIJK', 'abcdefghijklmnopqrstuvwxyz', 'abc/def/ghi/jkl/mno', 'abc!@#$%^&*()[]{}\|\;\'";:.>,