Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_resource(url, asset_name, flags):
resp = SESSION.get(url)
resp.raise_for_status()
buf = resp.content
if flags & 1:
bio = io.BytesIO()
bio.write(buf[4:8])
bio.write(buf[16:])
buf = lz4.loads(bio.getvalue())
return buf
for selector in mp:
if selector.platform == platform and \
selector.asset_qual == asset_qual and \
selector.sound_qual == sound_qual:
get_file = selector.filename
break
abso = "/".join(( DBMANIFEST.format(version), get_file ))
resp = SESSION.get(abso)
resp.raise_for_status()
buf = resp.content
bio = io.BytesIO()
bio.write(buf[4:8])
bio.write(buf[16:])
data = lz4.loads(bio.getvalue())
with open(dest_file, "wb") as write_db:
write_db.write(data)
return dest_file
def readLZ4(self, data, shape, dtype, size):
"""
Unpack lz4 compressed frame and return np array image data
"""
import numpy as np
import lz4, bitshuffle
dtype = np.dtype(dtype)
data = lz4.loads(data)
return np.reshape(np.fromstring(data, dtype=dtype), shape[::-1])
def __init__(self, raw_message, *args, **kwargs):
compression = kwargs.pop('compression', False)
raw_message = lz4.loads(raw_message) if compression else raw_message
message = msgpack.unpackb(raw_message)
try:
self.datas = message['datas']
except KeyError:
errors_logger.exception("Invalid response message : %s" %
message)
raise MessageFormatError("Invalid response message")
for i in (1,3,4): header.update(json.loads(frames[i].bytes))
if header.get("bss_job_mode", 4) != bss_job_mode:
return None, None
dtype = header["type"]
shape = header["shape"][::-1]
if dtype in ("int32","uint32"): byte = 4
elif dtype in ("int16","uint16"): byte = 2
else: raise RuntimeError("Unknown dtype (%s)"%dtype)
size = byte*shape[0]*shape[1]
if header["encoding"] == "lz4<":
data = lz4.loads(struct.pack('u4", buffer=data[8:12])/4
data = bitshuffle.decompress_lz4(blob, shape, numpy.dtype(dtype), blocksize)
data = data.reshape(shape)
elif header["encoding"] == "bs16-lz4<":
data = frames[2].bytes
blob = numpy.fromstring(data[12:],dtype=numpy.uint8)
data = bitshuffle.decompress_lz4(blob, shape, numpy.dtype(dtype))
data = data.reshape(shape)
else:
RuntimeError("Unknown encoding (%s)"%header["encoding"])