]> granicus.if.org Git - python/commitdiff
Test urlparse cache with try/except instead of has_key.
authorGuido van Rossum <guido@python.org>
Fri, 11 Jul 1997 20:13:10 +0000 (20:13 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 11 Jul 1997 20:13:10 +0000 (20:13 +0000)
This makes it thread-safe again.

Lib/urlparse.py

index 31d853a168dda00ae779734f6d8c1778b1806a2a..aeed393a837e1ffbaf9d3fb92977c45aefd79b81 100644 (file)
@@ -44,8 +44,10 @@ def clear_cache():
 # (e.g. netloc is a single string) and we don't expand % escapes.
 def urlparse(url, scheme = '', allow_framents = 1):
        key = url, scheme, allow_framents
-       if _parse_cache.has_key(key):
+       try:
            return _parse_cache[key]
+       except KeyError:
+           pass
        if len(_parse_cache) >= MAX_CACHE_SIZE: # avoid runaway growth
            clear_cache()
        netloc = path = params = query = fragment = ''