当前位置: 首页>>代码示例>>Python>>正文


Python re.LOCALE属性代码示例

本文整理汇总了Python中re.LOCALE属性的典型用法代码示例。如果您正苦于以下问题:Python re.LOCALE属性的具体用法?Python re.LOCALE怎么用?Python re.LOCALE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在re的用法示例。


在下文中一共展示了re.LOCALE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: render_re

# 需要导入模块: import re [as 别名]
# 或者: from re import LOCALE [as 别名]
def render_re(regex):
  """Renders a repr()-style value for a compiled regular expression."""
  actual_flags = []
  if regex.flags:
    flags = [
      (re.IGNORECASE, 'IGNORECASE'),
      (re.LOCALE, 'LOCALE'),
      (re.UNICODE, 'UNICODE'),
      (re.MULTILINE, 'MULTILINE'),
      (re.DOTALL, 'DOTALL'),
      (re.VERBOSE, 'VERBOSE'),
    ]
    for val, name in flags:
      if regex.flags & val:
        actual_flags.append(name)
  if actual_flags:
    return 're.compile(%r, %s)' % (regex.pattern, '|'.join(actual_flags))
  else:
    return 're.compile(%r)' % regex.pattern 
开发者ID:luci,项目名称:recipes-py,代码行数:21,代码来源:magic_check_fn.py

示例2: str_flags_to_int

# 需要导入模块: import re [as 别名]
# 或者: from re import LOCALE [as 别名]
def str_flags_to_int(str_flags):
    flags = 0
    if "i" in str_flags:
        flags |= re.IGNORECASE
    if "l" in str_flags:
        flags |= re.LOCALE
    if "m" in str_flags:
        flags |= re.MULTILINE
    if "s" in str_flags:
        flags |= re.DOTALL
    if "u" in str_flags:
        flags |= re.UNICODE
    if "x" in str_flags:
        flags |= re.VERBOSE

    return flags 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:18,代码来源:regex.py

示例3: _encode_regex

# 需要导入模块: import re [as 别名]
# 或者: from re import LOCALE [as 别名]
def _encode_regex(name, value, dummy0, dummy1):
    """Encode a python regex or bson.regex.Regex."""
    flags = value.flags
    # Python 2 common case
    if flags == 0:
        return b"\x0B" + name + _make_c_string_check(value.pattern) + b"\x00"
    # Python 3 common case
    elif flags == re.UNICODE:
        return b"\x0B" + name + _make_c_string_check(value.pattern) + b"u\x00"
    else:
        sflags = b""
        if flags & re.IGNORECASE:
            sflags += b"i"
        if flags & re.LOCALE:
            sflags += b"l"
        if flags & re.MULTILINE:
            sflags += b"m"
        if flags & re.DOTALL:
            sflags += b"s"
        if flags & re.UNICODE:
            sflags += b"u"
        if flags & re.VERBOSE:
            sflags += b"x"
        sflags += b"\x00"
        return b"\x0B" + name + _make_c_string_check(value.pattern) + sflags 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:27,代码来源:__init__.py

示例4: re_int_flag_to_str

# 需要导入模块: import re [as 别名]
# 或者: from re import LOCALE [as 别名]
def re_int_flag_to_str(int_flags):
    """Ripped from bson.json_util
    """
    flags = ""
    if int_flags & re.IGNORECASE:
        flags += "i"
    if int_flags & re.LOCALE:
        flags += "l"
    if int_flags & re.MULTILINE:
        flags += "m"
    if int_flags & re.DOTALL:
        flags += "s"
    if int_flags & re.UNICODE:
        flags += "u"
    if int_flags & re.VERBOSE:
        flags += "x"
    return flags 
开发者ID:davidlatwe,项目名称:montydb,代码行数:19,代码来源:__init__.py

示例5: re_str_flags_to_int

