本文整理匯總了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
示例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
示例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
示例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
示例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
示例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
示例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
###############################################################################
示例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
示例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")
示例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")
示例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)
示例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")
示例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")
示例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)
示例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