/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Robert Collins
  • Date: 2009-03-27 04:10:25 UTC
  • mfrom: (4208 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4216.
  • Revision ID: robertc@robertcollins.net-20090327041025-rgutx4q03xo4pq6l
Resolve NEWS conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2009 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
import os
18
18
import re
1740
1740
                continue
1741
1741
            raise
1742
1742
 
 
1743
def re_compile_checked(re_string, flags=0, where=""):
 
1744
    """Return a compiled re, or raise a sensible error.
 
1745
    
 
1746
    This should only be used when compiling user-supplied REs.
 
1747
 
 
1748
    :param re_string: Text form of regular expression.
 
1749
    :param flags: eg re.IGNORECASE
 
1750
    :param where: Message explaining to the user the context where 
 
1751
        it occurred, eg 'log search filter'.
 
1752
    """
 
1753
    # from https://bugs.launchpad.net/bzr/+bug/251352
 
1754
    try:
 
1755
        re_obj = re.compile(re_string, flags)
 
1756
        re_obj.search("")
 
1757
        return re_obj
 
1758
    except re.error, e:
 
1759
        if where:
 
1760
            where = ' in ' + where
 
1761
        # despite the name 'error' is a type
 
1762
        raise errors.BzrCommandError('Invalid regular expression%s: %r: %s'
 
1763
            % (where, re_string, e))
 
1764
 
1743
1765
 
1744
1766
if sys.platform == "win32":
1745
1767
    import msvcrt