# 需要导入模块: import re [as 别名]
# 或者: from re import LOCALE [as 别名]
def re_str_flags_to_int(str_flags):
    flags = 0
    if "i" in str_flags:
        flags |= re.IGNORECASE
    if "l" in str_flags:
        flags |= re.LOCALE
    if "m" in str_flags:
        flags |= re.MULTILINE
    if "s" in str_flags:
        flags |= re.DOTALL
    if "u" in str_flags:
        flags |= re.UNICODE
    if "x" in str_flags:
        flags |= re.VERBOSE

    return flags 
开发者ID:davidlatwe,项目名称:montydb,代码行数:18,代码来源:__init__.py

示例6: addRecordData

# 需要导入模块: import re [as 别名]
# 或者: from re import LOCALE [as 别名]
def addRecordData(self, *args):
        if not args:
            # handle bad input
            return
        if len(args) < 2:
            # called via lexer
            key, val = args[0].split(None, 1)
        else:
            # called via xmllog:addRecordData
            key, val = args
        if key[0].isdigit() or \
                not re.match('^\w[a-zA-Z0-9_.-]*$', key,
                    flags = re.LOCALE | re.UNICODE):
            raise RuntimeError("'%s' is not a legal XML name" % key)
        if isinstance(val, (str, unicode)):
            val = saxutils.escape(val)
        recordData = self._getRecordData()
        recordData[key] = val 
开发者ID:sassoftware,项目名称:conary,代码行数:20,代码来源:logger.py

示例7: __init__

# 需要导入模块: import re [as 别名]
# 或者: from re import LOCALE [as 别名]
def __init__(self, logdispatcher):
        """
        Initialize all object attributes
        @author: ekkehard j. koch
        """
        self.logdispatcher = logdispatcher
        self.command = []
        self.commandblank = True
        self.returncode = 0
        self.output = []
        self.stdout = []
        self.stderr = []
        self.shell = False
        self.setLogPriority(LogPriority.DEBUG)
        self.flags = ["DEBUG", "IGNORECASE", "LOCALE", "MULTILINE", "DOTALL",
                      "UNICODE", "VERBOSE"]
        self.flag = ""

        # set this to False if you need to run a command that has no return code
        self.wait = True
        self.cmdtimeout = 0

############################################################################### 
开发者ID:CSD-Public,项目名称:stonix,代码行数:25,代码来源:CommandHelper.py

示例8: findReplaceFlags

# 需要导入模块: import re [as 别名]
# 或者: from re import LOCALE [as 别名]
def findReplaceFlags(self, tokens):
        """Map letters in |tokens| to re flags."""
        flags = re.MULTILINE
        if u'i' in tokens:
            flags |= re.IGNORECASE
        if u'l' in tokens:
            # Affects \w, \W, \b, \B.
            flags |= re.LOCALE
        if u'm' in tokens:
            # Affects ^, $.
            flags |= re.MULTILINE
        if u's' in tokens:
            # Affects ..
            flags |= re.DOTALL
        if u'x' in tokens:
            # Affects whitespace and # comments.
            flags |= re.VERBOSE
        if u'u' in tokens:
            # Affects \w, \W, \b, \B.
            flags |= re.UNICODE
        if 0:
            tokens = re.sub(u'[ilmsxu]', u'', tokens)
            if len(tokens):
                self.setMessage(u'unknown regex flags ' + tokens)
        return flags 
开发者ID:google,项目名称:ci_edit,代码行数:27,代码来源:actions.py

示例9: test_special_escapes

