summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Doc/c-api/init.rst2
-rw-r--r--Doc/library/subprocess.rst2
-rw-r--r--Include/pyport.h4
-rw-r--r--Lib/collections.py22
-rw-r--r--Lib/test/string_tests.py57
-rw-r--r--Lib/test/test_bytes.py62
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS6
-rw-r--r--Objects/bytearrayobject.c13
-rw-r--r--Objects/bytesobject.c23
-rw-r--r--Objects/complexobject.c4
-rw-r--r--Objects/floatobject.c4
-rw-r--r--Objects/stringlib/find.h67
-rw-r--r--Objects/unicodeobject.c35
-rw-r--r--Python/sysmodule.c60
15 files changed, 221 insertions, 141 deletions
diff --git a/Doc/c-api/init.rst b/Doc/c-api/init.rst
index 12abf1e..e78add1 100644
--- a/Doc/c-api/init.rst
+++ b/Doc/c-api/init.rst
@@ -472,7 +472,7 @@ the fork, and releasing them afterwards. In addition, it resets any
:ref:`lock-objects` in the child. When extending or embedding Python, there
is no way to inform Python of additional (non-Python) locks that need to be
acquired before or reset after a fork. OS facilities such as
-:cfunc:`posix_atfork` would need to be used to accomplish the same thing.
+:cfunc:`pthread_atfork` would need to be used to accomplish the same thing.
Additionally, when extending or embedding Python, calling :cfunc:`fork`
directly rather than through :func:`os.fork` (and returning to or calling
into Python) may result in a deadlock by one of Python's internal locks
diff --git a/Doc/library/subprocess.rst b/Doc/library/subprocess.rst
index 7188b95..f146683 100644
--- a/Doc/library/subprocess.rst
+++ b/Doc/library/subprocess.rst
@@ -193,7 +193,7 @@ This module defines one class called :class:`Popen`:
Convenience Functions
^^^^^^^^^^^^^^^^^^^^^
-This module also defines four shortcut functions:
+This module also defines the following shortcut functions:
.. function:: call(*popenargs, **kwargs)
diff --git a/Include/pyport.h b/Include/pyport.h
index 13396a2..17a5379 100644
--- a/Include/pyport.h
+++ b/Include/pyport.h
@@ -279,6 +279,10 @@ typedef Py_intptr_t Py_ssize_t;
#include <stdlib.h>
+#ifdef HAVE_IEEEFP_H
+#include <ieeefp.h> /* needed for 'finite' declaration on some platforms */
+#endif
+
#include <math.h> /* Moved here from the math section, before extern "C" */
/********************************************
diff --git a/Lib/collections.py b/Lib/collections.py
index fb9464f..b2a590b 100644
--- a/Lib/collections.py
+++ b/Lib/collections.py
@@ -98,21 +98,11 @@ class OrderedDict(dict):
yield curr.key
curr = curr.prev
- def __reduce__(self):
- 'Return state information for pickling'
- items = [[k, self[k]] for k in self]
- tmp = self.__map, self.__root, self.__in_repr
- del self.__map, self.__root, self.__in_repr
- inst_dict = vars(self).copy()
- self.__map, self.__root, self.__in_repr = tmp
- if inst_dict:
- return (self.__class__, (items,), inst_dict)
- return self.__class__, (items,)
-
update = __update = MutableMapping.update
keys = MutableMapping.keys
values = MutableMapping.values
items = MutableMapping.items
+ __ne__ = MutableMapping.__ne__
__marker = object()
@@ -156,6 +146,16 @@ class OrderedDict(dict):
self.__in_repr = False
return result
+ def __reduce__(self):
+ 'Return state information for pickling'
+ items = [[k, self[k]] for k in self]
+ inst_dict = vars(self).copy()
+ for k in vars(OrderedDict()):
+ inst_dict.pop(k, None)
+ if inst_dict:
+ return (self.__class__, (items,), inst_dict)
+ return self.__class__, (items,)
+
def copy(self):
'od.copy() -> a shallow copy of od'
return self.__class__(self)
diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py
index a813616..09622dd 100644
--- a/Lib/test/string_tests.py
+++ b/Lib/test/string_tests.py
@@ -1156,6 +1156,63 @@ class MixinStrUnicodeUserStringTest:
self.checkraises(ValueError, S, 'rpartition', '')
self.checkraises(TypeError, S, 'rpartition', None)
+ def test_none_arguments(self):
+ # issue 11828
+ s = 'hello'
+ self.checkequal(2, s, 'find', 'l', None)
+ self.checkequal(3, s, 'find', 'l', -2, None)
+ self.checkequal(2, s, 'find', 'l', None, -2)
+ self.checkequal(0, s, 'find', 'h', None, None)
+
+ self.checkequal(3, s, 'rfind', 'l', None)
+ self.checkequal(3, s, 'rfind', 'l', -2, None)
+ self.checkequal(2, s, 'rfind', 'l', None, -2)
+ self.checkequal(0, s, 'rfind', 'h', None, None)
+
+ self.checkequal(2, s, 'index', 'l', None)
+ self.checkequal(3, s, 'index', 'l', -2, None)
+ self.checkequal(2, s, 'index', 'l', None, -2)
+ self.checkequal(0, s, 'index', 'h', None, None)
+
+ self.checkequal(3, s, 'rindex', 'l', None)
+ self.checkequal(3, s, 'rindex', 'l', -2, None)
+ self.checkequal(2, s, 'rindex', 'l', None, -2)
+ self.checkequal(0, s, 'rindex', 'h', None, None)
+
+ self.checkequal(2, s, 'count', 'l', None)
+ self.checkequal(1, s, 'count', 'l', -2, None)
+ self.checkequal(1, s, 'count', 'l', None, -2)
+ self.checkequal(0, s, 'count', 'x', None, None)
+
+ self.checkequal(True, s, 'endswith', 'o', None)
+ self.checkequal(True, s, 'endswith', 'lo', -2, None)
+ self.checkequal(True, s, 'endswith', 'l', None, -2)
+ self.checkequal(False, s, 'endswith', 'x', None, None)
+
+ self.checkequal(True, s, 'startswith', 'h', None)
+ self.checkequal(True, s, 'startswith', 'l', -2, None)
+ self.checkequal(True, s, 'startswith', 'h', None, -2)
+ self.checkequal(False, s, 'startswith', 'x', None, None)
+
+ def test_find_etc_raise_correct_error_messages(self):
+ # issue 11828
+ s = 'hello'
+ x = 'x'
+ self.assertRaisesRegexp(TypeError, r'^find\(', s.find,
+ x, None, None, None)
+ self.assertRaisesRegexp(TypeError, r'^rfind\(', s.rfind,
+ x, None, None, None)
+ self.assertRaisesRegexp(TypeError, r'^index\(', s.index,
+ x, None, None, None)
+ self.assertRaisesRegexp(TypeError, r'^rindex\(', s.rindex,
+ x, None, None, None)
+ self.assertRaisesRegexp(TypeError, r'^count\(', s.count,
+ x, None, None, None)
+ self.assertRaisesRegexp(TypeError, r'^startswith\(', s.startswith,
+ x, None, None, None)
+ self.assertRaisesRegexp(TypeError, r'^endswith\(', s.endswith,
+ x, None, None, None)
+
class MixinStrUnicodeTest:
# Additional tests that only work with str and unicode.
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py
index 8b964ca..a607bef 100644
--- a/Lib/test/test_bytes.py
+++ b/Lib/test/test_bytes.py
@@ -459,6 +459,68 @@ class BaseBytesTest(unittest.TestCase):
self.assertRaises(ValueError, self.type2test.maketrans, b'abc', b'xyzq')
self.assertRaises(TypeError, self.type2test.maketrans, 'abc', 'def')
+ def test_none_arguments(self):
+ # issue 11828
+ b = self.type2test(b'hello')
+ l = self.type2test(b'l')
+ h = self.type2test(b'h')
+ x = self.type2test(b'x')
+ o = self.type2test(b'o')
+
+ self.assertEqual(2, b.find(l, None))
+ self.assertEqual(3, b.find(l, -2, None))
+ self.assertEqual(2, b.find(l, None, -2))
+ self.assertEqual(0, b.find(h, None, None))
+
+ self.assertEqual(3, b.rfind(l, None))
+ self.assertEqual(3, b.rfind(l, -2, None))
+ self.assertEqual(2, b.rfind(l, None, -2))
+ self.assertEqual(0, b.rfind(h, None, None))
+
+ self.assertEqual(2, b.index(l, None))
+ self.assertEqual(3, b.index(l, -2, None))
+ self.assertEqual(2, b.index(l, None, -2))
+ self.assertEqual(0, b.index(h, None, None))
+
+ self.assertEqual(3, b.rindex(l, None))
+ self.assertEqual(3, b.rindex(l, -2, None))
+ self.assertEqual(2, b.rindex(l, None, -2))
+ self.assertEqual(0, b.rindex(h, None, None))
+
+ self.assertEqual(2, b.count(l, None))
+ self.assertEqual(1, b.count(l, -2, None))
+ self.assertEqual(1, b.count(l, None, -2))
+ self.assertEqual(0, b.count(x, None, None))
+
+ self.assertEqual(True, b.endswith(o, None))
+ self.assertEqual(True, b.endswith(o, -2, None))
+ self.assertEqual(True, b.endswith(l, None, -2))
+ self.assertEqual(False, b.endswith(x, None, None))
+
+ self.assertEqual(True, b.startswith(h, None))
+ self.assertEqual(True, b.startswith(l, -2, None))
+ self.assertEqual(True, b.startswith(h, None, -2))
+ self.assertEqual(False, b.startswith(x, None, None))
+
+ def test_find_etc_raise_correct_error_messages(self):
+ # issue 11828
+ b = self.type2test(b'hello')
+ x = self.type2test(b'x')
+ self.assertRaisesRegexp(TypeError, r'\bfind\b', b.find,
+ x, None, None, None)
+ self.assertRaisesRegexp(TypeError, r'\brfind\b', b.rfind,
+ x, None, None, None)
+ self.assertRaisesRegexp(TypeError, r'\bindex\b', b.index,
+ x, None, None, None)
+ self.assertRaisesRegexp(TypeError, r'\brindex\b', b.rindex,
+ x, None, None, None)
+ self.assertRaisesRegexp(TypeError, r'\bcount\b', b.count,
+ x, None, None, None)
+ self.assertRaisesRegexp(TypeError, r'\bstartswith\b', b.startswith,
+ x, None, None, None)
+ self.assertRaisesRegexp(TypeError, r'\bendswith\b', b.endswith,
+ x, None, None, None)
+
class BytesTest(BaseBytesTest):
type2test = bytes
diff --git a/Misc/ACKS b/Misc/ACKS
index f5fa82f..6a4fdd5 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -58,6 +58,7 @@ Donald Beaudry
David Beazley
Robin Becker
Neal Becker
+Torsten Becker
Bill Bedford
Stefan Behnel
Reimer Behrends
diff --git a/Misc/NEWS b/Misc/NEWS
index 8063d02..663846f 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -38,6 +38,9 @@ Core and Builtins
- Issue #8278: On Windows and with a NTFS filesystem, os.stat() and os.utime()
can now handle dates after 2038.
+- issue #11828: startswith and endswith don't accept None as slice index.
+ Patch by Torsten Becker.
+
- Issue #4236: PyModule_Create2 now checks the import machinery directly
rather than the Py_IsInitialized flag, avoiding a Fatal Python
error in certain circumstances when an import is done in __del__.
@@ -62,6 +65,9 @@ Library
- Issue #11467: Fix urlparse behavior when handling urls which contains scheme
specific part only digits. Patch by Santoso Wijaya.
+- Issue #11875: collections.OrderedDict's __reduce__ was temporarily
+ mutating the object instead of just working on a copy.
+
- collections.Counter().copy() now works correctly for subclasses.
- Issue #11474: Fix the bug with url2pathname() handling of '/C|/' on Windows.
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
index 8aa770d..6fc229d 100644
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -1082,8 +1082,8 @@ bytearray_find_internal(PyByteArrayObject *self, PyObject *args, int dir)
Py_ssize_t start=0, end=PY_SSIZE_T_MAX;
Py_ssize_t res;
- if (!PyArg_ParseTuple(args, "O|O&O&:find/rfind/index/rindex", &subobj,
- _PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
+ if (!stringlib_parse_args_finds("find/rfind/index/rindex",
+ args, &subobj, &start, &end))
return -2;
if (_getbuffer(subobj, &subbuf) < 0)
return -2;
@@ -1133,8 +1133,7 @@ bytearray_count(PyByteArrayObject *self, PyObject *args)
Py_buffer vsub;
PyObject *count_obj;
- if (!PyArg_ParseTuple(args, "O|O&O&:count", &sub_obj,
- _PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
+ if (!stringlib_parse_args_finds("count", args, &sub_obj, &start, &end))
return NULL;
if (_getbuffer(sub_obj, &vsub) < 0)
@@ -1292,8 +1291,7 @@ bytearray_startswith(PyByteArrayObject *self, PyObject *args)
PyObject *subobj;
int result;
- if (!PyArg_ParseTuple(args, "O|O&O&:startswith", &subobj,
- _PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
+ if (!stringlib_parse_args_finds("startswith", args, &subobj, &start, &end))
return NULL;
if (PyTuple_Check(subobj)) {
Py_ssize_t i;
@@ -1332,8 +1330,7 @@ bytearray_endswith(PyByteArrayObject *self, PyObject *args)
PyObject *subobj;
int result;
- if (!PyArg_ParseTuple(args, "O|O&O&:endswith", &subobj,
- _PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
+ if (!stringlib_parse_args_finds("endswith", args, &subobj, &start, &end))
return NULL;
if (PyTuple_Check(subobj)) {
Py_ssize_t i;
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
index 334e356..616f390 100644
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -1567,19 +1567,9 @@ bytes_find_internal(PyBytesObject *self, PyObject *args, int dir)
const char *sub;
Py_ssize_t sub_len;
Py_ssize_t start=0, end=PY_SSIZE_T_MAX;
- PyObject *obj_start=Py_None, *obj_end=Py_None;
- if (!PyArg_ParseTuple(args, "O|OO:find/rfind/index/rindex", &subobj,
- &obj_start, &obj_end))
- return -2;
- /* To support None in "start" and "end" arguments, meaning
- the same as if they were not passed.
- */
- if (obj_start != Py_None)
- if (!_PyEval_SliceIndex(obj_start, &start))
- return -2;
- if (obj_end != Py_None)
- if (!_PyEval_SliceIndex(obj_end, &end))
+ if (!stringlib_parse_args_finds("find/rfind/index/rindex",
+ args, &subobj, &start, &end))
return -2;
if (PyBytes_Check(subobj)) {
@@ -1826,8 +1816,7 @@ bytes_count(PyBytesObject *self, PyObject *args)
Py_ssize_t sub_len;
Py_ssize_t start = 0, end = PY_SSIZE_T_MAX;
- if (!PyArg_ParseTuple(args, "O|O&O&:count", &sub_obj,
- _PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
+ if (!stringlib_parse_args_finds("count", args, &sub_obj, &start, &end))
return NULL;
if (PyBytes_Check(sub_obj)) {
@@ -2648,8 +2637,7 @@ bytes_startswith(PyBytesObject *self, PyObject *args)
PyObject *subobj;
int result;
- if (!PyArg_ParseTuple(args, "O|O&O&:startswith", &subobj,
- _PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
+ if (!stringlib_parse_args_finds("startswith", args, &subobj, &start, &end))
return NULL;
if (PyTuple_Check(subobj)) {
Py_ssize_t i;
@@ -2689,8 +2677,7 @@ bytes_endswith(PyBytesObject *self, PyObject *args)
PyObject *subobj;
int result;
- if (!PyArg_ParseTuple(args, "O|O&O&:endswith", &subobj,
- _PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
+ if (!stringlib_parse_args_finds("endswith", args, &subobj, &start, &end))
return NULL;
if (PyTuple_Check(subobj)) {
Py_ssize_t i;
diff --git a/Objects/complexobject.c b/Objects/complexobject.c
index 300398e..4948a21 100644
--- a/Objects/complexobject.c
+++ b/Objects/complexobject.c
@@ -8,10 +8,6 @@
#include "Python.h"
#include "structmember.h"
-#ifdef HAVE_IEEEFP_H
-#include <ieeefp.h>
-#endif
-
#ifndef WITHOUT_COMPLEX
/* elementary operations on complex numbers */
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 6a2af74..8161ed5 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -15,10 +15,6 @@
#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) < (y) ? (x) : (y))
-#ifdef HAVE_IEEEFP_H
-#include <ieeefp.h>
-#endif
-
#ifdef _OSF_SOURCE
/* OSF1 5.1 doesn't make this available with XOPEN_SOURCE_EXTENDED defined */
diff --git a/Objects/stringlib/find.h b/Objects/stringlib/find.h
index bf06530..4407d71 100644
--- a/Objects/stringlib/find.h
+++ b/Objects/stringlib/find.h
@@ -102,32 +102,33 @@ stringlib_contains_obj(PyObject* str, PyObject* sub)
#endif /* STRINGLIB_STR */
-#ifdef FROM_UNICODE
-
/*
This function is a helper for the "find" family (find, rfind, index,
-rindex) of unicodeobject.c file, because they all have the same
-behaviour for the arguments.
+rindex) and for count, startswith and endswith, because they all have
+the same behaviour for the arguments.
It does not touch the variables received until it knows everything
is ok.
-
-Note that we receive a pointer to the pointer of the substring object,
-so when we create that object in this function we don't DECREF it,
-because it continues living in the caller functions (those functions,
-after finishing using the substring, must DECREF it).
*/
+#define FORMAT_BUFFER_SIZE 50
+
Py_LOCAL_INLINE(int)
-_ParseTupleFinds (PyObject *args, PyObject **substring,
- Py_ssize_t *start, Py_ssize_t *end) {
- PyObject *tmp_substring;
+stringlib_parse_args_finds(const char * function_name, PyObject *args,
+ PyObject **subobj,
+ Py_ssize_t *start, Py_ssize_t *end)
+{
+ PyObject *tmp_subobj;
Py_ssize_t tmp_start = 0;
Py_ssize_t tmp_end = PY_SSIZE_T_MAX;
PyObject *obj_start=Py_None, *obj_end=Py_None;
+ char format[FORMAT_BUFFER_SIZE] = "O|OO:";
+ size_t len = strlen(format);
- if (!PyArg_ParseTuple(args, "O|OO:find", &tmp_substring,
- &obj_start, &obj_end))
+ strncpy(format + len, function_name, FORMAT_BUFFER_SIZE - len - 1);
+ format[FORMAT_BUFFER_SIZE - 1] = '\0';
+
+ if (!PyArg_ParseTuple(args, format, &tmp_subobj, &obj_start, &obj_end))
return 0;
/* To support None in "start" and "end" arguments, meaning
@@ -140,16 +141,44 @@ _ParseTupleFinds (PyObject *args, PyObject **substring,
if (!_PyEval_SliceIndex(obj_end, &tmp_end))
return 0;
- tmp_substring = PyUnicode_FromObject(tmp_substring);
- if (!tmp_substring)
- return 0;
-
*start = tmp_start;
*end = tmp_end;
- *substring = tmp_substring;
+ *subobj = tmp_subobj;
return 1;
}
+#undef FORMAT_BUFFER_SIZE
+
+#ifdef FROM_UNICODE
+
+/*
+Wraps stringlib_parse_args_finds() and additionally ensures that the
+first argument is a unicode object.
+
+Note that we receive a pointer to the pointer of the substring object,
+so when we create that object in this function we don't DECREF it,
+because it continues living in the caller functions (those functions,
+after finishing using the substring, must DECREF it).
+*/
+
+Py_LOCAL_INLINE(int)
+stringlib_parse_args_finds_unicode(const char * function_name, PyObject *args,
+ PyUnicodeObject **substring,
+ Py_ssize_t *start, Py_ssize_t *end)
+{
+ PyObject *tmp_substring;
+
+ if(stringlib_parse_args_finds(function_name, args, &tmp_substring,
+ start, end)) {
+ tmp_substring = PyUnicode_FromObject(tmp_substring);
+ if (!tmp_substring)
+ return 0;
+ *substring = (PyUnicodeObject *)tmp_substring;
+ return 1;
+ }
+ return 0;
+}
+
#endif /* FROM_UNICODE */
#endif /* STRINGLIB_FIND_H */
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 6bffaea..877640d 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -7150,13 +7150,8 @@ unicode_count(PyUnicodeObject *self, PyObject *args)
Py_ssize_t end = PY_SSIZE_T_MAX;
PyObject *result;
- if (!PyArg_ParseTuple(args, "O|O&O&:count", &substring,
- _PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
- return NULL;
-
- substring = (PyUnicodeObject *)PyUnicode_FromObject(
- (PyObject *)substring);
- if (substring == NULL)
+ if (!stringlib_parse_args_finds_unicode("count", args, &substring,
+ &start, &end))
return NULL;
FIX_START_END(self);
@@ -7306,12 +7301,13 @@ Return -1 on failure.");
static PyObject *
unicode_find(PyUnicodeObject *self, PyObject *args)
{
- PyObject *substring;
+ PyUnicodeObject *substring;
Py_ssize_t start;
Py_ssize_t end;
Py_ssize_t result;
- if (!_ParseTupleFinds(args, &substring, &start, &end))
+ if (!stringlib_parse_args_finds_unicode("find", args, &substring,
+ &start, &end))
return NULL;
result = stringlib_find_slice(
@@ -7368,11 +7364,12 @@ static PyObject *
unicode_index(PyUnicodeObject *self, PyObject *args)
{
Py_ssize_t result;
- PyObject *substring;
+ PyUnicodeObject *substring;
Py_ssize_t start;
Py_ssize_t end;
- if (!_ParseTupleFinds(args, &substring, &start, &end))
+ if (!stringlib_parse_args_finds_unicode("index", args, &substring,
+ &start, &end))
return NULL;
result = stringlib_find_slice(
@@ -8230,12 +8227,13 @@ Return -1 on failure.");
static PyObject *
unicode_rfind(PyUnicodeObject *self, PyObject *args)
{
- PyObject *substring;
+ PyUnicodeObject *substring;
Py_ssize_t start;
Py_ssize_t end;
Py_ssize_t result;
- if (!_ParseTupleFinds(args, &substring, &start, &end))
+ if (!stringlib_parse_args_finds_unicode("rfind", args, &substring,
+ &start, &end))
return NULL;
result = stringlib_rfind_slice(
@@ -8257,12 +8255,13 @@ Like S.rfind() but raise ValueError when the substring is not found.");
static PyObject *
unicode_rindex(PyUnicodeObject *self, PyObject *args)
{
- PyObject *substring;
+ PyUnicodeObject *substring;
Py_ssize_t start;
Py_ssize_t end;
Py_ssize_t result;
- if (!_ParseTupleFinds(args, &substring, &start, &end))
+ if (!stringlib_parse_args_finds_unicode("rindex", args, &substring,
+ &start, &end))
return NULL;
result = stringlib_rfind_slice(
@@ -8725,8 +8724,7 @@ unicode_startswith(PyUnicodeObject *self,
Py_ssize_t end = PY_SSIZE_T_MAX;
int result;
- if (!PyArg_ParseTuple(args, "O|O&O&:startswith", &subobj,
- _PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
+ if (!stringlib_parse_args_finds("startswith", args, &subobj, &start, &end))
return NULL;
if (PyTuple_Check(subobj)) {
Py_ssize_t i;
@@ -8771,8 +8769,7 @@ unicode_endswith(PyUnicodeObject *self,
Py_ssize_t end = PY_SSIZE_T_MAX;
int result;
- if (!PyArg_ParseTuple(args, "O|O&O&:endswith", &subobj,
- _PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
+ if (!stringlib_parse_args_finds("endswith", args, &subobj, &start, &end))
return NULL;
if (PyTuple_Check(subobj)) {
Py_ssize_t i;
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index f85cc55..c688172 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -1065,8 +1065,6 @@ settrace() -- set the global debug tracing function\n\
/* end of sys_doc */ ;
/* Subversion branch and revision management */
-static const char _patchlevel_revision[] = PY_PATCHLEVEL_REVISION;
-static const char headurl[] = "$HeadURL$";
static int svn_initialized;
static char patchlevel_revision[50]; /* Just the number */
static char branch[50];
@@ -1076,64 +1074,14 @@ static const char *svn_revision;
static void
svnversion_init(void)
{
- const char *python, *br_start, *br_end, *br_end2, *svnversion;
- Py_ssize_t len;
- int istag = 0;
-
if (svn_initialized)
return;
- python = strstr(headurl, "/python/");
- if (!python) {
- strcpy(branch, "unknown branch");
- strcpy(shortbranch, "unknown");
- }
- else {
- br_start = python + 8;
- br_end = strchr(br_start, '/');
- assert(br_end);
-
- /* Works even for trunk,
- as we are in trunk/Python/sysmodule.c */
- br_end2 = strchr(br_end+1, '/');
-
- istag = strncmp(br_start, "tags", 4) == 0;
- if (strncmp(br_start, "trunk", 5) == 0) {
- strcpy(branch, "trunk");
- strcpy(shortbranch, "trunk");
- }
- else if (istag || strncmp(br_start, "branches", 8) == 0) {
- len = br_end2 - br_start;
- strncpy(branch, br_start, len);
- branch[len] = '\0';
-
- len = br_end2 - (br_end + 1);
- strncpy(shortbranch, br_end + 1, len);
- shortbranch[len] = '\0';
- }
- else {
- Py_FatalError("bad HeadURL");
- return;
- }
- }
-
-
- svnversion = _Py_svnversion();
- if (strcmp(svnversion, "Unversioned directory") != 0 && strcmp(svnversion, "exported") != 0)
- svn_revision = svnversion;
- else if (istag) {
- len = strlen(_patchlevel_revision);
- assert(len >= 13);
- assert(len < (sizeof(patchlevel_revision) + 13));
- strncpy(patchlevel_revision, _patchlevel_revision + 11,
- len - 13);
- patchlevel_revision[len - 13] = '\0';
- svn_revision = patchlevel_revision;
- }
- else
- svn_revision = "";
-
svn_initialized = 1;
+ *patchlevel_revision = '\0';
+ strcpy(branch, "");
+ strcpy(shortbranch, "unknown");
+ svn_revision = "";
}
/* Return svnversion output if available.