summaryrefslogtreecommitdiffstats
path: root/Objects/longobject.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-05-22 21:56:47 (GMT)
committerGuido van Rossum <guido@python.org>2007-05-22 21:56:47 (GMT)
commit4581ae5fa2450db3f00384e4b2e86654605100d4 (patch)
tree3029bdbbfd3495e4d832036cc17d7ab0bc2f1c02 /Objects/longobject.c
parent0e225aa09bb8059c333424d58beecd833b2d2b6c (diff)
downloadcpython-4581ae5fa2450db3f00384e4b2e86654605100d4.zip
cpython-4581ae5fa2450db3f00384e4b2e86654605100d4.tar.gz
cpython-4581ae5fa2450db3f00384e4b2e86654605100d4.tar.bz2
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?!?).
Diffstat (limited to 'Objects/longobject.c')
-rw-r--r--Objects/longobject.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c
index d325b8e..1f497c4 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -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),