From 3cef33a5791b60ba91ff1177bb258ab0eb067b12 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Fri, 21 Mar 2014 11:24:40 -0400 Subject: Issue #20627: xmlrpc.client.ServerProxy is now a context manager. Patch by Claudiu Popa. --- Lib/xmlrpc/client.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'Lib/xmlrpc/client.py') diff --git a/Lib/xmlrpc/client.py b/Lib/xmlrpc/client.py index c2ae7070f9..567554da37 100644 --- a/Lib/xmlrpc/client.py +++ b/Lib/xmlrpc/client.py @@ -1449,6 +1449,12 @@ class ServerProxy: return self.__transport raise AttributeError("Attribute %r not found" % (attr,)) + def __enter__(self): + return self + + def __exit__(self, *args): + self.__close() + # compatibility Server = ServerProxy -- cgit v1.2.1 From 96367f7260ed4fe01c56bf36356fb983281d2dbd Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 22 Jul 2014 12:14:52 +0300 Subject: Issue #22031: Reprs now always use hexadecimal format with the "0x" prefix when contain an id in form " at 0x...". --- Lib/xmlrpc/client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Lib/xmlrpc/client.py') diff --git a/Lib/xmlrpc/client.py b/Lib/xmlrpc/client.py index 567554da37..d46f32c8df 100644 --- a/Lib/xmlrpc/client.py +++ b/Lib/xmlrpc/client.py @@ -354,7 +354,7 @@ class DateTime: return self.value def __repr__(self): - return "" % (self.value, id(self)) + return "" % (self.value, id(self)) def decode(self, data): self.value = str(data).strip() @@ -846,7 +846,7 @@ class MultiCall: self.__call_list = [] def __repr__(self): - return "" % id(self) + return "" % id(self) __str__ = __repr__ -- cgit v1.2.1 From bcd8dccf51c716a73884baa8eb3ad84065685a8b Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Fri, 25 Jul 2014 23:36:00 +0300 Subject: Issue #22033: Reprs of most Python implemened classes now contain actual class name instead of hardcoded one. --- Lib/xmlrpc/client.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'Lib/xmlrpc/client.py') diff --git a/Lib/xmlrpc/client.py b/Lib/xmlrpc/client.py index d46f32c8df..3a1435d611 100644 --- a/Lib/xmlrpc/client.py +++ b/Lib/xmlrpc/client.py @@ -207,8 +207,8 @@ class ProtocolError(Error): self.headers = headers def __repr__(self): return ( - "" % - (self.url, self.errcode, self.errmsg) + "<%s for %s: %s %s>" % + (self.__class__.__name__, self.url, self.errcode, self.errmsg) ) ## @@ -236,7 +236,8 @@ class Fault(Error): self.faultCode = faultCode self.faultString = faultString def __repr__(self): - return "" % (self.faultCode, self.faultString) + return "<%s %s: %r>" % (self.__class__.__name__, + self.faultCode, self.faultString) # -------------------------------------------------------------------- # Special values @@ -354,7 +355,7 @@ class DateTime: return self.value def __repr__(self): - return "" % (self.value, id(self)) + return "<%s %r at %#x>" % (self.__class__.__name__, self.value, id(self)) def decode(self, data): self.value = str(data).strip() @@ -846,7 +847,7 @@ class MultiCall: self.__call_list = [] def __repr__(self): - return "" % id(self) + return "<%s at %#x>" % (self.__class__.__name__, id(self)) __str__ = __repr__ @@ -1426,8 +1427,8 @@ class ServerProxy: def __repr__(self): return ( - "" % - (self.__host, self.__handler) + "<%s for %s%s>" % + (self.__class__.__name__, self.__host, self.__handler) ) __str__ = __repr__ -- cgit v1.2.1 From 1e73b7a71628034a0d6b33defbe5ace89713fe69 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 31 Jan 2015 12:05:05 +0200 Subject: Issue #23326: Removed __ne__ implementations. Since fixing default __ne__ implementation in issue #21408 they are redundant. --- Lib/xmlrpc/client.py | 9 --------- 1 file changed, 9 deletions(-) (limited to 'Lib/xmlrpc/client.py') diff --git a/Lib/xmlrpc/client.py b/Lib/xmlrpc/client.py index 9435015144..047929a861 100644 --- a/Lib/xmlrpc/client.py +++ b/Lib/xmlrpc/client.py @@ -340,10 +340,6 @@ class DateTime: s, o = self.make_comparable(other) return s == o - def __ne__(self, other): - s, o = self.make_comparable(other) - return s != o - def timetuple(self): return time.strptime(self.value, "%Y%m%dT%H:%M:%S") @@ -407,11 +403,6 @@ class Binary: other = other.data return self.data == other - def __ne__(self, other): - if isinstance(other, Binary): - other = other.data - return self.data != other - def decode(self, data): self.data = base64.decodebytes(data) -- cgit v1.2.1 From d6c289dad8f6c9979a3bec08cc003acab661bef2 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 4 Apr 2015 11:01:02 +0300 Subject: Issue #22831: Use "with" to avoid possible fd leaks. --- Lib/xmlrpc/client.py | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) (limited to 'Lib/xmlrpc/client.py') diff --git a/Lib/xmlrpc/client.py b/Lib/xmlrpc/client.py index 047929a861..34208d1c75 100644 --- a/Lib/xmlrpc/client.py +++ b/Lib/xmlrpc/client.py @@ -1010,12 +1010,9 @@ def gzip_encode(data): if not gzip: raise NotImplementedError f = BytesIO() - gzf = gzip.GzipFile(mode="wb", fileobj=f, compresslevel=1) - gzf.write(data) - gzf.close() - encoded = f.getvalue() - f.close() - return encoded + with gzip.GzipFile(mode="wb", fileobj=f, compresslevel=1) as gzf: + gzf.write(data) + return f.getvalue() ## # Decode a string using the gzip content encoding such as specified by the @@ -1036,17 +1033,14 @@ def gzip_decode(data, max_decode=20971520): """ if not gzip: raise NotImplementedError - f = BytesIO(data) - gzf = gzip.GzipFile(mode="rb", fileobj=f) - try: - if max_decode < 0: # no limit - decoded = gzf.read() - else: - decoded = gzf.read(max_decode + 1) - except OSError: - raise ValueError("invalid data") - f.close() - gzf.close() + with gzip.GzipFile(mode="rb", fileobj=BytesIO(data)) as gzf: + try: + if max_decode < 0: # no limit + decoded = gzf.read() + else: + decoded = gzf.read(max_decode + 1) + except OSError: + raise ValueError("invalid data") if max_decode >= 0 and len(decoded) > max_decode: raise ValueError("max gzipped payload length exceeded") return decoded -- cgit v1.2.1 From 424cef7b4e30453d221dba5c5282e0cf7e40e60c Mon Sep 17 00:00:00 2001 From: R David Murray Date: Sun, 5 Apr 2015 19:26:29 -0400 Subject: #3566: Clean up handling of remote server disconnects. This changeset does two things: introduces a new RemoteDisconnected exception (that subclasses ConnectionResetError and BadStatusLine) so that a remote server disconnection can be detected by client code (and provides a better error message for debugging purposes), and ensures that the client socket is closed if a ConnectionError happens, so that the automatic re-connection code can work if the application handles the error and continues on. Tests are added that confirm that a connection is re-used or not re-used as appropriate to the various combinations of protocol version and headers. Patch by Martin Panter, reviewed by Demian Brecht. (Tweaked only slightly by me.) --- Lib/xmlrpc/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Lib/xmlrpc/client.py') diff --git a/Lib/xmlrpc/client.py b/Lib/xmlrpc/client.py index 34208d1c75..da089a2f03 100644 --- a/Lib/xmlrpc/client.py +++ b/Lib/xmlrpc/client.py @@ -1128,7 +1128,7 @@ class Transport: if i or e.errno not in (errno.ECONNRESET, errno.ECONNABORTED, errno.EPIPE): raise - except http.client.BadStatusLine: #close after we sent request + except http.client.RemoteDisconnected: if i: raise -- cgit v1.2.1