summaryrefslogtreecommitdiff
path: root/Lib/sre.py
diff options
context:
space:
mode:
authorFredrik Lundh <fredrik@pythonware.com>2000-06-30 13:55:15 +0000
committerFredrik Lundh <fredrik@pythonware.com>2000-06-30 13:55:15 +0000
commit0640e1161f37fd3415e9efdbde1e293efb98978c (patch)
treec008ad1c1f5e8610921bb893df78fa86f06fa2cf /Lib/sre.py
parentae1b5b2e985eeea6433671d874ccaddfd36db5a6 (diff)
downloadcpython-git-0640e1161f37fd3415e9efdbde1e293efb98978c.tar.gz
the mad patcher strikes again:
-- added pickling support (only works if sre is imported) -- fixed wordsize problems in engine (instead of casting literals down to the character size, cast characters up to the literal size (same as the code word size). this prevents false hits when you're matching a unicode pattern against an 8-bit string. (unfortunately, this broke another test, but I think the test should be changed in this case; more on that on python-dev) -- added sre.purge function (unofficial, clears the cache)
Diffstat (limited to 'Lib/sre.py')
-rw-r--r--Lib/sre.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/sre.py b/Lib/sre.py
index 97a5140e91..5e6aeeb853 100644
--- a/Lib/sre.py
+++ b/Lib/sre.py
@@ -89,6 +89,10 @@ def _compile(pattern, flags=0):
_cache[key] = p
return p
+def purge():
+ # clear pattern cache
+ _cache.clear()
+
def _sub(pattern, template, string, count=0):
# internal: pattern.sub implementation hook
return _subn(pattern, template, string, count)[0]
@@ -142,3 +146,12 @@ def _split(pattern, string, maxsplit=0):
n = n + 1
append(string[i:])
return s
+
+# register myself for pickling
+
+import copy_reg
+
+def _pickle(p):
+ return _compile, (p.pattern, p.flags)
+
+copy_reg.pickle(type(_compile("")), _pickle, _compile)