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


Python sre_compile.compile方法代码示例

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


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

示例1: _compile

# 需要导入模块: import sre_compile [as 别名]
# 或者: from sre_compile import compile [as 别名]
def _compile(pattern, flags):
    # internal: compile pattern
    try:
        #fixme brython
        #return _cache[type(pattern), pattern, flags]
        return _cache["%s:%s:%s" % (type(pattern), pattern, flags)]
    except KeyError:
       pass
    #print(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")
    p = sre_compile.compile(pattern, flags)
    #print('_compile', p)
    if len(_cache) >= _MAXCACHE:
        _cache.clear()
    #fix me brython
    #_cache[type(pattern), pattern, flags] = p
    _cache["%s:%s:%s" % (type(pattern), pattern, flags)]= p
    return p 
开发者ID:war-and-code,项目名称:jawfish,代码行数:26,代码来源:re.py

示例2: _compile

# 需要导入模块: import sre_compile [as 别名]
# 或者: from sre_compile import compile [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 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:24,代码来源:re.py

示例3: _compile

# 需要导入模块: import sre_compile [as 别名]
# 或者: from sre_compile import compile [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 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:19,代码来源:re.py

示例4: ReplaceAll

# 需要导入模块: import sre_compile [as 别名]
# 或者: from sre_compile import compile [as 别名]
def ReplaceAll(pattern, rep, s):
  """Replaces instances of pattern in a string with a replacement.

  The compiled regex is kept in a cache shared by Match and Search.

  Args:
    pattern: regex pattern
    rep: replacement text
    s: search string

  Returns:
    string with replacements made (or original string if no replacements)
  """
  if pattern not in _regexp_compile_cache:
    _regexp_compile_cache[pattern] = sre_compile.compile(pattern)
  return _regexp_compile_cache[pattern].sub(rep, s) 
开发者ID:msracver,项目名称:Deep-Exemplar-based-Colorization,代码行数:18,代码来源:cpp_lint.py

示例5: _compile

# 需要导入模块: import sre_compile [as 别名]
# 或者: from sre_compile import compile [as 别名]
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:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:27,代码来源:re.py

示例6: __init__

# 需要导入模块: import sre_compile [as 别名]
# 或者: from sre_compile import compile [as 别名]
def __init__(self, lexicon, flags=0):
        from sre_constants import BRANCH, SUBPATTERN
        if isinstance(flags, RegexFlag):
            flags = flags.value
        self.lexicon = lexicon
        # combine phrases into a compound pattern
        p = []
        s = sre_parse.Pattern()
        s.flags = flags
        for phrase, action in lexicon:
            gid = s.opengroup()
            p.append(sre_parse.SubPattern(s, [
                (SUBPATTERN, (gid, 0, 0, sre_parse.parse(phrase, flags))),
                ]))
            s.closegroup(gid, p[-1])
        p = sre_parse.SubPattern(s, [(BRANCH, (None, p))])
        self.scanner = sre_compile.compile(p) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:19,代码来源:re.py

示例7: compile

# 需要导入模块: import sre_compile [as 别名]
# 或者: from sre_compile import compile [as 别名]
def compile(pattern, flags=0):
    "Compile a regular expression pattern, returning a pattern object."
    #print("_re.py:214")
    return _compile(pattern, flags) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:6,代码来源:re.py

示例8: _compile_repl

# 需要导入模块: import sre_compile [as 别名]
# 或者: from sre_compile import compile [as 别名]
def _compile_repl(repl, pattern):
    # internal: compile replacement pattern
    try:
        #fix me brython
        #return _cache_repl[repl, pattern]
        return _cache_repl["%s:%s" % (repl, pattern)]
    except KeyError:
        pass
    p = sre_parse.parse_template(repl, pattern)
    if len(_cache_repl) >= _MAXCACHE:
        _cache_repl.clear()
    _cache_repl["%s:%s" % (repl, pattern)] = p
    #fix me brython
    #_cache_repl[repl, pattern] = p
    return p 
开发者ID:war-and-code,项目名称:jawfish,代码行数:17,代码来源:re.py

示例9: __init__

# 需要导入模块: import sre_compile [as 别名]
# 或者: from sre_compile import compile [as 别名]
def __init__(self, lexicon, flags=0):
        from sre_constants import BRANCH, SUBPATTERN
        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:war-and-code,项目名称:jawfish,代码行数:16,代码来源:re.py

示例10: _compile

# 需要导入模块: import sre_compile [as 别名]
# 或者: from sre_compile import compile [as 别名]
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:rafasashi,项目名称:razzy-spinner,代码行数:17,代码来源:regexp.py

示例11: compile

# 需要导入模块: import sre_compile [as 别名]
# 或者: from sre_compile import compile [as 别名]
def compile(pattern, flags=0):
    "Compile a regular expression pattern, returning a pattern object."
    return _compile(pattern, flags) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:5,代码来源:re.py

示例12: _compile_repl

# 需要导入模块: import sre_compile [as 别名]
# 或者: from sre_compile import compile [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 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:re.py

示例13: _compile

# 需要导入模块: import sre_compile [as 别名]
# 或者: from sre_compile import compile [as 别名]
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:awemulya,项目名称:kobo-predict,代码行数:29,代码来源:re.py

示例14: _compile_repl

# 需要导入模块: import sre_compile [as 别名]
# 或者: from sre_compile import compile [as 别名]
def _compile_repl(repl, pattern):
    # internal: compile replacement pattern
    try:
        return _cache_repl[repl, pattern]
    except KeyError:
        pass
    p = sre_parse.parse_template(repl, pattern)
    if len(_cache_repl) >= _MAXCACHE:
        _cache_repl.clear()
    _cache_repl[repl, pattern] = p
    return p 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:13,代码来源:re.py

示例15: __init__

# 需要导入模块: import sre_compile [as 别名]
# 或者: from sre_compile import compile [as 别名]
def __init__(self, lexicon, flags=0):
        from sre_constants import BRANCH, SUBPATTERN
        self.lexicon = lexicon
        # combine phrases into a compound pattern
        p = []
        s = sre_parse.Pattern()
        s.flags = flags
        for phrase, action in lexicon:
            gid = s.opengroup()
            p.append(sre_parse.SubPattern(s, [
                (SUBPATTERN, (gid, sre_parse.parse(phrase, flags))),
                ]))
            s.closegroup(gid, p[-1])
        p = sre_parse.SubPattern(s, [(BRANCH, (None, p))])
        self.scanner = sre_compile.compile(p) 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:17,代码来源:re.py


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