aboutsummaryrefslogtreecommitdiffstats
path: root/netlib/tcp.py
diff options
context:
space:
mode:
Diffstat (limited to 'netlib/tcp.py')
-rw-r--r--netlib/tcp.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/netlib/tcp.py b/netlib/tcp.py
index f49346a1..ede8682b 100644
--- a/netlib/tcp.py
+++ b/netlib/tcp.py
@@ -216,10 +216,16 @@ class Address(object):
def use_ipv6(self, b):
self.family = socket.AF_INET6 if b else socket.AF_INET
+ def __repr__(self):
+ return repr(self.address)
+
def __eq__(self, other):
other = Address.wrap(other)
return (self.address, self.family) == (other.address, other.family)
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
class _Connection(object):
def get_current_cipher(self):
@@ -313,6 +319,8 @@ class TCPClient(_Connection):
if self.source_address:
connection.bind(self.source_address())
connection.connect(self.address())
+ if not self.source_address:
+ self.source_address = Address(connection.getsockname())
self.rfile = Reader(connection.makefile('rb', self.rbufsize))
self.wfile = Writer(connection.makefile('wb', self.wbufsize))
except (socket.error, IOError), err:
@@ -486,10 +494,10 @@ class TCPServer(object):
# none.
if traceback:
exc = traceback.format_exc()
- print >> fp, '-'*40
- print >> fp, "Error in processing of request from %s:%s" % (client_address.host, client_address.port)
- print >> fp, exc
- print >> fp, '-'*40
+ print('-' * 40, file=fp)
+ print("Error in processing of request from %s:%s" % (client_address.host, client_address.port), file=fp)
+ print(exc, file=fp)
+ print('-' * 40, file=fp)
def handle_client_connection(self, conn, client_address): # pragma: no cover
"""