本文整理汇总了Python中sre_compile.compile函数的典型用法代码示例。如果您正苦于以下问题:Python compile函数的具体用法?Python compile怎么用?Python compile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了compile函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, runtimePath) :
self.availRuleNames = []
basePath = os.path.join(runtimePath, "rules")
ruleFiles = os.listdir(basePath)
rulePattern = sre_compile.compile("^(.*)\.py$")
for eachRuleFile in ruleFiles :
if os.path.isfile(os.path.join(basePath, eachRuleFile)) :
ruleMatch = rulePattern.match(eachRuleFile)
if ruleMatch != None and eachRuleFile.find("__init__") == -1 :
ruleName = ruleMatch.group(1)
self.availRuleNames.append(ruleName)
self.availRuleCount = len(self.availRuleNames)
self.availRuleModules = {}
self.loadedRule = []
self.rules = []
self.preprocessRules = []
self.functionNameRules = []
self.functionScopeRules = []
self.typeNameRules = []
self.typeScopeRules = []
self.lineRules = []
self.fileEndRules = []
self.fileStartRules = []
self.projectRules = []
self.rollBackImporter = None
开发者ID:DLR-SC,项目名称:tigl,代码行数:25,代码来源:nsiqcppstyle_rulemanager.py
示例2: _compile
def _compile(pattern, flags):
# internal: compile pattern
if isinstance(flags, RegexFlag):
flags = flags.value
try:
return _cache[type(pattern), pattern, flags]
except KeyError:
pass
if isinstance(pattern, Pattern):
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")
p = sre_compile.compile(pattern, flags)
if not (flags & DEBUG):
if len(_cache) >= _MAXCACHE:
# Drop the oldest item
try:
del _cache[next(iter(_cache))]
except (StopIteration, RuntimeError, KeyError):
pass
_cache[type(pattern), pattern, flags] = p
return p
开发者ID:Apoorvadabhere,项目名称:cpython,代码行数:25,代码来源:re.py
示例3: compile_regexp_to_noncapturing
def compile_regexp_to_noncapturing(pattern, flags=0):
"""
Convert all grouping parentheses in the given regexp pattern to
non-capturing groups, and return the result. E.g.:
>>> from nltk.internals import compile_regexp_to_noncapturing
>>> compile_regexp_to_noncapturing('ab(c(x+)(z*))?d')
'ab(?:c(?:x+)(?:z*))?d'
:type pattern: str
:rtype: str
"""
def convert_regexp_to_noncapturing_parsed(parsed_pattern):
res_data = []
for key, value in parsed_pattern.data:
if key == sre_constants.SUBPATTERN:
index, subpattern = value
value = (None, convert_regexp_to_noncapturing(subpattern))
elif key == sre_constants.GROUPREF:
raise ValueError('Regular expressions with back-references are not supported: {0}'.format(pattern))
res_data.append((key, value))
parsed_pattern.data = res_data
parsed_pattern.pattern.groups = 1
parsed_pattern.pattern.groupdict = {}
return parsed_pattern
return sre_compile.compile(convert_regexp_to_noncapturing_parsed(sre_parse.parse(pattern)))
开发者ID:osu-ling5802-2016,项目名称:Sigmorphon2016,代码行数:27,代码来源:internals.py
示例4: _compile
def _compile(*key):
pattern, flags = key
bypass_cache = flags & DEBUG
if not bypass_cache:
cachekey = (type(key[0]),) + key
p = _cache.get(cachekey)
if p is not None:
return p
if isinstance(pattern, _pattern_type):
if flags:
raise ValueError("Cannot process flags argument with a compiled pattern")
return pattern
else:
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 as v:
raise error, v
if not bypass_cache:
if len(_cache) >= _MAXCACHE:
_cache.clear()
_cache[cachekey] = p
return p
开发者ID:webiumsk,项目名称:WOT-0.9.12-CT,代码行数:25,代码来源:re.py
示例5: _compile
def _compile(*key):
# internal: compile pattern
taint = _get_taint(key[0])
if taint is not None: # can't hash the set
taint = tuple(taint)
cachekey = (type(key[0]), key, taint)
p = re._cache.get(cachekey)
if p is not None:
return p
pattern, flags = key
if isinstance(pattern, re._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")
p = sre_compile.compile(pattern, flags)
if len(re._cache) >= re._MAXCACHE:
re._cache.clear()
re._cache[cachekey] = p
return p
开发者ID:delta-force,项目名称:deltaforce-python,代码行数:25,代码来源:taint.py
示例6: __init__
def __init__(self, lexicons, init_state=None, flags=0):
# All the regexp magic below is copied from re.Scanner from
# the standard library.
import sre_compile
import sre_parse
from sre_constants import BRANCH, SUBPATTERN
if init_state is None:
init_state = State()
if not hasattr(init_state, 'start'):
init_state.start = None
self.init_state = init_state
self.lexicons = lexicons
self.scanners = {}
for start, lexicon in lexicons.iteritems():
# combine phrases into a compound pattern
p, a = [], []
s = sre_parse.Pattern()
s.flags = flags
for phrase, action in lexicon:
p.append(sre_parse.SubPattern(s, [
(SUBPATTERN, (len(p)+1,
sre_parse.parse(phrase, flags))),
]))
a.append(action)
p = sre_parse.SubPattern(s, [(BRANCH, (None, p))])
s.groups = len(p)
self.scanners[start] = sre_compile.compile(p).match, a
开发者ID:Serabe,项目名称:geogebra,代码行数:27,代码来源:lexing.py
示例7: _compile
def _compile(pattern, flags):
# internal: compile pattern
try:
p, loc = _cache[type(pattern), pattern, flags]
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")
p = sre_compile.compile(pattern, flags)
if not (flags & DEBUG):
if len(_cache) >= _MAXCACHE:
_cache.clear()
if p.flags & LOCALE:
if not _locale:
return p
loc = _locale.setlocale(_locale.LC_CTYPE)
else:
loc = None
_cache[type(pattern), pattern, flags] = p, loc
return p
开发者ID:LibingEmail0104,项目名称:src_project,代码行数:27,代码来源:re.py
示例8: __init__
def __init__(self, lexicon, flags=FLAGS):
self.actions = [None]
# combine phrases into a compound pattern
s = sre_parse.Pattern()
s.flags = flags
p = []
# NOTE(kgibbs): These lines must be added to make this file work under
# Python 2.2, which is commonly used at Google.
def enumerate(obj):
i = -1
for item in obj:
i += 1
yield i, item
# NOTE(kgibbs): End changes.
for idx, token in enumerate(lexicon):
phrase = token.pattern
try:
subpattern = sre_parse.SubPattern(s,
[(SUBPATTERN, (idx + 1, sre_parse.parse(phrase, flags)))])
except sre_constants.error:
raise
p.append(subpattern)
self.actions.append(token)
s.groups = len(p)+1 # NOTE(guido): Added to make SRE validation work
p = sre_parse.SubPattern(s, [(BRANCH, (None, p))])
self.scanner = sre_compile.compile(p)
开发者ID:1stvamp,项目名称:brumcon9-talk,代码行数:27,代码来源:scanner.py
示例9: Sub
def Sub(self, pattern, repl, s):
"""Replace the string for the pattern by the paramter repl, caching the compiled regexp."""
# for example: s='a1234a' ,repl='OOOO' pattern = r'd+'
# result is 'aOOOOa'
#
if not pattern in self._regexp_compile_cache:
self._regexp_compile_cache[pattern] = sre_compile.compile(pattern)
return self._regexp_compile_cache[pattern].sub(repl,s)
开发者ID:299299,项目名称:PulseAudio_Work,代码行数:8,代码来源:common.py
示例10: Match
def Match(self, pattern, s):
"""Matches the string with the pattern, caching the compiled regexp."""
# The regexp compilation caching is inlined in both Match and Search for
# performance reasons; factoring it out into a separate function turns out
# to be noticeably expensive.
if not pattern in self._regexp_compile_cache:
self._regexp_compile_cache[pattern] = sre_compile.compile(pattern)
return self._regexp_compile_cache[pattern].match(s)
开发者ID:299299,项目名称:PulseAudio_Work,代码行数:8,代码来源:common.py
示例11: _compile_typed
def _compile_typed(text_bytes_type, pattern, flags):
# internal: compile pattern
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")
return sre_compile.compile(pattern, flags)
开发者ID:earney,项目名称:pycomo,代码行数:10,代码来源:re.py
示例12: __init__
def __init__(self, lexicon, flags=0):
from sre_constants import BRANCH, SUBPATTERN
self.lexicon = lexicon
p = []
s = sre_parse.Pattern()
s.flags = flags
for (phrase, action) in lexicon:
p.append(sre_parse.SubPattern(s, [(SUBPATTERN, (len(p) + 1, sre_parse.parse(phrase, flags)))]))
s.groups = len(p) + 1
p = sre_parse.SubPattern(s, [(BRANCH, (None, p))])
self.scanner = sre_compile.compile(p)
开发者ID:johndpope,项目名称:sims4-ai-engine,代码行数:11,代码来源:re.py
示例13: __init__
def __init__(self, lexicon):
from sre_constants import BRANCH, SUBPATTERN
self.lexicon = lexicon
# combine phrases into a compound pattern
p = []
s = sre_parse.Pattern()
for phrase, action in lexicon:
p.append(sre_parse.SubPattern(s, [(SUBPATTERN, (len(p), sre_parse.parse(phrase)))]))
p = sre_parse.SubPattern(s, [(BRANCH, (None, p))])
s.groups = len(p)
self.scanner = sre_compile.compile(p)
开发者ID:AngusGeek,项目名称:org.aspectj,代码行数:12,代码来源:sre.py
示例14: _compile
def _compile(*key):
# internal: compile pattern
p = _cache.get(key)
if p is not None:
return p
pattern, flags = key
if type(pattern) not in sre_compile.STRING_TYPES:
return pattern
try:
p = sre_compile.compile(pattern, flags)
except error, v:
raise error, v # invalid expression
开发者ID:AngusGeek,项目名称:org.aspectj,代码行数:12,代码来源:sre.py
示例15: _get_group_pattern
def _get_group_pattern(self,flags):
# combine phrases into a compound pattern
patterns = []
sub_pattern = sre_parse.Pattern()
sub_pattern.flags = flags
for phrase, action in self.lexicon:
patterns.append(sre_parse.SubPattern(sub_pattern, [
(SUBPATTERN, (len(patterns) + 1, sre_parse.parse(phrase, flags))),
]))
sub_pattern.groups = len(patterns) + 1
group_pattern = sre_parse.SubPattern(sub_pattern, [(BRANCH, (None, patterns))])
return sre_compile.compile(group_pattern)
开发者ID:zetsub0u,项目名称:bulbs,代码行数:12,代码来源:groovy.py
示例16: __init__
def __init__(self, lexicon, flags=0):
self.lexicon = lexicon
# combine phrases into a compound pattern
p = []
s = sre_parse.Pattern()
s.flags = flags
for phrase, action in lexicon:
p.append(sre_parse.SubPattern(s, [
(SUBPATTERN, (len(p)+1, sre_parse.parse(phrase, flags))),
]))
s.groups = len(p)+1
p = sre_parse.SubPattern(s, [(BRANCH, (None, p))])
self.scanner = sre_compile.compile(p)
开发者ID:0xBADCA7,项目名称:grumpy,代码行数:13,代码来源:re.py
示例17: _compile
def _compile(*key):
p = _cache.get(key)
if (p is not None):
return p
(pattern, flags,) = key
if (type(pattern) is _pattern_type):
return pattern
if (type(pattern) not in sre_compile.STRING_TYPES):
raise TypeError, 'first argument must be string or compiled pattern'
try:
p = sre_compile.compile(pattern, flags)
except error, v:
raise error, v
开发者ID:Etnorazz,项目名称:LeapConductor,代码行数:13,代码来源:sre.py
示例18: __init__
def __init__(self, regexp, negative=False, **property_names):
"""
Create a new C{RegexpTokenizer} from a given regular expression.
@type regexp: C{string} or C{SRE_Pattern}
@param regexp: The regular expression used to tokenized texts.
Unless C{negative} is true, this regular expression
specifies the form of a single word type; so the list of
tokens generated by tokenization includes all non-overlapping
substrings that match C{regexp}
@type negative: C{boolean}
@param negative: An optional parameter that inverts the
meaning of C{regexp}. In particular, if C{negative} is
true, then C{regexp} is taken to specify the form of word
separators (and not word types); so the list of tokens
generated by tokenization includes all substrings that
occur I{between} matches of the regular expression.
@type property_names: C{dict}
@param property_names: A dictionary that can be used to override
the default property names. Each entry maps from a
default property name to a new property name.
"""
assert chktype(1, regexp, str)
AbstractTokenizer.__init__(self, **property_names)
if hasattr(regexp, "pattern"):
regexp = regexp.pattern
self._negative = bool(negative)
# Replace any grouping parentheses with non-grouping ones. We
# need to do this, because the list returned by re.sub will
# contain an element corresponding to every set of grouping
# parentheses. We must not touch escaped parentheses, and
# need to handle the case of escaped escapes (e.g. "\\(").
# We also need to handle nested parentheses, which means our
# regexp contexts must be zero-width. There are also issues with
# parenthesis appearing in bracketed contexts, hence we've
# operated on the intermediate parse structure from sre_parse.
parsed = sre_parse.parse(regexp)
parsed = _remove_group_identifiers(parsed)
# Add grouping parentheses around the regexp; this will allow
# us to access the material that was split on.
# Need to set the Pattern to expect a single group
pattern = sre_parse.Pattern()
pattern.groups += 1
grouped = sre_parse.SubPattern(pattern)
grouped.append((sre_constants.SUBPATTERN, (1, parsed)))
self._regexp = sre_compile.compile(grouped, re.UNICODE)
开发者ID:ronaldahmed,项目名称:robot-navigation,代码行数:51,代码来源:__init__.py
示例19: _compile
def _compile(*key):
# internal: compile pattern
p = _cache.get(key)
if p is not None:
return p
pattern, flags = key
if type(pattern) is _pattern_type:
return pattern
if type(pattern) not in sre_compile.STRING_TYPES:
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
开发者ID:denis-vilyuzhanin,项目名称:OpenModelSphereMirror,代码行数:14,代码来源:sre.py
示例20: _compile
def _compile(regexp):
parsed = sre_parse.parse(regexp)
parsed = _remove_group_identifiers(parsed)
# Add grouping parentheses around the regexp; this will allow
# us to access the material that was split on.
# Need to set the Pattern to expect a single group
pattern = sre_parse.Pattern()
pattern.groups += 1
grouped = sre_parse.SubPattern(pattern)
grouped.append((sre_constants.SUBPATTERN, (1, parsed)))
return sre_compile.compile(grouped, re.UNICODE | re.MULTILINE | re.DOTALL)
开发者ID:sethwoodworth,项目名称:wikipedia-style-edits,代码行数:15,代码来源:regexp.py
注:本文中的sre_compile.compile函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论