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 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 upload(self, filepath): """ Upload the file with filepath (relative path) and retun the result """ # check if this file is for updating or creating new if self.has_master(filepath): url = self.get_update_link() request = urllib2.Request(url) else: url = self.get_create_link() url += self.CONFIGS.get("master_code") request = urllib2.Request(url) self.set_basicauth(request) # build form file = os.path.join(self.basepath, filepath) fhandle = open(file) form = MultiPartForm() form.addFile('file', filepath, fhandle) form.addField('name', filepath) request.add_header("Content-Type", form.getContentType()); request.add_data(str(form)) try: handle = urllib2.urlopen(request) data = handle.read() if data.startswith('Success'): return True, '' else: return False, data except urllib2.HTTPError, e: return False, 'Issue with remote server. Status code %s' % e.code