~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Parth Malwankar
  • Date: 2010-06-30 12:03:30 UTC
  • mto: This revision was merged to the branch mainline in revision 5339.
  • Revision ID: parth.malwankar@gmail.com-20100630120330-uud7s38i8s08izh8
added InvalidPattern error.
This is raised by lazy_regex and Globster on bad regex.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2163
2163
            raise
2164
2164
 
2165
2165
 
2166
 
def re_compile_checked(re_string, flags=0, where=""):
2167
 
    """Return a compiled re, or raise a sensible error.
2168
 
 
2169
 
    This should only be used when compiling user-supplied REs.
2170
 
 
2171
 
    :param re_string: Text form of regular expression.
2172
 
    :param flags: eg re.IGNORECASE
2173
 
    :param where: Message explaining to the user the context where
2174
 
        it occurred, eg 'log search filter'.
2175
 
    """
2176
 
    # from https://bugs.launchpad.net/bzr/+bug/251352
2177
 
    try:
2178
 
        re_obj = re.compile(re_string, flags)
2179
 
        re_obj.search("")
2180
 
        return re_obj
2181
 
    except re.error, e:
2182
 
        if where:
2183
 
            where = ' in ' + where
2184
 
        # despite the name 'error' is a type
2185
 
        raise errors.BzrCommandError('Invalid regular expression%s: %r: %s'
2186
 
            % (where, re_string, e))
2187
 
 
2188
 
 
2189
2166
if sys.platform == "win32":
2190
2167
    import msvcrt
2191
2168
    def getchar():