Commits

David Bennett committed 5f67946

Add replacement addinfourl class compatible with python-2.7's xmlrpclib.

  • Participants
  • Parent commits 762d497

Comments (0)

Files changed (1)

File yolk/pypi.py

 import time
 import logging
 import urllib2
+import httplib
 
 from yolk.utils import get_yolk_dir
 
 #XML_RPC_SERVER = 'http://cheeseshop.python.org/simple'
 
 
+class addinfourl(urllib2.addinfourl):
+    """
+    Replacement addinfourl class compatible with python-2.7's xmlrpclib
+
+    In python-2.7, xmlrpclib expects that the response object that it receives
+    has a getheader method. httplib.HTTPResponse provides this but
+    urllib2.addinfourl does not. Add the necessary functions here, ported to
+    use the internal data structures of addinfourl.
+    """
+    def getheader(self, name, default=None):
+        if self.headers is None:
+            raise httplib.ResponseNotReady()
+        return self.headers.getheader(name, default)
+
+    def getheaders(self):
+        if self.headers is None:
+            raise httplib.ResponseNotReady()
+        return self.headers.items()
+urllib2.addinfourl = addinfourl
+
+
 class ProxyTransport(xmlrpclib.Transport):
     """
     Provides an XMl-RPC transport routing via a http proxy.