~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: 2010-10-05 21:15:13 UTC
  • mfrom: (5448.3.5 374700-Add-gnu-lsh-support)
  • Revision ID: pqm@pqm.ubuntu.com-20101005211513-whouyj5t7oo92gmq
(gz) Add support for GNU lsh as a secure shell client (Matthew Gordon)

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
 
from __future__ import absolute_import
28
 
 
29
23
import re
30
24
 
31
25
from bzrlib import errors
50
44
    def __init__(self, args=(), kwargs={}):
51
45
        """Create a new proxy object, passing in the args to pass to re.compile
52
46
 
53
 
        :param args: The `*args` to pass to re.compile
54
 
        :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
55
49
        """
56
50
        self._real_regex = None
57
51
        self._regex_args = args
73
67
            # cleaner message to the user.
74
68
            raise errors.InvalidPattern('"' + args[0] + '" ' +str(e))
75
69
 
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
 
 
89
70
    def __getattr__(self, attr):
90
71
        """Return a member from the proxied regex object.
91
72