def postFile(self, file_, pathname, url): """ generated source for method postFile """ if self.forcedSSL and not url.startswith("https"): raise QuerySecurityException("SSL is required with basic auth") request = urllib2.Request(url) self.set_basicauth(request) # build form fhandle = open(file_) form = MultiPartForm() form.addFile('file', pathname, fhandle) form.addField('name', pathname) request.add_header("Content-Type", form.getContentType()) request.add_data(str(form)) try: handle = urllib2.urlopen(request) data = handle.read() if handle.getcode() != 200: raise QueryException(data, handle.getcode()) return handle.getcode() except urllib2.HTTPError, e: raise QueryException(e.read(), e.code)
def removeFile(self, url): """ This is not part of the Java API at the moment so this is not generated. """ if self.forcedSSL and not url.startswith("https"): raise QuerySecurityException("SSL is required with basic auth") request = RequestWithMethod('DELETE', url) self.set_basicauth(request) try: handle = urllib2.urlopen(request) if handle.getcode() != 200: raise QueryException(data, handle.getcode()) except urllib2.HTTPError, e: raise QueryException(e.read(), e.code)
def getFile(self, url): """ generated source for method getFile """ if self.forcedSSL and not url.startswith("https"): raise QuerySecurityException("SSL is required with basic auth") request = urllib2.Request(url) self.set_basicauth(request) try: handle = urllib2.urlopen(request) data = handle.read() if handle.getcode() != 200: raise QueryException(data, handle.getcode()) return data except urllib2.HTTPError, e: raise QueryException(e.read(), e.code)
def doQuery(self): """ generated source for method doQuery """ try: url = SERVER + self.projectId + "/api/list-master/json" json = self.getFile(url) data = simplejson.loads(json) if data.get('success') != '1': raise QueryException("Invalid response:" + data, 0) self.masterFiles = data.get('master_files') except QuerySecurityException as cse: # Making sure that URL starts with https. #cse.printStackTrace() raise cse
class Query(object): """ generated source for class Query """ def __init__(self): """ generated source for method __init__ """ self.forcedSSL = False def setBasicAuth(self, username, password): """ generated source for method setBasicAuth """ self.forcedSSL = FORCE_SSL self.username = username self.password = password def postFile(self, file_, pathname, url): """ generated source for method postFile """ if self.forcedSSL and not url.startswith("https"): raise QuerySecurityException("SSL is required with basic auth") request = urllib2.Request(url) self.set_basicauth(request) # build form fhandle = open(file_) form = MultiPartForm() form.addFile('file', pathname, fhandle) form.addField('name', pathname) request.add_header("Content-Type", form.getContentType()); request.add_data(str(form)) try: handle = urllib2.urlopen(request) data = handle.read() if handle.getcode() not in (200, 201): raise QueryException(data, handle.getcode()) return handle.getcode() except urllib2.HTTPError, e: raise QueryException(e.read(), e.code) except Exception, e: raise QueryException(str(e), 0)