本文整理汇总了Python中sre_compile.error方法的典型用法代码示例。如果您正苦于以下问题:Python sre_compile.error方法的具体用法?Python sre_compile.error怎么用?Python sre_compile.error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sre_compile
的用法示例。
在下文中一共展示了sre_compile.error方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _compile
# 需要导入模块: import sre_compile [as 别名]
# 或者: from sre_compile import error [as 别名]
def _compile(*key):
# internal: compile pattern
pattern, flags = key
bypass_cache = flags & DEBUG
if not bypass_cache:
cachekey = (type(key[0]),) + key
try:
p, loc = _cache[cachekey]
if loc is None or loc == _locale.setlocale(_locale.LC_CTYPE):
return p
except KeyError:
pass
if isinstance(pattern, _pattern_type):
if flags:
raise ValueError('Cannot process flags argument with a compiled pattern')
return pattern
if not sre_compile.isstring(pattern):
raise TypeError, "first argument must be string or compiled pattern"
try:
p = sre_compile.compile(pattern, flags)
except error, v:
raise error, v # invalid expression
示例2: _compile
# 需要导入模块: import sre_compile [as 别名]
# 或者: from sre_compile import error [as 别名]
def _compile(*key):
# internal: compile pattern
cachekey = (type(key[0]),) + key
p = _cache.get(cachekey)
if p is not None:
return p
pattern, flags = key
if isinstance(pattern, _pattern_type):
if flags:
raise ValueError('Cannot process flags argument with a compiled pattern')
return pattern
if not sre_compile.isstring(pattern):
raise TypeError, "first argument must be string or compiled pattern"
try:
p = sre_compile.compile(pattern, flags)
except error, v:
raise error, v # invalid expression
示例3: match_log
# 需要导入模块: import sre_compile [as 别名]
# 或者: from sre_compile import error [as 别名]
def match_log(self, line):
"""
Matches lines from compare log with the target serial output. Compare log lines are matched in seq using index
self.compare_log_idx. Lines can be strings to be matched as is or regular expressions.
:param line:
:return:
"""
if self.compare_log_idx < len(self.compare_log):
regex = self.compare_log[self.compare_log_idx]
# Either the line is matched as is or it is checked as a regular expression.
try:
if regex in line or re.search(regex, line):
self.compare_log_idx += 1
except error:
# May not be a regular expression
return False
return self.compare_log_idx == len(self.compare_log)
示例4: _compile_repl
# 需要导入模块: import sre_compile [as 别名]
# 或者: from sre_compile import error [as 别名]
def _compile_repl(*key):
# internal: compile replacement pattern
p = _cache_repl.get(key)
if p is not None:
return p
repl, pattern = key
try:
p = sre_parse.parse_template(repl, pattern)
except error, v:
raise error, v # invalid expression
示例5: _compile
# 需要导入模块: import sre_compile [as 别名]
# 或者: from sre_compile import error [as 别名]
def _compile(*key):
# internal: compile pattern
cachekey = (type(key[0]),) + key
p = _cache.get(cachekey)
if p is not None:
return p
pattern, flags = key
if isinstance(pattern, _pattern_type):
return pattern
if not sre_compile.isstring(pattern):
raise TypeError, "first argument must be string or compiled pattern"
try:
p = sre_compile.compile(pattern, flags)
except error, v:
raise error, v # invalid expression