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
1644e6eb
Commit
1644e6eb
authored
Sep 17, 2007
by
Sean Reifscheider
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
issue1140: Guido's patch from revision 58098 (2.6) applied to 2.5.
parent
b5ec5876
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
17 deletions
+33
-17
Lib/test/test_re.py
Lib/test/test_re.py
+25
-0
Modules/_sre.c
Modules/_sre.c
+8
-17
No files found.
Lib/test/test_re.py
View file @
1644e6eb
...
...
@@ -83,6 +83,31 @@ class ReTests(unittest.TestCase):
self.assertEqual(re.sub('
\
r
\
n
', '
\
n
', '
abc
\
r
\
ndef
\
r
\
n
'),
'
abc
\
ndef
\
n
')
def test_bug_1140(self):
# re.sub(x, y, u'') should return u'', not '', and
# re.sub(x, y, '') should return '', not u''.
# Also:
# re.sub(x, y, unicode(x)) should return unicode(y), and
# re.sub(x, y, str(x)) should return
# str(y) if isinstance(y, str) else unicode(y).
for x in '
x
', u'
x
':
for y in '
y
', u'
y
':
z = re.sub(x, y, u'')
self.assertEqual(z, u'')
self.assertEqual(type(z), unicode)
#
z = re.sub(x, y, '')
self.assertEqual(z, '')
self.assertEqual(type(z), str)
#
z = re.sub(x, y, unicode(x))
self.assertEqual(z, y)
self.assertEqual(type(z), unicode)
#
z = re.sub(x, y, str(x))
self.assertEqual(z, y)
self.assertEqual(type(z), type(y))
def test_sub_template_numeric_escape(self):
# bug 776311 and friends
self.assertEqual(re.sub('
x
', r'
\
0
', '
x
'), '
\
0
')
...
...
Modules/_sre.c
View file @
1644e6eb
...
...
@@ -1979,7 +1979,7 @@ deepcopy(PyObject** object, PyObject* memo)
#endif
static
PyObject
*
join_list
(
PyObject
*
list
,
PyObject
*
pattern
)
join_list
(
PyObject
*
list
,
PyObject
*
string
)
{
/* join list elements */
...
...
@@ -1990,24 +1990,15 @@ join_list(PyObject* list, PyObject* pattern)
#endif
PyObject
*
result
;
switch
(
PyList_GET_SIZE
(
list
))
{
case
0
:
Py_DECREF
(
list
);
return
PySequence_GetSlice
(
pattern
,
0
,
0
);
case
1
:
result
=
PyList_GET_ITEM
(
list
,
0
);
Py_INCREF
(
result
);
Py_DECREF
(
list
);
return
result
;
}
/* two or more elements: slice out a suitable separator from the
first member, and use that to join the entire list */
joiner
=
PySequence_GetSlice
(
pattern
,
0
,
0
);
joiner
=
PySequence_GetSlice
(
string
,
0
,
0
);
if
(
!
joiner
)
return
NULL
;
if
(
PyList_GET_SIZE
(
list
)
==
0
)
{
Py_DECREF
(
list
);
return
joiner
;
}
#if PY_VERSION_HEX >= 0x01060000
function
=
PyObject_GetAttrString
(
joiner
,
"join"
);
if
(
!
function
)
{
...
...
@@ -2443,7 +2434,7 @@ next:
Py_DECREF
(
filter
);
/* convert list to single string (also removes list) */
item
=
join_list
(
list
,
s
elf
->
pattern
);
item
=
join_list
(
list
,
s
tring
);
if
(
!
item
)
return
NULL
;
...
...
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