Python _sre.MAXREPEAT Examples
The following are 13
code examples of _sre.MAXREPEAT().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
_sre
, or try the search function
.
Example #1
Source File: sre_compile.py From jawfish with MIT License | 5 votes |
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
Example #2
Source File: test_re.py From jawfish with MIT License | 5 votes |
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)
Example #3
Source File: test_re.py From ironpython2 with Apache License 2.0 | 5 votes |
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)
Example #4
Source File: sre_compile.py From BinderFilter with MIT License | 5 votes |
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
Example #5
Source File: test_re.py From BinderFilter with MIT License | 5 votes |
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)
Example #6
Source File: test_re.py From oss-ftp with MIT License | 5 votes |
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)
Example #7
Source File: test_re.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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)
Example #8
Source File: sre_parse.py From ironpython3 with Apache License 2.0 | 5 votes |
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
Example #9
Source File: test_re.py From ironpython3 with Apache License 2.0 | 5 votes |
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)
Example #10
Source File: test_re.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #11
Source File: test_re.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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)
Example #12
Source File: test_re.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
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)
Example #13
Source File: test_re.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
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)