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
0c6c6472
Commit
0c6c6472
authored
Apr 26, 2011
by
Ezio Melotti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#6780: fix starts/endswith error message to mention that tuples are accepted too.
parent
76500246
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
46 additions
and
6 deletions
+46
-6
Lib/test/test_str.py
Lib/test/test_str.py
+12
-1
Lib/test/test_unicode.py
Lib/test/test_unicode.py
+11
-0
Misc/NEWS
Misc/NEWS
+3
-0
Objects/stringobject.c
Objects/stringobject.c
+10
-2
Objects/unicodeobject.c
Objects/unicodeobject.c
+10
-3
No files found.
Lib/test/test_str.py
View file @
0c6c6472
...
...
@@ -414,7 +414,18 @@ class StrTest(
self
.
assertEqual
(
'Andr
\
202
x'
.
decode
(
'ascii'
,
'replace'
),
'Andr
\
202
x'
.
decode
(
encoding
=
'ascii'
,
errors
=
'replace'
))
def
test_startswith_endswith_errors
(
self
):
with
self
.
assertRaises
(
UnicodeDecodeError
):
'
\
xff
'
.
startswith
(
u'x'
)
with
self
.
assertRaises
(
UnicodeDecodeError
):
'
\
xff
'
.
endswith
(
u'x'
)
for
meth
in
(
'foo'
.
startswith
,
'foo'
.
endswith
):
with
self
.
assertRaises
(
TypeError
)
as
cm
:
meth
([
'f'
])
exc
=
str
(
cm
.
exception
)
self
.
assertIn
(
'unicode'
,
exc
)
self
.
assertIn
(
'str'
,
exc
)
self
.
assertIn
(
'tuple'
,
exc
)
def
test_main
():
test_support
.
run_unittest
(
StrTest
)
...
...
Lib/test/test_unicode.py
View file @
0c6c6472
...
...
@@ -442,6 +442,17 @@ class UnicodeTest(
return
u'
\
u1234
'
self
.
assertEqual
(
'%s'
%
Wrapper
(),
u'
\
u1234
'
)
def
test_startswith_endswith_errors
(
self
):
for
meth
in
(
u'foo'
.
startswith
,
u'foo'
.
endswith
):
with
self
.
assertRaises
(
UnicodeDecodeError
):
meth
(
'
\
xff
'
)
with
self
.
assertRaises
(
TypeError
)
as
cm
:
meth
([
'f'
])
exc
=
str
(
cm
.
exception
)
self
.
assertIn
(
'unicode'
,
exc
)
self
.
assertIn
(
'str'
,
exc
)
self
.
assertIn
(
'tuple'
,
exc
)
@
test_support
.
run_with_locale
(
'LC_ALL'
,
'de_DE'
,
'fr_FR'
)
def
test_format_float
(
self
):
# should not format with a comma, but always with C locale
...
...
Misc/NEWS
View file @
0c6c6472
...
...
@@ -9,6 +9,9 @@ What's New in Python 2.7.2?
Core and Builtins
-----------------
- Issue #6780: fix starts/endswith error message to mention that tuples are
accepted too.
- Issue #5057: fix a bug in the peepholer that led to non-portable pyc files
between narrow and wide builds while optimizing BINARY_SUBSCR on non-BMP
chars (e.g. u"\U00012345"[0]).
...
...
Objects/stringobject.c
View file @
0c6c6472
...
...
@@ -2918,8 +2918,12 @@ string_startswith(PyStringObject *self, PyObject *args)
Py_RETURN_FALSE
;
}
result
=
_string_tailmatch
(
self
,
subobj
,
start
,
end
,
-
1
);
if
(
result
==
-
1
)
if
(
result
==
-
1
)
{
if
(
PyErr_ExceptionMatches
(
PyExc_TypeError
))
PyErr_Format
(
PyExc_TypeError
,
"startswith first arg must be str, "
"unicode, or tuple, not %s"
,
Py_TYPE
(
subobj
)
->
tp_name
);
return
NULL
;
}
else
return
PyBool_FromLong
(
result
);
}
...
...
@@ -2958,8 +2962,12 @@ string_endswith(PyStringObject *self, PyObject *args)
Py_RETURN_FALSE
;
}
result
=
_string_tailmatch
(
self
,
subobj
,
start
,
end
,
+
1
);
if
(
result
==
-
1
)
if
(
result
==
-
1
)
{
if
(
PyErr_ExceptionMatches
(
PyExc_TypeError
))
PyErr_Format
(
PyExc_TypeError
,
"endswith first arg must be str, "
"unicode, or tuple, not %s"
,
Py_TYPE
(
subobj
)
->
tp_name
);
return
NULL
;
}
else
return
PyBool_FromLong
(
result
);
}
...
...
Objects/unicodeobject.c
View file @
0c6c6472
...
...
@@ -7666,8 +7666,12 @@ unicode_startswith(PyUnicodeObject *self,
Py_RETURN_FALSE
;
}
substring
=
(
PyUnicodeObject
*
)
PyUnicode_FromObject
(
subobj
);
if
(
substring
==
NULL
)
if
(
substring
==
NULL
)
{
if
(
PyErr_ExceptionMatches
(
PyExc_TypeError
))
PyErr_Format
(
PyExc_TypeError
,
"startswith first arg must be str, "
"unicode, or tuple, not %s"
,
Py_TYPE
(
subobj
)
->
tp_name
);
return
NULL
;
}
result
=
tailmatch
(
self
,
substring
,
start
,
end
,
-
1
);
Py_DECREF
(
substring
);
return
PyBool_FromLong
(
result
);
...
...
@@ -7710,9 +7714,12 @@ unicode_endswith(PyUnicodeObject *self,
Py_RETURN_FALSE
;
}
substring
=
(
PyUnicodeObject
*
)
PyUnicode_FromObject
(
subobj
);
if
(
substring
==
NULL
)
if
(
substring
==
NULL
)
{
if
(
PyErr_ExceptionMatches
(
PyExc_TypeError
))
PyErr_Format
(
PyExc_TypeError
,
"endswith first arg must be str, "
"unicode, or tuple, not %s"
,
Py_TYPE
(
subobj
)
->
tp_name
);
return
NULL
;
}
result
=
tailmatch
(
self
,
substring
,
start
,
end
,
+
1
);
Py_DECREF
(
substring
);
return
PyBool_FromLong
(
result
);
...
...
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