# 需要导入模块: import re [as 别名]
# 或者: from re import LOCALE [as 别名]
def test_special_escapes(self):
        self.assertEqual(re.search(r"\b(b.)\b",
                                   "abcd abc bcd bx").group(1), "bx")
        self.assertEqual(re.search(r"\B(b.)\B",
                                   "abc bcd bc abxd").group(1), "bx")
        self.assertEqual(re.search(r"\b(b.)\b",
                                   "abcd abc bcd bx", re.LOCALE).group(1), "bx")
        self.assertEqual(re.search(r"\B(b.)\B",
                                   "abc bcd bc abxd", re.LOCALE).group(1), "bx")
        self.assertEqual(re.search(r"\b(b.)\b",
                                   "abcd abc bcd bx", re.UNICODE).group(1), "bx")
        self.assertEqual(re.search(r"\B(b.)\B",
                                   "abc bcd bc abxd", re.UNICODE).group(1), "bx")
        self.assertEqual(re.search(r"^abc$", "\nabc\n", re.M).group(0), "abc")
        self.assertEqual(re.search(r"^\Aabc\Z$", "abc", re.M).group(0), "abc")
        self.assertEqual(re.search(r"^\Aabc\Z$", "\nabc\n", re.M), None)
        self.assertEqual(re.search(r"\b(b.)\b",
                                   "abcd abc bcd bx").group(1), "bx")
        self.assertEqual(re.search(r"\B(b.)\B",
                                   "abc bcd bc abxd").group(1), "bx")
        self.assertEqual(re.search(r"^abc$", "\nabc\n", re.M).group(0), "abc")
        self.assertEqual(re.search(r"^\Aabc\Z$", "abc", re.M).group(0), "abc")
        self.assertEqual(re.search(r"^\Aabc\Z$", "\nabc\n", re.M), None)
        self.assertEqual(re.search(r"\d\D\w\W\s\S",
                                   "1aa! a").group(0), "1aa! a")
        self.assertEqual(re.search(r"\d\D\w\W\s\S",
                                   "1aa! a", re.LOCALE).group(0), "1aa! a")
        self.assertEqual(re.search(r"\d\D\w\W\s\S",
                                   "1aa! a", re.UNICODE).group(0), "1aa! a") 
开发者ID:war-and-code,项目名称:jawfish,代码行数:31,代码来源:test_re.py

示例10: test_getlower

# 需要导入模块: import re [as 别名]
# 或者: from re import LOCALE [as 别名]
def test_getlower(self):
        import _sre
        self.assertEqual(_sre.getlower(ord('A'), 0), ord('a'))
        self.assertEqual(_sre.getlower(ord('A'), re.LOCALE), ord('a'))
        self.assertEqual(_sre.getlower(ord('A'), re.UNICODE), ord('a'))

        self.assertEqual(re.match("abc", "ABC", re.I).group(0), "ABC")
        self.assertEqual(re.match("abc", "ABC", re.I).group(0), "ABC") 
开发者ID:war-and-code,项目名称:jawfish,代码行数:10,代码来源:test_re.py

示例11: test_constants

# 需要导入模块: import re [as 别名]
# 或者: from re import LOCALE [as 别名]
def test_constants(self):
        self.assertEqual(re.I, re.IGNORECASE)
        self.assertEqual(re.L, re.LOCALE)
        self.assertEqual(re.M, re.MULTILINE)
        self.assertEqual(re.S, re.DOTALL)
        self.assertEqual(re.X, re.VERBOSE) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:8,代码来源:test_re.py

示例12: test_special_escapes

