"""Return human-readable description of the filter."""
return str(self.d)
-class BasicHTTPAuthTransport(xmlrpclib.Transport):
+class BasicHTTPAuthTransport(xmlrpclib.SafeTransport):
- def __init__(self, username = None, password = None):
+ def __init__(self, username = None, password = None, use_https = False):
self.username = username
self.password = password
- xmlrpclib.Transport.__init__(self)
+ self.use_https = use_https
+ xmlrpclib.SafeTransport.__init__(self)
def authenticated(self):
return self.username != None and self.password != None
auth = 'Basic ' + base64.encodestring(credentials).strip()
connection.putheader('Authorization', auth)
+ def make_connection(self, host):
+ if self.use_https:
+ fn = xmlrpclib.SafeTransport.make_connection
+ else:
+ fn = xmlrpclib.Transport.make_connection
+ return fn(self, host)
+
def usage():
sys.stderr.write("Usage: %s <action> [options]\n\n" % \
(os.path.basename(sys.argv[0])))
if submitter_str != "":
ids = person_ids_by_name(rpc, submitter_str)
if len(ids) == 0:
- sys.stderr.write("Note: Nobody found matching *%s*\n", \
+ sys.stderr.write("Note: Nobody found matching *%s*\n" % \
submitter_str)
else:
for id in ids:
person = rpc.person_get(id)
print "Patches submitted by %s <%s>:" % \
- (person['name'], person['email'])
+ (unicode(person['name']).encode("utf-8"), \
+ unicode(person['email']).encode("utf-8"))
f = filter
f.add("submitter_id", id)
patches = rpc.patch_list(f.d)
if delegate_str != "":
ids = person_ids_by_name(rpc, delegate_str)
if len(ids) == 0:
- sys.stderr.write("Note: Nobody found matching *%s*\n", \
+ sys.stderr.write("Note: Nobody found matching *%s*\n" % \
delegate_str)
else:
for id in ids:
sys.exit(1)
try:
- f.write(s)
+ f.write(unicode(s).encode("utf-8"))
f.close()
print "Saved patch to %s" % fname
except:
sys.stderr.write("Patch not updated\n")
def patch_id_from_hash(rpc, project, hash):
- patch = rpc.patch_get_by_project_hash(project, hash)
+ try:
+ patch = rpc.patch_get_by_project_hash(project, hash)
+ except xmlrpclib.Fault:
+ # the server may not have the newer patch_get_by_project_hash function,
+ # so fall back to hash-only.
+ patch = rpc.patch_get_by_hash(hash)
+
if patch == {}:
return None
if config.has_option('auth', 'username') and \
config.has_option('auth', 'password'):
+ use_https = url.startswith('https')
+
transport = BasicHTTPAuthTransport( \
config.get('auth', 'username'),
- config.get('auth', 'password'))
+ config.get('auth', 'password'),
+ use_https)
else:
sys.stderr.write(("The %s action requires authentication, "