~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lazy_regex.py

  • Committer: Patch Queue Manager
  • Date: 2016-04-21 04:10:52 UTC
  • mfrom: (6616.1.1 fix-en-user-guide)
  • Revision ID: pqm@pqm.ubuntu.com-20160421041052-clcye7ns1qcl2n7w
(richard-wilbur) Ensure build of English use guide always uses English text
 even when user's locale specifies a different language. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Lazily compiled regex objects.
18
18
 
19
 
This module defines a class which creates proxy objects for regex compilation.
20
 
This allows overriding re.compile() to return lazily compiled objects.
 
19
This module defines a class which creates proxy objects for regex
 
20
compilation.  This allows overriding re.compile() to return lazily compiled
 
21
objects.  
 
22
 
 
23
We do this rather than just providing a new interface so that it will also
 
24
be used by existing Python modules that create regexs.
21
25
"""
22
26
 
 
27
from __future__ import absolute_import
 
28
 
23
29
import re
24
30
 
25
31
from bzrlib import errors
44
50
    def __init__(self, args=(), kwargs={}):
45
51
        """Create a new proxy object, passing in the args to pass to re.compile
46
52
 
47
 
        :param args: The *args to pass to re.compile
48
 
        :param kwargs: The **kwargs to pass to re.compile
 
53
        :param args: The `*args` to pass to re.compile
 
54
        :param kwargs: The `**kwargs` to pass to re.compile
49
55
        """
50
56
        self._real_regex = None
51
57
        self._regex_args = args
67
73
            # cleaner message to the user.
68
74
            raise errors.InvalidPattern('"' + args[0] + '" ' +str(e))
69
75
 
 
76
    def __getstate__(self):
 
77
        """Return the state to use when pickling."""
 
78
        return {
 
79
            "args": self._regex_args,
 
80
            "kwargs": self._regex_kwargs,
 
81
            }
 
82
 
 
83
    def __setstate__(self, dict):
 
84
        """Restore from a pickled state."""
 
85
        self._real_regex = None
 
86
        setattr(self, "_regex_args", dict["args"])
 
87
        setattr(self, "_regex_kwargs", dict["kwargs"])
 
88
 
70
89
    def __getattr__(self, attr):
71
90
        """Return a member from the proxied regex object.
72
91