mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Make test_base64 pass.
Change binascii.Error to derive from ValueError and raise binascii.Error everywhere where values are bad (why on earth did the old code use TypeError?!?).
This commit is contained in:
parent
0e225aa09b
commit
4581ae5fa2
5 changed files with 268 additions and 232 deletions
|
@ -3519,11 +3519,20 @@ long_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
|||
return PyLong_FromLong(0L);
|
||||
if (base == -909)
|
||||
return PyNumber_Long(x);
|
||||
else if (PyString_Check(x)) {
|
||||
else if (PyString_Check(x) || PyBytes_Check(x)) {
|
||||
/* Since PyLong_FromString doesn't have a length parameter,
|
||||
* check here for possible NULs in the string. */
|
||||
char *string = PyString_AS_STRING(x);
|
||||
if (strlen(string) != PyString_Size(x)) {
|
||||
char *string;
|
||||
int size;
|
||||
if (PyBytes_Check(x)) {
|
||||
string = PyBytes_AS_STRING(x);
|
||||
size = PyBytes_GET_SIZE(x);
|
||||
}
|
||||
else {
|
||||
string = PyString_AS_STRING(x);
|
||||
size = PyString_GET_SIZE(x);
|
||||
}
|
||||
if (strlen(string) != size) {
|
||||
/* create a repr() of the input string,
|
||||
* just like PyLong_FromString does. */
|
||||
PyObject *srepr;
|
||||
|
@ -3536,7 +3545,7 @@ long_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
|||
Py_DECREF(srepr);
|
||||
return NULL;
|
||||
}
|
||||
return PyLong_FromString(PyString_AS_STRING(x), NULL, base);
|
||||
return PyLong_FromString(string, NULL, base);
|
||||
}
|
||||
else if (PyUnicode_Check(x))
|
||||
return PyLong_FromUnicode(PyUnicode_AS_UNICODE(x),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue