def _system_gunzip(archive_file): _, ext = os.path.splitext(archive_file) decompressed_file = os.path.basename(archive_file.strip(ext)) working_dir = os.getcwd() destination_abspath = os.path.join(working_dir, decompressed_file) compressed_file = os.path.basename(archive_file) copy_path = os.path.join(working_dir, compressed_file) shutil.copy(archive_file, copy_path) gzip = which("gzip") gzip.add_default_arg("-d") gzip(copy_path) return destination_abspath
def _get_image_blob(roidb, scale_inds): """Builds an input blob from the images in the roidb at the specified scales. """ num_images = len(roidb) processed_ims = [] im_scales = [] for i in xrange(num_images): im = None if cfg.TRAIN.FORMAT == "pickle": with gzip(roidb[i][image], 'rb') as f: im = cPickle.load(f) else: im = cv2.imread(roidb[i]['image']) # print roidb[i]['image'] if roidb[i]['flipped']: im = im[:, ::-1, :] target_size = cfg.TRAIN.SCALES[scale_inds[i]] im, im_scale = prep_im_for_blob(im, cfg.PIXEL_MEANS, target_size, cfg.TRAIN.MAX_SIZE) im_scales.append(im_scale) processed_ims.append(im) # Create a blob to hold the input images blob = im_list_to_blob(processed_ims) return blob, im_scales
def as_json(): make_logs() response = Response() response.headers[b"Content-Type"] = b"application/json; charset: utf-8" response = gzip(json.dumps(frappe.local.response, default=json_handler, separators=(',', ':')), response=response) return response
def as_json(): make_logs() response = Response() if frappe.local.response.http_status_code: response.status_code = frappe.local.response['http_status_code'] del frappe.local.response['http_status_code'] response.headers[b"Content-Type"] = b"application/json; charset: utf-8" response = gzip(json.dumps(frappe.local.response, default=json_handler, separators=(',',':')), response=response) return response
def save(self, fname, iszip=True): d = {} for k, v in self.__dict__.items(): if hasattr(v, '__dict__'): d[k] = v.__dict__ else: d[k] = v if not iszip: marshal.dump(d, open(fname, 'wb')) else: f = gzip(fname, 'wb') f.write(marshal.dumps(d)) f.close()
def fasta_to_fastq(fp_fa, fp_fq, zipped, dummy_char = "I"): """ Function to convert fasta (at `fp_fa`) to fastq (at `fp_fq`) possibly zipped, adding a `dummy_score`. """ if len(dummy_char) != 1: raise Exception("FASTQ dummy quality char must be only one char.") fq = open(fp_fq, 'w') seq = -1 if zipped: f = gzip(fp_fa) else: f = open(fp_fa) for line in f.readlines(): if line[0] == '>': if seq == -1: fq.write('@'+line[1:]) else: fq.write(seq+'\n') fq.write('+\n') fq.write(dummy_char*len(seq)+'\n') fq.write('@'+line[1:]) seq = '' else: seq += line.strip() f.close() if len(seq) > 0: fq.write(seq+'\n') fq.write('+\n') fq.write(dummy_char*len(seq)+'\n') fq.close()
def get(self): if 'If-None-Match' in self.request.headers: status = 304 headers = { 'Date': 'Tue, 20 Mar 2012 20:07:51 GMT', 'Server': 'Google Frontend' } else: body = gzip('hello gzipped?') status = 200 headers = { 'Cache-Control' : 'public, must-revalidate', #'Content-Encoding' : 'gzip', #'Content-Length' : '%d' % len(body), #'Content-Type' : 'text/html; charset=utf-8', #'Date' : 'Tue, 20 Mar 2012 20:06:24 GMT', 'ETag' : 'w/"0-124427221-0-"', #'Server' : 'Google Frontend', #'Vary' : 'Accept-Encoding', } #for key in self.response.headers: # del self.response.headers[key] for key in headers.keys(): self.response.headers[key] = headers[key] self.response.set_status(status) if status == 200: self.response.out.write(body)
from StringIO import StringIO import gzip import urllib2 request = urllib2.Request('https://www.downtownla.com/explore/dining-nightlife/happy-hour-finder/bunker-hill-bar-grill') request.add_header('Accept-encoding', 'gzip') response = urllib2.urlopen(request) if response.info().get('Content-Encoding') == 'gzip': buf = StringIO( response.read()) f = gzip(fileobj=buf) data = f.read()
if not datafile: #raise Exception("Canceled. No file selected") exit() print("Data source: " + datafile.decode()) if datafile.endswith(b"json"): data = json.load(open(datafile)) elif datafile.endswith(b"iqapack"): try: import msgpack data = msgpack.load(open(datafile, "rb"), encoding="utf-8") except ImportError as e: raise ImportError(e) elif datafile.endswith(b"json.gz"): try: import gzip data = json.load(gzip(open(datafile))) except ImportError as e: raise ImportError(e) #data = msgpack.load( open( datafile, "rb" ) ) #datafile = input("Enter the name of the JSON file containing IQA_Molecule (inside quotes) data: \n") #try: # datafile = "Fe2CO8_anion2.adf.json" # FIXME: hardcoded for easing development # data = json.load( open( datafile ) ) #except: # print("Wrong! Example: 'ch4.adf.json'") # datafile = input("Enter the name of the JSON file containing IQA_Molecule (inside quotes) data: \n") # data = json.load( open( datafile ) ) #molec = type('IQA_Molecule', (object,), data["molecule_or_group"])