diff --git a/Lib/_sre.py b/Lib/_sre.py index 3baa8e953..f8a919c55 100644 --- a/Lib/_sre.py +++ b/Lib/_sre.py @@ -249,6 +249,9 @@ class SRE_Match(object): else: self.lastgroup = None + def __getitem__(self, rank): + return self.group(rank) + def _create_regs(self, state): """Creates a tuple of index pairs representing matched groups.""" regs = [(state.start, state.string_position)] @@ -317,7 +320,7 @@ class SRE_Match(object): The default argument is used for groups that did not participate in the match (defaults to None).""" groupdict = {} - for key, value in list(self.re.groupindex.items()): + for key, value in self.re.groupindex.items(): groupdict[key] = self._get_slice(value, default) return groupdict @@ -344,8 +347,10 @@ class SRE_Match(object): class _State(object): def __init__(self, string, start, end, flags): + if isinstance(string, bytearray): + string = str(bytes(string), "latin1") if isinstance(string, bytes): - string = string.decode() + string = str(string, "latin1") self.string = string if start < 0: start = 0 @@ -654,6 +659,10 @@ class _OpcodeDispatcher(_Dispatcher): self.general_op_literal(ctx, operator.eq, ctx.state.lower) return True + def op_literal_uni_ignore(self, ctx): + self.general_op_literal(ctx, operator.eq, ctx.state.lower) + return True + def op_not_literal_ignore(self, ctx): # match literal regardless of case # @@ -731,6 +740,10 @@ class _OpcodeDispatcher(_Dispatcher): self.general_op_in(ctx, ctx.state.lower) return True + def op_in_uni_ignore(self, ctx): + self.general_op_in(ctx, ctx.state.lower) + return True + def op_jump(self, ctx): # jump forward # diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py index 3dfdc3667..37cbc6f79 100644 --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -452,8 +452,6 @@ class ReTests(unittest.TestCase): self.assertEqual(m.group(2, 1), ('b', 'a')) self.assertEqual(m.group(Index(2), Index(1)), ('b', 'a')) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_match_getitem(self): pat = re.compile('(?:(?Pa)|(?Pb))(?Pc)?') @@ -1189,8 +1187,6 @@ class ReTests(unittest.TestCase): self.checkPatternError(r"[\U00110000]", r'bad escape \U00110000', 1) self.assertTrue(re.match(r"[\U0001d49c-\U0001d4b5]", "\U0001d49e")) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_sre_byte_literals(self): for i in [0, 8, 16, 32, 64, 127, 128, 255]: self.assertTrue(re.match((r"\%03o" % i).encode(), bytes([i]))) @@ -1212,8 +1208,6 @@ class ReTests(unittest.TestCase): self.checkPatternError(br"\x1", r'incomplete escape \x1', 0) self.checkPatternError(br"\x1z", r'incomplete escape \x1', 0) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_sre_byte_class_literals(self): for i in [0, 8, 16, 32, 64, 127, 128, 255]: self.assertTrue(re.match((r"[\%o]" % i).encode(), bytes([i])))