diff options
author | Guido van Rossum <guido@python.org> | 1996-12-27 15:26:15 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1996-12-27 15:26:15 (GMT) |
commit | 671dc20efccf7fb75fa4aa7ac2d94593c58c4abf (patch) | |
tree | 80baf3b0387cbda523b470d0b48c4afd6dcb5daa | |
parent | babab6869fbbbf5c092dac2c3a7b3ef807114ac4 (diff) | |
download | cpython-671dc20efccf7fb75fa4aa7ac2d94593c58c4abf.zip cpython-671dc20efccf7fb75fa4aa7ac2d94593c58c4abf.tar.gz cpython-671dc20efccf7fb75fa4aa7ac2d94593c58c4abf.tar.bz2 |
Crude but effective hack to clear the parser cache every so often.
(Fred Drake.)
-rw-r--r-- | Lib/urlparse.py | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/Lib/urlparse.py b/Lib/urlparse.py index 571ef0e..9177533 100644 --- a/Lib/urlparse.py +++ b/Lib/urlparse.py @@ -19,9 +19,11 @@ uses_fragment = ['ftp', 'hdl', 'http', 'gopher', 'news', 'nntp', 'wais', # Characters valid in scheme names scheme_chars = string.letters + string.digits + '+-.' +MAX_CACHE_SIZE = 2000 _parse_cache = {} def clear_cache(): + """Clear the parse cache.""" global _parse_cache _parse_cache = {} @@ -35,6 +37,8 @@ def urlparse(url, scheme = '', allow_framents = 1): key = url, scheme, allow_framents if _parse_cache.has_key(key): return _parse_cache[key] + if len(_parse_cache) >= MAX_CACHE_SIZE: # avoid runaway growth + clear_cache() netloc = path = params = query = fragment = '' i = string.find(url, ':') if i > 0: |