--- /opt/python2.6/release26-maint/Lib/urlparse.py 2009-01-14 08:36:05.000000000 -0200 +++ optmizedurlparse.py 2009-01-14 14:49:33.000000000 -0200 @@ -35,11 +35,6 @@ MAX_CACHE_SIZE = 20 _parse_cache = {} -def clear_cache(): - """Clear the parse cache.""" - _parse_cache.clear() - - class ResultMixin(object): """Shared methods for the parsed result objects.""" @@ -136,18 +131,19 @@ Return a 5-tuple: (scheme, netloc, path, query, fragment). Note that we don't break the components up in smaller bits (e.g. netloc is a single string) and we don't expand % escapes.""" + global _parse_cache allow_fragments = bool(allow_fragments) key = url, scheme, allow_fragments, type(url), type(scheme) cached = _parse_cache.get(key, None) if cached: return cached if len(_parse_cache) >= MAX_CACHE_SIZE: # avoid runaway growth - clear_cache() + _parse_cache = {} netloc = query = fragment = '' i = url.find(':') if i > 0: - if url[:i] == 'http': # optimize the common case - scheme = url[:i].lower() + scheme = url[:i].lower() + if scheme == 'http': # optimize the common case url = url[i+1:] if url[:2] == '//': netloc, url = _splitnetloc(url, 2) @@ -162,7 +158,7 @@ if c not in scheme_chars: break else: - scheme, url = url[:i].lower(), url[i+1:] + url = url[i+1:] if scheme in uses_netloc and url[:2] == '//': netloc, url = _splitnetloc(url, 2) if allow_fragments and scheme in uses_fragment and '#' in url: