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


Python _sre.MAXREPEAT屬性代碼示例

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


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

示例1: _simple

# 需要導入模塊: import _sre [as 別名]
# 或者: from _sre import MAXREPEAT [as 別名]
def _simple(av):
    # check if av is a "simple" operator
    lo, hi = av[2].getwidth()
    if lo == 0 and hi == MAXREPEAT:
        raise error("nothing to repeat")
    return lo == hi == 1 and av[2][0][0] != SUBPATTERN 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:8,代碼來源:sre_compile.py

示例2: test_repeat_minmax_overflow

# 需要導入模塊: import _sre [as 別名]
# 或者: from _sre import MAXREPEAT [as 別名]
def test_repeat_minmax_overflow(self):
        # Issue #13169
        string = "x" * 100000
        self.assertEqual(re.match(r".{65535}", string).span(), (0, 65535))
        self.assertEqual(re.match(r".{,65535}", string).span(), (0, 65535))
        self.assertEqual(re.match(r".{65535,}?", string).span(), (0, 65535))
        self.assertEqual(re.match(r".{65536}", string).span(), (0, 65536))
        self.assertEqual(re.match(r".{,65536}", string).span(), (0, 65536))
        self.assertEqual(re.match(r".{65536,}?", string).span(), (0, 65536))
        # 2**128 should be big enough to overflow both SRE_CODE and Py_ssize_t.
        self.assertRaises(OverflowError, re.compile, r".{%d}" % 2**128)
        self.assertRaises(OverflowError, re.compile, r".{,%d}" % 2**128)
        self.assertRaises(OverflowError, re.compile, r".{%d,}?" % 2**128)
        self.assertRaises(OverflowError, re.compile, r".{%d,%d}" % (2**129, 2**128))

    # FIXME: brython: implement test.support
#    @cpython_only
#    def test_repeat_minmax_overflow_maxrepeat(self):
#        try:
#            from _sre import MAXREPEAT
#        except ImportError:
#            self.skipTest('requires _sre.MAXREPEAT constant')
#        string = "x" * 100000
#        self.assertIsNone(re.match(r".{%d}" % (MAXREPEAT - 1), string))
#        self.assertEqual(re.match(r".{,%d}" % (MAXREPEAT - 1), string).span(),
#                         (0, 100000))
#        self.assertIsNone(re.match(r".{%d,}?" % (MAXREPEAT - 1), string))
#        self.assertRaises(OverflowError, re.compile, r".{%d}" % MAXREPEAT)
#        self.assertRaises(OverflowError, re.compile, r".{,%d}" % MAXREPEAT)
#        self.assertRaises(OverflowError, re.compile, r".{%d,}?" % MAXREPEAT) 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:32,代碼來源:test_re.py

示例3: test_repeat_minmax_overflow_maxrepeat

# 需要導入模塊: import _sre [as 別名]
# 或者: from _sre import MAXREPEAT [as 別名]
def test_repeat_minmax_overflow_maxrepeat(self):
        try:
            from _sre import MAXREPEAT
        except ImportError:
            self.skipTest('requires _sre.MAXREPEAT constant')
        string = "x" * 100000
        self.assertIsNone(re.match(r".{%d}" % (MAXREPEAT - 1), string))
        self.assertEqual(re.match(r".{,%d}" % (MAXREPEAT - 1), string).span(),
                         (0, 100000))
        self.assertIsNone(re.match(r".{%d,}?" % (MAXREPEAT - 1), string))
        self.assertRaises(OverflowError, re.compile, r".{%d}" % MAXREPEAT)
        self.assertRaises(OverflowError, re.compile, r".{,%d}" % MAXREPEAT)
        self.assertRaises(OverflowError, re.compile, r".{%d,}?" % MAXREPEAT) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:15,代碼來源:test_re.py

示例4: _simple

# 需要導入模塊: import _sre [as 別名]
# 或者: from _sre import MAXREPEAT [as 別名]
def _simple(av):
    # check if av is a "simple" operator
    lo, hi = av[2].getwidth()
    if lo == 0 and hi == MAXREPEAT:
        raise error, "nothing to repeat"
    return lo == hi == 1 and av[2][0][0] != SUBPATTERN 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:8,代碼來源:sre_compile.py

示例5: getwidth

# 需要導入模塊: import _sre [as 別名]
# 或者: from _sre import MAXREPEAT [as 別名]
def getwidth(self):
        # determine the width (min, max) for this subpattern
        if self.width:
            return self.width
        lo = hi = 0
        UNITCODES = (ANY, RANGE, IN, LITERAL, NOT_LITERAL, CATEGORY)
        REPEATCODES = (MIN_REPEAT, MAX_REPEAT)
        for op, av in self.data:
            if op is BRANCH:
                i = MAXREPEAT - 1
                j = 0
                for av in av[1]:
                    l, h = av.getwidth()
                    i = min(i, l)
                    j = max(j, h)
                lo = lo + i
                hi = hi + j
            elif op is CALL:
                i, j = av.getwidth()
                lo = lo + i
                hi = hi + j
            elif op is SUBPATTERN:
                i, j = av[1].getwidth()
                lo = lo + i
                hi = hi + j
            elif op in REPEATCODES:
                i, j = av[2].getwidth()
                lo = lo + i * av[0]
                hi = hi + j * av[1]
            elif op in UNITCODES:
                lo = lo + 1
                hi = hi + 1
            elif op == SUCCESS:
                break
        self.width = min(lo, MAXREPEAT - 1), min(hi, MAXREPEAT)
        return self.width 
開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:38,代碼來源:sre_parse.py


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