diff options
author | Walter Dörwald <walter@livinglogic.de> | 2007-06-05 13:41:53 (GMT) |
---|---|---|
committer | Walter Dörwald <walter@livinglogic.de> | 2007-06-05 13:41:53 (GMT) |
commit | a7eb93ec43e0ad18a0c78c93afb85e9cb9fd3f2f (patch) | |
tree | e5fbd31007c92804408643c48ee3b16d247d6462 | |
parent | 787b03ba4b023663074a76b473b143d0a2998c3b (diff) | |
download | cpython-a7eb93ec43e0ad18a0c78c93afb85e9cb9fd3f2f.zip cpython-a7eb93ec43e0ad18a0c78c93afb85e9cb9fd3f2f.tar.gz cpython-a7eb93ec43e0ad18a0c78c93afb85e9cb9fd3f2f.tar.bz2 |
Simplify socket_repr() by using PyUnicode_FromFormat()
directly. Add a test that calls socket_repr().
-rw-r--r-- | Lib/test/test_socket.py | 4 | ||||
-rw-r--r-- | Modules/socketmodule.c | 4 |
2 files changed, 5 insertions, 3 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index cfb293f..8ba2ceb 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -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) diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index eca29dd..4ae745c 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -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); } |