当前位置: 首页>>代码示例>>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;未经允许,请勿转载。