# 需要导入模块: import re [as 别名]
# 或者: from re import LOCALE [as 别名]
def test_special_escapes(self):
        self.assertEqual(re.search(r"\b(b.)\b",
                                   "abcd abc bcd bx").group(1), "bx")
        self.assertEqual(re.search(r"\B(b.)\B",
                                   "abc bcd bc abxd").group(1), "bx")
        self.assertEqual(re.search(r"\b(b.)\b",
                                   "abcd abc bcd bx", re.LOCALE).group(1), "bx")
        self.assertEqual(re.search(r"\B(b.)\B",
                                   "abc bcd bc abxd", re.LOCALE).group(1), "bx")
        if have_unicode:
            self.assertEqual(re.search(r"\b(b.)\b",
                                       "abcd abc bcd bx", re.UNICODE).group(1), "bx")
            self.assertEqual(re.search(r"\B(b.)\B",
                                       "abc bcd bc abxd", re.UNICODE).group(1), "bx")
        self.assertEqual(re.search(r"^abc$", "\nabc\n", re.M).group(0), "abc")
        self.assertEqual(re.search(r"^\Aabc\Z$", "abc", re.M).group(0), "abc")
        self.assertIsNone(re.search(r"^\Aabc\Z$", "\nabc\n", re.M))
        self.assertEqual(re.search(r"\b(b.)\b",
                                   u"abcd abc bcd bx").group(1), "bx")
        self.assertEqual(re.search(r"\B(b.)\B",
                                   u"abc bcd bc abxd").group(1), "bx")
        self.assertEqual(re.search(r"^abc$", u"\nabc\n", re.M).group(0), "abc")
        self.assertEqual(re.search(r"^\Aabc\Z$", u"abc", re.M).group(0), "abc")
        self.assertIsNone(re.search(r"^\Aabc\Z$", u"\nabc\n", re.M))
        self.assertEqual(re.search(r"\d\D\w\W\s\S",
                                   "1aa! a").group(0), "1aa! a")
        self.assertEqual(re.search(r"\d\D\w\W\s\S",
                                   "1aa! a", re.LOCALE).group(0), "1aa! a")
        if have_unicode:
            self.assertEqual(re.search(r"\d\D\w\W\s\S",
                                       "1aa! a", re.UNICODE).group(0), "1aa! a") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:33,代码来源:test_re.py

示例13: test_getlower

# 需要导入模块: import re [as 别名]
# 或者: from re import LOCALE [as 别名]
def test_getlower(self):
        import _sre
        self.assertEqual(_sre.getlower(ord('A'), 0), ord('a'))
        self.assertEqual(_sre.getlower(ord('A'), re.LOCALE), ord('a'))
        if have_unicode:
            self.assertEqual(_sre.getlower(ord('A'), re.UNICODE), ord('a'))

        self.assertEqual(re.match("abc", "ABC", re.I).group(0), "ABC")
        self.assertEqual(re.match("abc", u"ABC", re.I).group(0), "ABC") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:test_re.py

示例14: _regex_from_encoded_pattern

# 需要导入模块: import re [as 别名]
# 或者: from re import LOCALE [as 别名]
def _regex_from_encoded_pattern(s):
    """'foo'    -> re.compile(re.escape('foo'))
       '/foo/'  -> re.compile('foo')
       '/foo/i' -> re.compile('foo', re.I)
    """
    if s.startswith('/') and s.rfind('/') != 0:
        # Parse it: /PATTERN/FLAGS
        idx = s.rfind('/')
        pattern, flags_str = s[1:idx], s[idx+1:]
        flag_from_char = {
            "i": re.IGNORECASE,
            "l": re.LOCALE,
            "s": re.DOTALL,
            "m": re.MULTILINE,
            "u": re.UNICODE,
        }
        flags = 0
        for char in flags_str:
            try:
                flags |= flag_from_char[char]
            except KeyError:
                raise ValueError("unsupported regex flag: '%s' in '%s' "
                                 "(must be one of '%s')"
                                 % (char, s, ''.join(list(flag_from_char.keys()))))
        return re.compile(s[1:idx], flags)
    else:  # not an encoded regex
        return re.compile(re.escape(s))


# Recipe: dedent (0.1.2) 
开发者ID:b1ueb1ues,项目名称:dl,代码行数:32,代码来源:markdown2.py

示例15: preprocess_data

# 需要导入模块: import re [as 别名]
# 或者: from re import LOCALE [as 别名]
def preprocess_data(line, token_pattern=token_pattern,                     
                     encode_digit=False):
    line=str(line)
    token_pattern = re.compile(token_pattern, flags = re.UNICODE | re.LOCALE)
    tokens = [x.lower() for x in token_pattern.findall(line)]  
    return tokens


#caluclate dist features 
开发者ID:ChenglongChen,项目名称:kaggle-HomeDepot,代码行数:11,代码来源:grams_and_terms_features.py


注:本文中的re.LOCALE属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。