Python jsonpickle 模块,loads() 实例源码

我们从Python开源项目中,提取了以下21个代码示例,用于说明如何使用jsonpickle.loads()

项目:robograph    作者:csparpa    | 项目源码 | 文件源码
def deserialize(cls, json_string):
        """
        Builds a Graph from a JSON representation
        :param json_string: JSON str
        :return: datamodel.base.graph.Graph instance
        """
        try:
            graph_dict = json.loads(json_string)
            result = graph.Graph(name=graph_dict['name'])
            nodes = dict()
            for item in graph_dict['nodes']:
                nodes[item['id']] = NodeSerializer.from_dict(item['data'])
            result.add_nodes(nodes.values())
            for e in graph_dict['edges']:
                result.connect(nodes[e['id_node_from']],
                               nodes[e['id_node_to']],
                               e['output_label'])
            return result
        except Exception as e:
            raise
            #raise GraphDeserializationException(e.message)
项目:PJON-python    作者:Girgitt    | 项目源码 | 文件源码
def listen(self, rcv_timeout=0.01):

        message = True
        while message:
            try:
                message = self._pubsub.get_message(timeout=rcv_timeout)
            except ConnectionError:
                log.error("lost connection to Redis")
                time.sleep(1)
                break
            if message:
                log.debug("%s - receied pub message: %s" % (self._cli_id, message))
                if message['type'] == 'message':
                    try:
                        return jsonpickle.loads(message['data'])
                    except(ValueError, KeyError):
                        return message['data']
        return None
项目:xavier    作者:bepress    | 项目源码 | 文件源码
def process_event(self, event):
        name, args, kwargs = jsonpickle.loads(event)

        func = self.functions.get(name)
        if not func:
            logger.info("processing event - missing function name: %s", name)
            raise Exception("Missing function")

        try:
            func(*args, **kwargs)
        except Exception as e:
            return False

        return True
项目:robograph    作者:csparpa    | 项目源码 | 文件源码
def from_dict(cls, node_dict):
        """
        Creates a node from a dict representation
        :param node_dict: dict
        :return: datamodel.base.node.Node
        """
        # import classes, so we can instantiate them at need
        import robograph.datamodel

        # retrieve the class object so we can instantiate the node
        klass = eval(node_dict['class'])
        node = klass(name=node_dict['name'])

        # now retrieve the parameters
        parameters = dict()
        for p in node_dict['params']:
            parameters[p] = node_dict['params'][p]

            # are we deserializing a pickled function?
            if isinstance(node_dict['params'][p], unicode):
                if "py/bytes" in node_dict['params'][p]:
                    parameters[p] = cloudpickle.loads(jsonpickle.loads(node_dict['params'][p]))

        node.input(parameters)
        node.set_output_label(node_dict['output_label'])
        return node
项目:robograph    作者:csparpa    | 项目源码 | 文件源码
def deserialize(cls, json_string):
        """
        Builds a Node from a JSON representation
        :param json_string: JSON str
        :return: datamodel.base.node.Node instance
        """
        try:
            node_dict = json.loads(json_string)
            return NodeSerializer.from_dict(node_dict)
        except Exception as e:
            raise NodeDeserializationException(e.message)
项目:django-herald    作者:worthwhile    | 项目源码 | 文件源码
def get_extra_data(self):
        """
        Return extra data that was saved
        """

        if not self.extra_data:
            return {}
        else:
            return json.loads(self.extra_data)
项目:django-herald    作者:worthwhile    | 项目源码 | 文件源码
def get_attachments(self):
        if self.attachments:
            return jsonpickle.loads(self.attachments)
        else:
            return None
项目:keras-text    作者:raghakot    | 项目源码 | 文件源码
def load(file_name):
    if file_name.endswith('.json'):
        with open(file_name, 'r') as f:
            return jsonpickle.loads(f.read())

    if file_name.endswith('.npy'):
        return np.load(file_name)

    return joblib.load(file_name)
项目:InplusTrader_Linux    作者:zhengwsh    | 项目源码 | 文件源码
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))
项目:InplusTrader_Linux    作者:zhengwsh    | 项目源码 | 文件源码
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))
项目:InplusTrader_Linux    作者:zhengwsh    | 项目源码 | 文件源码
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))
项目:InplusTrader_Linux    作者:zhengwsh    | 项目源码 | 文件源码
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))
项目:InplusTrader_Linux    作者:zhengwsh    | 项目源码 | 文件源码
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))
项目:incubator-ariatosca    作者:apache    | 项目源码 | 文件源码
def wrap_if_needed(exception):
    try:
        jsonpickle.loads(jsonpickle.dumps(exception))
        return exception
    except BaseException:
        return _WrappedException(type(exception).__name__, str(exception))
项目:incubator-ariatosca    作者:apache    | 项目源码 | 文件源码
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)
项目:incubator-ariatosca    作者:apache    | 项目源码 | 文件源码
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)
项目:incubator-ariatosca    作者:apache    | 项目源码 | 文件源码
def test_wrapping_required1(self):
        e = NonJsonPickleableException(_ARG1, _ARG2)
        wrapped_e = exceptions.wrap_if_needed(e)
        wrapped_e = jsonpickle.loads(jsonpickle.dumps(wrapped_e))
        assert isinstance(wrapped_e, exceptions._WrappedException)
        assert wrapped_e.exception_type == type(e).__name__
        assert wrapped_e.exception_str == str(e)
项目:incubator-ariatosca    作者:apache    | 项目源码 | 文件源码
def test_wrapping_required2(self):
        e = NonJsonPickleableException(arg1=_ARG1, arg2=_ARG2)
        wrapped_e = exceptions.wrap_if_needed(e)
        wrapped_e = jsonpickle.loads(jsonpickle.dumps(wrapped_e))
        assert isinstance(wrapped_e, exceptions._WrappedException)
        assert wrapped_e.exception_type == type(e).__name__
        assert wrapped_e.exception_str == str(e)
项目:rqalpha    作者:ricequant    | 项目源码 | 文件源码
def set_state(self, state):
        self._open_orders = []
        self._delayed_orders = []

        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))
项目:rqalpha    作者:ricequant    | 项目源码 | 文件源码
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))
项目:puppet    作者:Raytone-D    | 项目源码 | 文件源码
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))