~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lazy_regex.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-04-19 04:37:48 UTC
  • mfrom: (5741.3.8 506265-command-deprecation)
  • Revision ID: pqm@pqm.ubuntu.com-20110419043748-qq4lsmc50cckqzp7
(mbp) Deprecate 'bzr clone' and 'bzr get' (bug 506265) (Martin Pool)

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
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.
 
19
This module defines a class which creates proxy objects for regex compilation.
 
20
This allows overriding re.compile() to return lazily compiled objects.
25
21
"""
26
22
 
27
23
import re
48
44
    def __init__(self, args=(), kwargs={}):
49
45
        """Create a new proxy object, passing in the args to pass to re.compile
50
46
 
51
 
        :param args: The `*args` to pass to re.compile
52
 
        :param kwargs: The `**kwargs` to pass to re.compile
 
47
        :param args: The *args to pass to re.compile
 
48
        :param kwargs: The **kwargs to pass to re.compile
53
49
        """
54
50
        self._real_regex = None
55
51
        self._regex_args = args
71
67
            # cleaner message to the user.
72
68
            raise errors.InvalidPattern('"' + args[0] + '" ' +str(e))
73
69
 
74
 
    def __getstate__(self):
75
 
        """Return the state to use when pickling."""
76
 
        return {
77
 
            "args": self._regex_args,
78
 
            "kwargs": self._regex_kwargs,
79
 
            }
80
 
 
81
 
    def __setstate__(self, dict):
82
 
        """Restore from a pickled state."""
83
 
        self._real_regex = None
84
 
        setattr(self, "_regex_args", dict["args"])
85
 
        setattr(self, "_regex_kwargs", dict["kwargs"])
86
 
 
87
70
    def __getattr__(self, attr):
88
71
        """Return a member from the proxied regex object.
89
72