[Python-checkins] cpython: Fix User-Agent for the xmlrpc.client, and catch KeyboardInterrupt for the

florent.xicluna python-checkins at python.org
Sun Oct 30 20:40:03 CET 2011


http://hg.python.org/cpython/rev/197d703fb23e
changeset:   73219:197d703fb23e
parent:      73217:0aa52d845caa
user:        Florent Xicluna <florent.xicluna at gmail.com>
date:        Sun Oct 30 20:39:24 2011 +0100
summary:
  Fix User-Agent for the xmlrpc.client, and catch KeyboardInterrupt for the standalone xmlrpc.server.

files:
  Lib/xmlrpc/client.py |  7 ++++---
  Lib/xmlrpc/server.py |  9 +++++++--
  Misc/NEWS            |  3 +++
  3 files changed, 14 insertions(+), 5 deletions(-)


diff --git a/Lib/xmlrpc/client.py b/Lib/xmlrpc/client.py
--- a/Lib/xmlrpc/client.py
+++ b/Lib/xmlrpc/client.py
@@ -128,6 +128,7 @@
 """
 
 import base64
+import sys
 import time
 import http.client
 from xml.parsers import expat
@@ -152,7 +153,8 @@
     s = s.replace("<", "&lt;")
     return s.replace(">", "&gt;",)
 
-__version__ = "1.0.1"
+# used in User-Agent header sent
+__version__ = sys.version[:3]
 
 # xmlrpc integer limits
 MAXINT =  2**31-1
@@ -408,7 +410,6 @@
         out.write("<value><base64>\n")
         encoded = base64.encodebytes(self.data)
         out.write(encoded.decode('ascii'))
-        out.write('\n')
         out.write("</base64></value>\n")
 
 def _binary(data):
@@ -1079,7 +1080,7 @@
     """Handles an HTTP transaction to an XML-RPC server."""
 
     # client identifier (may be overridden)
-    user_agent = "xmlrpclib.py/%s (by www.pythonware.com)" % __version__
+    user_agent = "Python-xmlrpc/%s" % __version__
 
     #if true, we'll request gzip encoding
     accept_gzip_encoding = True
diff --git a/Lib/xmlrpc/server.py b/Lib/xmlrpc/server.py
--- a/Lib/xmlrpc/server.py
+++ b/Lib/xmlrpc/server.py
@@ -956,8 +956,13 @@
 
 
 if __name__ == '__main__':
-    print('Running XML-RPC server on port 8000')
     server = SimpleXMLRPCServer(("localhost", 8000))
     server.register_function(pow)
     server.register_function(lambda x,y: x+y, 'add')
-    server.serve_forever()
+    print('Serving XML-RPC on localhost port 8000')
+    try:
+        server.serve_forever()
+    except KeyboardInterrupt:
+        print("\nKeyboard interrupt received, exiting.")
+        server.server_close()
+        sys.exit(0)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -347,6 +347,9 @@
 Library
 -------
 
+- Fix the xmlrpc.client user agent to return something similar to
+  urllib.request user agent: "Python-xmlrpc/3.3".
+
 - Issue #13293: Better error message when trying to marshal bytes using
   xmlrpc.client.
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list