mirror of https://github.com/python/cpython
Simplify socket_repr() by using PyUnicode_FromFormat()
directly. Add a test that calls socket_repr().
This commit is contained in:
parent
787b03ba4b
commit
a7eb93ec43
|
@ -217,6 +217,10 @@ class SocketPairTest(unittest.TestCase, ThreadableTest):
|
||||||
|
|
||||||
class GeneralModuleTests(unittest.TestCase):
|
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):
|
def test_weakref(self):
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
p = proxy(s)
|
p = proxy(s)
|
||||||
|
|
|
@ -2787,13 +2787,11 @@ sock_repr(PySocketSockObject *s)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
PyOS_snprintf(
|
return PyUnicode_FromFormat(
|
||||||
buf, sizeof(buf),
|
|
||||||
"<socket object, fd=%ld, family=%d, type=%d, proto=%d>",
|
"<socket object, fd=%ld, family=%d, type=%d, proto=%d>",
|
||||||
(long)s->sock_fd, s->sock_family,
|
(long)s->sock_fd, s->sock_family,
|
||||||
s->sock_type,
|
s->sock_type,
|
||||||
s->sock_proto);
|
s->sock_proto);
|
||||||
return PyUnicode_FromString(buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue