mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Bring some code from brython master
This commit is contained in:
1 parent
c0fc94fc2b
commit
d099831bbf
2 files changed
+15
-8
No files matched your search
Vendored
+15
-2
@@ -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
|
||||
# <LITERAL_IGNORE> <code>
|
||||
@@ -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
|
||||
# <JUMP> <offset>
|
||||
|
||||
@@ -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('(?:(?P<a1>a)|(?P<b2>b))(?P<c3>c)?')
|
||||
|
||||
@@ -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])))
|
||||
|
||||
Reference in new issue
Block a user