當前位置: 首頁>>代碼示例>>Python>>正文


Python sre_compile.isstring方法代碼示例

本文整理匯總了Python中sre_compile.isstring方法的典型用法代碼示例。如果您正苦於以下問題:Python sre_compile.isstring方法的具體用法?Python sre_compile.isstring怎麽用?Python sre_compile.isstring使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sre_compile的用法示例。


在下文中一共展示了sre_compile.isstring方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _compile

# 需要導入模塊: import sre_compile [as 別名]
# 或者: from sre_compile import isstring [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 isstring [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 isstring [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: _compile

# 需要導入模塊: import sre_compile [as 別名]
# 或者: from sre_compile import isstring [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

示例5: _compile

# 需要導入模塊: import sre_compile [as 別名]
# 或者: from sre_compile import isstring [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

示例6: _compile

# 需要導入模塊: import sre_compile [as 別名]
# 或者: from sre_compile import isstring [as 別名]
def _compile(pattern, flags):
    # internal: compile pattern
    bypass_cache = flags & DEBUG
    if not bypass_cache:
        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 bypass_cache:
        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:IronLanguages,項目名稱:ironpython3,代碼行數:31,代碼來源:re.py

示例7: _compile

# 需要導入模塊: import sre_compile [as 別名]
# 或者: from sre_compile import isstring [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 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:17,代碼來源:re.py


注:本文中的sre_compile.isstring方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。