本文整理匯總了Python中jsonpickle.loads方法的典型用法代碼示例。如果您正苦於以下問題:Python jsonpickle.loads方法的具體用法?Python jsonpickle.loads怎麽用?Python jsonpickle.loads使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類jsonpickle
的用法示例。
在下文中一共展示了jsonpickle.loads方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: load_area
# 需要導入模塊: import jsonpickle [as 別名]
# 或者: from jsonpickle import loads [as 別名]
def load_area(self):
""" Load the dock area into the workspace content.
"""
area = None
plugin = self.workbench.get_plugin("declaracad.ui")
try:
#with open('inkcut.workspace.db', 'r') as f:
# area = pickle.loads(f.read())
pass #: TODO:
except Exception as e:
print(e)
if area is None:
print("Creating new area")
area = plugin.create_new_area()
else:
print("Loading existing doc area")
area.set_parent(self.content)
示例2: main
# 需要導入模塊: import jsonpickle [as 別名]
# 或者: from jsonpickle import loads [as 別名]
def main(**kwargs):
""" Runs ModelExporter.export() using the passed options.
Parameters
----------
options: Dict
A jsonpickle dumped exporter
"""
options = kwargs.pop('options')
exporter = jsonpickle.loads(options)
assert exporter, "Failed to load exporter from: {}".format(options)
# An Application is required
app = QtApplication()
t0 = time.time()
print("Exporting {e.filename} to {e.path}...".format(e=exporter))
sys.stdout.flush()
exporter.export()
print("Success! Took {} seconds.".format(round(time.time()-t0, 2)))
示例3: _bind_observers
# 需要導入模塊: import jsonpickle [as 別名]
# 或者: from jsonpickle import loads [as 別名]
def _bind_observers(self):
""" Try to load the plugin state """
try:
if os.path.exists(self._state_file):
with enaml.imports():
with open(self._state_file, 'r') as f:
state = pickle.loads(f.read())
self.__setstate__(state)
log.warning("Plugin {} state restored from: {}".format(
self.manifest.id, self._state_file))
except Exception as e:
log.warning("Plugin {} failed to load state: {}".format(
self.manifest.id, traceback.format_exc()))
#: Hook up observers
for member in self._state_members:
self.observe(member.name, self._save_state)
示例4: get_extra_data
# 需要導入模塊: import jsonpickle [as 別名]
# 或者: from jsonpickle import loads [as 別名]
def get_extra_data(self):
"""
Return extra data that was saved
"""
if not self.extra_data:
return {}
else:
return json.loads(self.extra_data)
示例5: get_attachments
# 需要導入模塊: import jsonpickle [as 別名]
# 或者: from jsonpickle import loads [as 別名]
def get_attachments(self):
if self.attachments:
return jsonpickle.loads(self.attachments)
else:
return None
示例6: test_get_encoded_attachments_file
# 需要導入模塊: import jsonpickle [as 別名]
# 或者: from jsonpickle import loads [as 別名]
def test_get_encoded_attachments_file(self):
class TestNotification(EmailNotification):
attachments = [File(open('tests/python.jpeg', 'rb'))]
attachments = jsonpickle.loads(TestNotification()._get_encoded_attachments())
self.assertEqual(attachments[0][0], 'tests/python.jpeg')
self.assertEqual(attachments[0][2], 'image/jpeg')
示例7: read_dialogue_file
# 需要導入模塊: import jsonpickle [as 別名]
# 或者: from jsonpickle import loads [as 別名]
def read_dialogue_file(filename):
with io.open(filename, "r") as f:
dialogue_json = f.read()
return jsonpickle.loads(dialogue_json)
示例8: deserialize_instance
# 需要導入模塊: import jsonpickle [as 別名]
# 或者: from jsonpickle import loads [as 別名]
def deserialize_instance(self, string: str) -> Instance:
"""
Deserializes an `Instance` from a string. We use this when reading processed data from a
cache.
The default implementation is to use `jsonpickle`. If you would like some other format
for your pre-processed data, override this method.
"""
return jsonpickle.loads(string.strip()) # type: ignore
示例9: read_dialogue_file
# 需要導入模塊: import jsonpickle [as 別名]
# 或者: from jsonpickle import loads [as 別名]
def read_dialogue_file(filename: Text):
return jsonpickle.loads(utils.read_file(filename))
示例10: set_state
# 需要導入模塊: import jsonpickle [as 別名]
# 或者: from jsonpickle import loads [as 別名]
def set_state(self, state):
delayed_orders = jsonpickle.loads(state.decode('utf-8'))
for account in self._accounts.values():
for o in account.daily_orders.values():
if not o._is_final():
if o.order_id in delayed_orders:
self._delayed_orders.append((account, o))
else:
self._open_orders.append((account, o))
示例11: set_state
# 需要導入模塊: import jsonpickle [as 別名]
# 或者: from jsonpickle import loads [as 別名]
def set_state(self, state):
state = jsonpickle.loads(state.decode('utf-8'))
for key, value in six.iteritems(state):
try:
self._objects[key].set_state(value)
except KeyError:
system_log.warn('core object state for {} ignored'.format(key))
示例12: set_state
# 需要導入模塊: import jsonpickle [as 別名]
# 或者: from jsonpickle import loads [as 別名]
def set_state(self, state):
value = jsonpickle.loads(state.decode('utf-8'))
for v in value['open_orders']:
o = Order()
o.set_state(v)
account = self._env.get_account(o.order_book_id)
self._open_orders.append((account, o))
for v in value['delayed_orders']:
o = Order()
o.set_state(v)
account = self._env.get_account(o.order_book_id)
self._delayed_orders.append((account, o))
示例13: _recv_message
# 需要導入模塊: import jsonpickle [as 別名]
# 或者: from jsonpickle import loads [as 別名]
def _recv_message(connection):
# Retrieving the length of the msg to come.
def _unpack(conn):
return struct.unpack(_INT_FMT, _recv_bytes(conn, _INT_SIZE))[0]
msg_metadata_len = _unpack(connection)
msg = _recv_bytes(connection, msg_metadata_len)
return jsonpickle.loads(msg)
示例14: _main
# 需要導入模塊: import jsonpickle [as 別名]
# 或者: from jsonpickle import loads [as 別名]
def _main():
arguments_json_path = sys.argv[1]
with open(arguments_json_path) as f:
arguments = pickle.loads(f.read())
# arguments_json_path is a temporary file created by the parent process.
# so we remove it here
os.remove(arguments_json_path)
task_id = arguments['task_id']
port = arguments['port']
messenger = _Messenger(task_id=task_id, port=port)
function = arguments['function']
operation_arguments = arguments['operation_arguments']
context_dict = arguments['context']
strict_loading = arguments['strict_loading']
try:
ctx = context_dict['context_cls'].instantiate_from_dict(**context_dict['context'])
except BaseException as e:
messenger.failed(e)
return
try:
messenger.started()
task_func = imports.load_attribute(function)
aria.install_aria_extensions(strict_loading)
for decorate in process_executor.decorate():
task_func = decorate(task_func)
task_func(ctx=ctx, **operation_arguments)
ctx.close()
messenger.succeeded()
except BaseException as e:
ctx.close()
messenger.failed(e)
示例15: wrap_if_needed
# 需要導入模塊: import jsonpickle [as 別名]
# 或者: from jsonpickle import loads [as 別名]
def wrap_if_needed(exception):
try:
jsonpickle.loads(jsonpickle.dumps(exception))
return exception
except BaseException:
return _WrappedException(type(exception).__name__, str(exception))