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
bf1253b2
Commit
bf1253b2
authored
Apr 26, 2011
by
Ezio Melotti
Browse files
Options
Browse Files
Download
Plain Diff
#6780: merge with 3.2.
parents
dff18b08
f2b3f780
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
53 additions
and
9 deletions
+53
-9
Lib/test/test_bytes.py
Lib/test/test_bytes.py
+10
-0
Lib/test/test_unicode.py
Lib/test/test_unicode.py
+8
-0
Misc/NEWS
Misc/NEWS
+3
-0
Objects/bytearrayobject.c
Objects/bytearrayobject.c
+12
-4
Objects/bytesobject.c
Objects/bytesobject.c
+10
-2
Objects/unicodeobject.c
Objects/unicodeobject.c
+10
-3
No files found.
Lib/test/test_bytes.py
View file @
bf1253b2
...
...
@@ -305,6 +305,11 @@ class BaseBytesTest(unittest.TestCase):
self
.
assertTrue
(
b
.
startswith
(
b"h"
))
self
.
assertFalse
(
b
.
startswith
(
b"hellow"
))
self
.
assertFalse
(
b
.
startswith
(
b"ha"
))
with
self
.
assertRaises
(
TypeError
)
as
cm
:
b
.
startswith
([
b'h'
])
exc
=
str
(
cm
.
exception
)
self
.
assertIn
(
'bytes'
,
exc
)
self
.
assertIn
(
'tuple'
,
exc
)
def
test_endswith
(
self
):
b
=
self
.
type2test
(
b'hello'
)
...
...
@@ -314,6 +319,11 @@ class BaseBytesTest(unittest.TestCase):
self
.
assertTrue
(
b
.
endswith
(
b"o"
))
self
.
assertFalse
(
b
.
endswith
(
b"whello"
))
self
.
assertFalse
(
b
.
endswith
(
b"no"
))
with
self
.
assertRaises
(
TypeError
)
as
cm
:
b
.
endswith
([
b'o'
])
exc
=
str
(
cm
.
exception
)
self
.
assertIn
(
'bytes'
,
exc
)
self
.
assertIn
(
'tuple'
,
exc
)
def
test_find
(
self
):
b
=
self
.
type2test
(
b'mississippi'
)
...
...
Lib/test/test_unicode.py
View file @
bf1253b2
...
...
@@ -819,6 +819,14 @@ class UnicodeTest(string_tests.CommonTest,
self
.
assertEqual
(
'%f'
%
INF
,
'inf'
)
self
.
assertEqual
(
'%F'
%
INF
,
'INF'
)
def
test_startswith_endswith_errors
(
self
):
for
meth
in
(
'foo'
.
startswith
,
'foo'
.
endswith
):
with
self
.
assertRaises
(
TypeError
)
as
cm
:
meth
([
'f'
])
exc
=
str
(
cm
.
exception
)
self
.
assertIn
(
'str'
,
exc
)
self
.
assertIn
(
'tuple'
,
exc
)
@
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 @
bf1253b2
...
...
@@ -10,6 +10,9 @@ What's New in Python 3.3 Alpha 1?
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. "\U00012345"[0]).
...
...
Objects/bytearrayobject.c
View file @
bf1253b2
...
...
@@ -1304,7 +1304,7 @@ PyDoc_STRVAR(startswith__doc__,
Return True if B starts with the specified prefix, False otherwise.
\n
\
With optional start, test B beginning at that position.
\n
\
With optional end, stop comparing B at that position.
\n
\
prefix can also be a tuple of
string
s to try."
);
prefix can also be a tuple of
byte
s to try."
);
static
PyObject
*
bytearray_startswith
(
PyByteArrayObject
*
self
,
PyObject
*
args
)
...
...
@@ -1331,8 +1331,12 @@ bytearray_startswith(PyByteArrayObject *self, PyObject *args)
Py_RETURN_FALSE
;
}
result
=
_bytearray_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 bytes "
"or a tuple of bytes, not %s"
,
Py_TYPE
(
subobj
)
->
tp_name
);
return
NULL
;
}
else
return
PyBool_FromLong
(
result
);
}
...
...
@@ -1343,7 +1347,7 @@ PyDoc_STRVAR(endswith__doc__,
Return True if B ends with the specified suffix, False otherwise.
\n
\
With optional start, test B beginning at that position.
\n
\
With optional end, stop comparing B at that position.
\n
\
suffix can also be a tuple of
string
s to try."
);
suffix can also be a tuple of
byte
s to try."
);
static
PyObject
*
bytearray_endswith
(
PyByteArrayObject
*
self
,
PyObject
*
args
)
...
...
@@ -1370,8 +1374,12 @@ bytearray_endswith(PyByteArrayObject *self, PyObject *args)
Py_RETURN_FALSE
;
}
result
=
_bytearray_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 bytes or "
"a tuple of bytes, not %s"
,
Py_TYPE
(
subobj
)
->
tp_name
);
return
NULL
;
}
else
return
PyBool_FromLong
(
result
);
}
...
...
Objects/bytesobject.c
View file @
bf1253b2
...
...
@@ -2224,8 +2224,12 @@ bytes_startswith(PyBytesObject *self, PyObject *args)
Py_RETURN_FALSE
;
}
result
=
_bytes_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 bytes "
"or a tuple of bytes, not %s"
,
Py_TYPE
(
subobj
)
->
tp_name
);
return
NULL
;
}
else
return
PyBool_FromLong
(
result
);
}
...
...
@@ -2264,8 +2268,12 @@ bytes_endswith(PyBytesObject *self, PyObject *args)
Py_RETURN_FALSE
;
}
result
=
_bytes_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 bytes or "
"a tuple of bytes, not %s"
,
Py_TYPE
(
subobj
)
->
tp_name
);
return
NULL
;
}
else
return
PyBool_FromLong
(
result
);
}
...
...
Objects/unicodeobject.c
View file @
bf1253b2
...
...
@@ -9101,8 +9101,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 or "
"a tuple of str, not %s"
,
Py_TYPE
(
subobj
)
->
tp_name
);
return
NULL
;
}
result
=
tailmatch
(
self
,
substring
,
start
,
end
,
-
1
);
Py_DECREF
(
substring
);
return
PyBool_FromLong
(
result
);
...
...
@@ -9145,9 +9149,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 or "
"a tuple of str, 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