Commits

Ronny Pfannschmidt committed 952b419 Merge

Merged in pablo/lodgeit-main (pull request #5) - netrc reading

Comments (0)

Files changed (1)

scripts/lodgeit.py

     return unicode(text, d['encoding'], 'ignore').encode('utf-8')
 
 
+def get_authenticated_url(url):
+    import netrc, urlparse
+    s = list(urlparse.urlsplit(url))
+    auth = netrc.netrc().authenticators(s[1])
+    if not auth:
+        return url
+    s[1] = '%s:%s@%s' % (auth[0], auth[2], s[1])
+    return urlparse.urlunsplit(s)
+
+
 def get_xmlrpc_service():
     """Create the XMLRPC server proxy and cache it."""
     global _xmlrpc_service
     import xmlrpclib
     if _xmlrpc_service is None:
         try:
-            _xmlrpc_service = xmlrpclib.ServerProxy(_server_name + 'xmlrpc/',
+            authurl = get_authenticated_url(_server_name)
+            _xmlrpc_service = xmlrpclib.ServerProxy(authurl + 'xmlrpc/',
                                                     allow_none=True)
         except Exception, err:
             fail('Could not connect to Pastebin: %s' % err, -1)