Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
68600aff
Commit
68600aff
authored
Nov 03, 2012
by
Ezio Melotti
Browse files
Options
Browse Files
Download
Plain Diff
#12759: merge with 3.2.
parents
befaac03
0941d9fc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
1 deletion
+30
-1
Lib/sre_parse.py
Lib/sre_parse.py
+7
-1
Lib/test/test_re.py
Lib/test/test_re.py
+20
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/sre_parse.py
View file @
68600aff
...
...
@@ -580,6 +580,8 @@ def _parse(source, state):
break
name
=
name
+
char
group
=
1
if
not
name
:
raise
error
(
"missing group name"
)
if
not
isname
(
name
):
raise
error
(
"bad character in group name"
)
elif
sourcematch
(
"="
):
...
...
@@ -592,6 +594,8 @@ def _parse(source, state):
if
char
==
")"
:
break
name
=
name
+
char
if
not
name
:
raise
error
(
"missing group name"
)
if
not
isname
(
name
):
raise
error
(
"bad character in group name"
)
gid
=
state
.
groupdict
.
get
(
name
)
...
...
@@ -644,6 +648,8 @@ def _parse(source, state):
break
condname
=
condname
+
char
group
=
2
if
not
condname
:
raise
error
(
"missing group name"
)
if
isname
(
condname
):
condgroup
=
state
.
groupdict
.
get
(
condname
)
if
condgroup
is
None
:
...
...
@@ -775,7 +781,7 @@ def parse_template(source, pattern):
break
name
=
name
+
char
if
not
name
:
raise
error
(
"
bad
group name"
)
raise
error
(
"
missing
group name"
)
try
:
index
=
int
(
name
)
if
index
<
0
:
...
...
Lib/test/test_re.py
View file @
68600aff
...
...
@@ -161,11 +161,31 @@ class ReTests(unittest.TestCase):
self.assertEqual(re.sub('
x
*
', '
-
', '
abxd
'), '
-
a
-
b
-
d
-
')
self.assertEqual(re.sub('
x
+
', '
-
', '
abxd
'), '
ab
-
d
')
def test_symbolic_groups(self):
re.compile('
(
?
P
<
a
>
x
)(
?
P
=
a
)(
?
(
a
)
y
)
')
re.compile('
(
?
P
<
a1
>
x
)(
?
P
=
a1
)(
?
(
a1
)
y
)
')
self.assertRaises(re.error, re.compile, '
(
?
P
<
a
>
)(
?
P
<
a
>
)
')
self.assertRaises(re.error, re.compile, '
(
?
Px
)
')
self.assertRaises(re.error, re.compile, '
(
?
P
=
)
')
self.assertRaises(re.error, re.compile, '
(
?
P
=
1
)
')
self.assertRaises(re.error, re.compile, '
(
?
P
=
a
)
')
self.assertRaises(re.error, re.compile, '
(
?
P
=
a1
)
')
self.assertRaises(re.error, re.compile, '
(
?
P
=
a
.)
')
self.assertRaises(re.error, re.compile, '
(
?
P
<
)
')
self.assertRaises(re.error, re.compile, '
(
?
P
<>
)
')
self.assertRaises(re.error, re.compile, '
(
?
P
<
1
>
)
')
self.assertRaises(re.error, re.compile, '
(
?
P
<
a
.
>
)
')
self.assertRaises(re.error, re.compile, '
(
?
())
')
self.assertRaises(re.error, re.compile, '
(
?
(
a
))
')
self.assertRaises(re.error, re.compile, '
(
?
(
1
a
))
')
self.assertRaises(re.error, re.compile, '
(
?
(
a
.))
')
def test_symbolic_refs(self):
self.assertRaises(re.error, re.sub, '
(
?
P
<
a
>
x
)
', '
\
g
<
a
', '
xx
')
self.assertRaises(re.error, re.sub, '
(
?
P
<
a
>
x
)
', '
\
g
<
', '
xx
')
self.assertRaises(re.error, re.sub, '
(
?
P
<
a
>
x
)
', '
\
g
', '
xx
')
self.assertRaises(re.error, re.sub, '
(
?
P
<
a
>
x
)
', '
\
g
<
a
a
>
', '
xx
')
self.assertRaises(re.error, re.sub, '
(
?
P
<
a
>
x
)
', '
\
g
<>
', '
xx
')
self.assertRaises(re.error, re.sub, '
(
?
P
<
a
>
x
)
', '
\
g
<
1
a1
>
', '
xx
')
self.assertRaises(IndexError, re.sub, '
(
?
P
<
a
>
x
)
', '
\
g
<
ab
>
', '
xx
')
self.assertRaises(re.error, re.sub, '
(
?
P
<
a
>
x
)
|
(
?
P
<
b
>
y
)
', '
\
g
<
b
>
', '
xx
')
...
...
Misc/NEWS
View file @
68600aff
...
...
@@ -61,6 +61,9 @@ Core and Builtins
Library
-------
-
Issue
#
12759
:
sre_parse
now
raises
a
proper
error
when
the
name
of
the
group
is
missing
.
Initial
patch
by
Serhiy
Storchaka
.
-
Issue
#
16152
:
fix
tokenize
to
ignore
whitespace
at
the
end
of
the
code
when
no
newline
is
found
.
Patch
by
Ned
Batchelder
.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment