Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def encode(array):
buff = cv2.imencode(".png", array)[1]
return pybase64.b64encode(buff).decode("utf-8")
def benchmark(args):
print(__package__ + ' ' + pybase64.get_version())
data = readall(args.input)
for altchars in [None, b'-_']:
for validate in [False, True]:
print('bench: altchars={0:s}, validate={1:s}'.format(
repr(altchars), repr(validate)))
bench_one(args.duration,
data,
pybase64.b64encode,
pybase64.b64decode,
pybase64.encodebytes,
altchars,
validate)
bench_one(args.duration,
data,
base64.b64encode,
b64decodeValidate,
b64encodebytes,
altchars,
validate)
def encode(args):
data = readall(args.input)
data = pybase64.b64encode(data, args.altchars)
writeall(args.output, data)
def encode(array):
buff = cv2.imencode(".png", array)[1]
return pybase64.b64encode(buff).decode("utf-8")
# Encode matrix if required
if encoding == 'b64':
for i, matrix in enumerate(matrices):
id = loci_ids[mat_idx[i]]
data_types[i] = 'dataUrl'
if not no_cache and id:
mat_b64 = None
try:
mat_b64 = rdb.get('im_b64_%s' % id)
if mat_b64 is not None:
matrices[i] = mat_b64.decode('ascii')
continue
except:
pass
mat_b64 = pybase64.b64encode(np_to_png(matrix)).decode('ascii')
if not no_cache:
try:
rdb.set('im_b64_%s' % id, mat_b64, 60 * 30)
except Exception as ex:
# error caching a tile
# log the error and carry forward, this isn't critical
logger.warn(ex)
matrices[i] = mat_b64
if max_previews > 0:
for i, preview in enumerate(previews):
previews[i] = pybase64.b64encode(
np_to_png(preview)
).decode('ascii')
mat_b64 = pybase64.b64encode(np_to_png(matrix)).decode('ascii')
if not no_cache:
try:
rdb.set('im_b64_%s' % id, mat_b64, 60 * 30)
except Exception as ex:
# error caching a tile
# log the error and carry forward, this isn't critical
logger.warn(ex)
matrices[i] = mat_b64
if max_previews > 0:
for i, preview in enumerate(previews):
previews[i] = pybase64.b64encode(
np_to_png(preview)
).decode('ascii')
for i, preview_2d in enumerate(previews_2d):
previews_2d[i] = pybase64.b64encode(
np_to_png(preview_2d)
).decode('ascii')
# Create results
results = {
'fragments': matrices,
'indices': [int(i) for i in mat_idx],
'dataTypes': data_types,
}
# Return Y aggregates as 1D previews on demand
if max_previews > 0: