diff Objects/bytesobject.c @ 48871:548dccc4008e

make bytes(o) respect __bytes__ #2415 This adds two new C-API functions: PyObject_Bytes and PyBytes_FromObject. Reviewer: Barry
author Benjamin Peterson <benjamin@python.org>
date Tue, 26 Aug 2008 16:46:47 +0000
parents a2720353f0d3
children d9fe29e95d60
line wrap: on
line diff
--- a/Objects/bytesobject.c	Mon Aug 25 21:05:21 2008 +0000
+++ b/Objects/bytesobject.c	Tue Aug 26 16:46:47 2008 +0000
@@ -2882,11 +2882,10 @@
 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 @@
 			"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);