summaryrefslogtreecommitdiffstats
path: root/Objects/bytesobject.c
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2008-08-26 16:46:47 (GMT)
committerBenjamin Peterson <benjamin@python.org>2008-08-26 16:46:47 (GMT)
commitc15a07333e712e682036d9ecb7230d25ccb1a85f (patch)
tree52eee04b10bc95047d25c9dd6b82ec9e48efeb97 /Objects/bytesobject.c
parenta786b026c9992cee195b7a550bab2c70c50f874f (diff)
downloadcpython-c15a07333e712e682036d9ecb7230d25ccb1a85f.zip
cpython-c15a07333e712e682036d9ecb7230d25ccb1a85f.tar.gz
cpython-c15a07333e712e682036d9ecb7230d25ccb1a85f.tar.bz2
make bytes(o) respect __bytes__ #2415
This adds two new C-API functions: PyObject_Bytes and PyBytes_FromObject. Reviewer: Barry
Diffstat (limited to 'Objects/bytesobject.c')
-rw-r--r--Objects/bytesobject.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
index d59e79a..3bda6d9 100644
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -2882,11 +2882,10 @@ str_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
static PyObject *
string_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
- PyObject *x = NULL, *it;
+ PyObject *x = NULL;
const char *encoding = NULL;
const char *errors = NULL;
PyObject *new = NULL;
- Py_ssize_t i, size;
static char *kwlist[] = {"source", "encoding", "errors", 0};
if (type != &PyBytes_Type)
@@ -2924,6 +2923,14 @@ string_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
"encoding or errors without a string argument");
return NULL;
}
+ return PyObject_Bytes(x);
+}
+
+PyObject *
+PyBytes_FromObject(PyObject *x)
+{
+ PyObject *new, *it;
+ Py_ssize_t i, size;
/* Is it an int? */
size = PyNumber_AsSsize_t(x, PyExc_ValueError);