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_element(element):
binary = json.dumps(json.loads(jsonpickle.dumps(element)), sort_keys=True).encode()
return binary
def _send_message(connection, message):
# Packing the length of the entire msg using struct.pack.
# This enables later reading of the content.
def _pack(data):
return struct.pack(_INT_FMT, len(data))
data = jsonpickle.dumps(message)
msg_metadata = _pack(data)
connection.send(msg_metadata)
connection.sendall(data)
def _save_templates_file(full_path, templates):
with open(full_path, 'w') as new_json_file:
new_json_file.write(jsonpickle.dumps(templates))
def encode_callable(fn, args, kwargs):
checksum_src = hash_source(fn)
doc = dict(
fn=fn, args=args, kwargs=kwargs,
module=fn.__module__, checksum_src=checksum_src)
# we need jsonpickle to encode the functions and
# json to ensure key sorting
binary = json.dumps(json.loads(jsonpickle.dumps(doc)),
sort_keys=True).encode()
m = hashlib.sha1()
m.update(binary)
checksum = m.hexdigest()
return {KEY_CALLABLE: binary, KEY_CALLABLE_CHECKSUM: checksum}
def _machineoutput(obj: Dict[str, Any]):
click.echo(f'Uc&42BWAaQ{jsonpickle.dumps(obj, unpicklable=False, backend=_machine_pickler)}')
def save_session(self, editor_id, editor_session):
if not self.session_save_file_extension:
log.debug("no filename extension for session data; not saving")
else:
s = {}
self.serialize_session(s)
if s and editor_session:
s[editor_id] = editor_session
jsonpickle.set_encoder_options("json", sort_keys=True, indent=4)
text = jsonpickle.dumps(s)
text = jsonutil.collapse_json(text, 8, self.json_expand_keywords)
path = self.save_adjacent(self.session_save_file_extension, text)
log.debug("saved session to {path}")
return path