def parse_response(self, response): headers = dict((k.upper(), v) for k, v in response.getheaders()) jsonwsp_response = JSONWSPResponse(response.status, response.reason, headers) jsonwsp_charset = probe_charset(jsonwsp_response.headers) content_type = response.getheader('content-type') content_type = content_type.replace('\n', '') multipart_match = rx_detect_multipart.findall(content_type) if len(multipart_match): multipart = multipart_match[0] boundary_match = rx_detect_boundary.findall(content_type) if len(boundary_match): boundary = boundary_match[0] mpr = MultiPartReader(20000, boundary.encode(jsonwsp_charset), response) mpr.read_chunk() while not mpr.eos: mpr.read_chunk() for cid, cinfo in mpr.attachments_by_id.items(): jsonwsp_response.attachments[PORTABLE_STRING( cid, jsonwsp_charset)] = attachment( open(cinfo['path'], 'rb'), cinfo['size'], cinfo['headers'], jsonwsp_charset) resdata = mpr.interface_request jsonwsp_response.response_body = resdata else: resdata = response.read() jsonwsp_response.response_body = resdata return jsonwsp_response
def download(self, name): """Download""" response = File() response.name = name filename = join(RES_PATH, response.name) response.data = attachment(open(filename, 'rb')) return response
def secure_download(self, token, name): """Download""" if not Authenticate().user.token == token: raise Unauthorized("Wrong token") response = File() response.name = name filename = join(RES_PATH, response.name) response.data = attachment(open(filename, 'rb')) return response
def check_attachment(self,val): global rx_detect_attachment_ref if type(val) == PORTABLE_STRING: m = rx_detect_attachment_ref.match(val) if m and m.groups()[0] in self.attachments: a = self.attachments[m.groups()[0]] attachment_copy = attachment(open(a.bufferobj.name,'rb'),a.size,a.headers,None) self.dict_attachments += [attachment_copy] return attachment_copy return None
def multi_download(self, names): """Download""" responses = [] for name in names: response = File() response.name = name filename = join(RES_PATH, response.name) response.data = attachment(open(filename, 'rb')) responses.append(response) return responses
def download_multi(self, name): """Download""" responses = [] for idx in xrange(3): response = File() response.name = "{}-{}.txt".format(name, idx + 1) filename = join(RES_PATH, response.name) response.data = attachment(open(filename, 'rb')) responses.append(response) return responses
def check_attachment(self, val): global rx_detect_attachment_ref if type(val) == PORTABLE_STRING: m = rx_detect_attachment_ref.match(val) if m and m.groups()[0] in self.attachments: a = self.attachments[m.groups()[0]] attachment_copy = attachment(open(a.bufferobj.name, 'rb'), a.size, a.headers, None) self.dict_attachments += [attachment_copy] return attachment_copy return None
def download(self,names): """ Download multiple files at once. For each name in the <b>names</b> the service attempts to find a file in service/upload that matches it. If a name does not have a matching file it is ignored. @param names: A list of the file names @rtype: Returns a list of File objects """ global upload_dir response = [] for name in names: f = File() f.name = name f.data = attachment(open(join(upload_dir,name),'rb')) response += [f] return response
def download(self, names): """ Download multiple files at once. For each name in the <b>names</b> the service attempts to find a file in service/upload that matches it. If a name does not have a matching file it is ignored. @param names: A list of the file names @rtype: Returns a list of File objects """ global upload_dir response = [] for name in names: f = File() f.name = name f.data = attachment(open(join(upload_dir, name), "rb")) response += [f] return response
def parse_response(self,response): headers = dict((k.upper(), v) for k, v in response.getheaders()) jsonwsp_response = JSONWSPResponse(response.status, response.reason, headers) jsonwsp_charset = probe_charset(jsonwsp_response.headers) content_type = response.getheader('content-type') content_type = content_type.replace('\n','') multipart_match = rx_detect_multipart.findall(content_type) if len(multipart_match): multipart = multipart_match[0] boundary_match = rx_detect_boundary.findall(content_type) if len(boundary_match): boundary = boundary_match[0] mpr = MultiPartReader(20000,boundary.encode(jsonwsp_charset),response) mpr.read_chunk() while not mpr.eos: mpr.read_chunk() for cid,cinfo in mpr.attachments_by_id.items(): jsonwsp_response.attachments[PORTABLE_STRING(cid,jsonwsp_charset)] = attachment(open(cinfo['path'],'rb'),cinfo['size'],cinfo['headers'],jsonwsp_charset) resdata = mpr.interface_request jsonwsp_response.response_body = resdata else: resdata = response.read() jsonwsp_response.response_body = resdata return jsonwsp_response