Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b979f10

Browse files
committed
merge with 3.3
2 parents cc75717 + 1d472b7 commit b979f10

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

Lib/sre_parse.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,25 @@ def tell(self):
225225
def seek(self, index):
226226
self.index, self.next = index
227227

228+
# The following three functions are not used in this module anymore, but we keep
229+
# them here (with DeprecationWarnings) for backwards compatibility.
230+
228231
def isident(char):
232+
import warnings
233+
warnings.warn('sre_parse.isident() will be removed in 3.5',
234+
DeprecationWarning, stacklevel=2)
229235
return "a" <= char <= "z" or "A" <= char <= "Z" or char == "_"
230236

231237
def isdigit(char):
238+
import warnings
239+
warnings.warn('sre_parse.isdigit() will be removed in 3.5',
240+
DeprecationWarning, stacklevel=2)
232241
return "0" <= char <= "9"
233242

234243
def isname(name):
244+
import warnings
245+
warnings.warn('sre_parse.isname() will be removed in 3.5',
246+
DeprecationWarning, stacklevel=2)
235247
# check that group name is a valid string
236248
if not isident(name[0]):
237249
return False
@@ -587,7 +599,7 @@ def _parse(source, state):
587599
group = 1
588600
if not name:
589601
raise error("missing group name")
590-
if not isname(name):
602+
if not name.isidentifier():
591603
raise error("bad character in group name")
592604
elif sourcematch("="):
593605
# named backreference
@@ -601,7 +613,7 @@ def _parse(source, state):
601613
name = name + char
602614
if not name:
603615
raise error("missing group name")
604-
if not isname(name):
616+
if not name.isidentifier():
605617
raise error("bad character in group name")
606618
gid = state.groupdict.get(name)
607619
if gid is None:
@@ -655,7 +667,7 @@ def _parse(source, state):
655667
group = 2
656668
if not condname:
657669
raise error("missing group name")
658-
if isname(condname):
670+
if condname.isidentifier():
659671
condgroup = state.groupdict.get(condname)
660672
if condgroup is None:
661673
raise error("unknown group name")
@@ -792,7 +804,7 @@ def literal(literal, p=p, pappend=a):
792804
if index < 0:
793805
raise error("negative group number")
794806
except ValueError:
795-
if not isname(name):
807+
if not name.isidentifier():
796808
raise error("bad character in group name")
797809
try:
798810
index = pattern.groupindex[name]

Lib/test/test_re.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ def test_symbolic_groups(self):
180180
self.assertRaises(re.error, re.compile, '(?(a))')
181181
self.assertRaises(re.error, re.compile, '(?(1a))')
182182
self.assertRaises(re.error, re.compile, '(?(a.))')
183+
# New valid/invalid identifiers in Python 3
184+
re.compile('(?P<µ>x)(?P=µ)(?(µ)y)')
185+
re.compile('(?P<𝔘𝔫𝔦𝔠𝔬𝔡𝔢>x)(?P=𝔘𝔫𝔦𝔠𝔬𝔡𝔢)(?(𝔘𝔫𝔦𝔠𝔬𝔡𝔢)y)')
186+
self.assertRaises(re.error, re.compile, '(?P<©>x)')
183187

184188
def test_symbolic_refs(self):
185189
self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<a', 'xx')
@@ -192,6 +196,10 @@ def test_symbolic_refs(self):
192196
self.assertRaises(re.error, re.sub, '(?P<a>x)|(?P<b>y)', '\g<b>', 'xx')
193197
self.assertRaises(re.error, re.sub, '(?P<a>x)|(?P<b>y)', '\\2', 'xx')
194198
self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<-1>', 'xx')
199+
# New valid/invalid identifiers in Python 3
200+
self.assertEqual(re.sub('(?P<µ>x)', r'\g<µ>', 'xx'), 'xx')
201+
self.assertEqual(re.sub('(?P<𝔘𝔫𝔦𝔠𝔬𝔡𝔢>x)', r'\g<𝔘𝔫𝔦𝔠𝔬𝔡𝔢>', 'xx'), 'xx')
202+
self.assertRaises(re.error, re.sub, '(?P<a>x)', r'\g<©>', 'xx')
195203

196204
def test_re_subn(self):
197205
self.assertEqual(re.subn("(?i)b+", "x", "bbbb BBBB"), ('x x', 2))

0 commit comments

Comments
 (0)