]> granicus.if.org Git - python/commitdiff
Simplify socket_repr() by using PyUnicode_FromFormat()
authorWalter Dörwald <walter@livinglogic.de>
Tue, 5 Jun 2007 13:41:53 +0000 (13:41 +0000)
committerWalter Dörwald <walter@livinglogic.de>
Tue, 5 Jun 2007 13:41:53 +0000 (13:41 +0000)
directly. Add a test that calls socket_repr().

Lib/test/test_socket.py
Modules/socketmodule.c

index cfb293fe19abf0907ee078af63aae0729485046c..8ba2cebeb7d8958ceae0bd65b667f1ec244a03a9 100644 (file)
@@ -217,6 +217,10 @@ class SocketPairTest(unittest.TestCase, ThreadableTest):
 
 class GeneralModuleTests(unittest.TestCase):
 
+    def test_repr(self):
+        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        self.assert_(repr(s).startswith("<socket.socket object"))
+
     def test_weakref(self):
         s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         p = proxy(s)
index eca29dd0709ae430b10c8392b4521548c96bd8d2..4ae745c31ef6d0be4b47a8f1791eb4f3aa5e920b 100644 (file)
@@ -2787,13 +2787,11 @@ sock_repr(PySocketSockObject *s)
                return NULL;
        }
 #endif
-       PyOS_snprintf(
-               buf, sizeof(buf),
+       return PyUnicode_FromFormat(
                "<socket object, fd=%ld, family=%d, type=%d, proto=%d>",
                (long)s->sock_fd, s->sock_family,
                s->sock_type,
                s->sock_proto);
-       return PyUnicode_FromString(buf);
 }