Rev 6285: (jelmer) Support pickling lazy_regex patterns. (Jelmer Vernooij) in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/
Patch Queue Manager
pqm at pqm.ubuntu.com
Wed Nov 23 14:11:03 UTC 2011
At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 6285 [merge]
revision-id: pqm at pqm.ubuntu.com-20111123141103-afx95vxa2t07ijy6
parent: pqm at pqm.ubuntu.com-20111123114853-98k118t2i003fdzn
parent: jelmer at samba.org-20111121160213-w3w6jkfps6s091gq
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2011-11-23 14:11:03 +0000
message:
(jelmer) Support pickling lazy_regex patterns. (Jelmer Vernooij)
modified:
bzrlib/lazy_regex.py lazy_regex.py-20061009091222-fyettq6z5qomdl9e-1
bzrlib/tests/test_lazy_regex.py test_lazy_regex.py-20061009091222-fyettq6z5qomdl9e-2
doc/en/release-notes/bzr-2.5.txt bzr2.5.txt-20110708125756-587p0hpw7oke4h05-1
=== modified file 'bzrlib/lazy_regex.py'
--- a/bzrlib/lazy_regex.py 2011-06-13 22:39:49 +0000
+++ b/bzrlib/lazy_regex.py 2011-11-21 16:02:13 +0000
@@ -71,6 +71,19 @@
# cleaner message to the user.
raise errors.InvalidPattern('"' + args[0] + '" ' +str(e))
+ def __getstate__(self):
+ """Return the state to use when pickling."""
+ return {
+ "args": self._regex_args,
+ "kwargs": self._regex_kwargs,
+ }
+
+ def __setstate__(self, dict):
+ """Restore from a pickled state."""
+ self._real_regex = None
+ setattr(self, "_regex_args", dict["args"])
+ setattr(self, "_regex_kwargs", dict["kwargs"])
+
def __getattr__(self, attr):
"""Return a member from the proxied regex object.
=== modified file 'bzrlib/tests/test_lazy_regex.py'
--- a/bzrlib/tests/test_lazy_regex.py 2011-06-28 22:39:41 +0000
+++ b/bzrlib/tests/test_lazy_regex.py 2011-11-21 16:02:13 +0000
@@ -16,6 +16,7 @@
"""Test that lazy regexes are not compiled right away"""
+import pickle
import re
from bzrlib import errors
@@ -115,6 +116,16 @@
pattern = lazy_regex.lazy_compile('[,;]*')
self.assertEqual(['x', 'y', 'z'], pattern.split('x,y;z'))
+ def test_pickle(self):
+ # When pickling, just compile the regex.
+ # Sphinx, which we use for documentation, pickles
+ # some compiled regexes.
+ lazy_pattern = lazy_regex.lazy_compile('[,;]*')
+ pickled = pickle.dumps(lazy_pattern)
+ unpickled_lazy_pattern = pickle.loads(pickled)
+ self.assertEqual(['x', 'y', 'z'],
+ unpickled_lazy_pattern.split('x,y;z'))
+
class TestInstallLazyCompile(tests.TestCase):
"""Tests for lazy compiled regexps.
=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- a/doc/en/release-notes/bzr-2.5.txt 2011-11-22 11:58:57 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt 2011-11-23 14:11:03 +0000
@@ -39,6 +39,9 @@
.. Fixes for situations where bzr would previously crash or give incorrect
or undesirable results.
+* Allow lazy compiled patterns from ``bzrlib.lazy_regex`` to be
+ pickled. (Jelmer Vernooij, #893149)
+
* A new section local option ``basename`` is available to help support some
``bzr-pipeline`` workflows and more generally help mapping local paths to
remote ones. See ``bzr help configuration`` for more details.
More information about the bazaar-commits
mailing list