bokeh/bokeh · either.py
python logo
def from_json(self, json, models=None):
        for tp in self.type_params:
            try:
                return tp.from_json(json, models)
            except DeserializationError:
                pass
        else:
            raise DeserializationError("%s couldn't deserialize %s" % (self, json))
Similar code snippets
1.
bokeh/bokeh · instance.py
Match rating: 66.24% · See similar code snippets
python logo
def from_json(self, json, models=None):
        if json is None:
            return None
        elif isinstance(json, dict):
            from ...model import Model
            if issubclass(self.instance_type, Model):
                if models is None:
                    raise DeserializationError("%s can't deserialize without models" % self)
                else:
                    model = models.get(json["id"])

                    if model is not None:
                        return model
                    else:
                        raise DeserializationError("%s failed to deserialize reference to %s" % (self, json))
            else:
                attrs = {}

                for name, value in iteritems(json):
                    prop_descriptor = self.instance_type.lookup(name).property
                    attrs[name] = prop_descriptor.from_json(value, models)

                # XXX: this doesn't work when Instance(Superclass) := Subclass()
                # Serialization dict must carry type information to resolve this.
                return self.instance_type(**attrs)
        else:
            raise DeserializationError("%s expected a dict or None, got %s" % (self, json))
2.
anti1869/sunhead · json.py
Match rating: 60.4% · See similar code snippets
python logo
def deserialize(self, msg: Serialized) -> Transferrable:
        body_txt = msg.decode("utf-8") if hasattr(msg, "decode") else msg
        try:
            deserialized = json.loads(body_txt)
        except json.JSONDecodeError:
            logger.error("Error deserializing message body", exc_info=True)
            if not self.graceful:
                raise SerializationError

            deserialized = self._deserialized_default

        return deserialized
3.
palantir/conjure-python-client · decoder.py
Match rating: 57.09% · See similar code snippets
python logo
def read_from_string(self, string_value, obj_type):
        # type: (str, ConjureTypeType) -> Any
        deserialized = json.loads(string_value)
        return self.decode(deserialized, obj_type)
4.
pavlov99/json-rpc · jsonrpc2.py
Match rating: 56.96% · See similar code snippets
python logo
def from_json(cls, json_str):
        data = cls.deserialize(json_str)
        return cls.from_data(data)
5.
GoogleCloudPlatform/appengine-mapreduce · json_util.py
Match rating: 55.68% · See similar code snippets
python logo
def from_json_str(cls, json_str):
    """Convert json string representation into class instance.

    Args:
      json_str: json representation as string.

    Returns:
      New instance of the class with data loaded from json string.
    """
    return cls.from_json(json.loads(json_str, cls=JsonDecoder))
6.
kylef/refract.py · json.py
Match rating: 55.52% · See similar code snippets
python logo
def deserialise(self, element_json: str) -> Element:
        """
        Deserialises the given JSON into an element.

        >>> json = '{"element": "string", "content": "Hello"'
        >>> JSONDeserialiser().deserialise(json)
        String(content='Hello')
        """

        return self.deserialise_dict(json.loads(element_json))
7.
anomaly/prestans · request.py
Match rating: 54.79% · See similar code snippets
python logo
def register_deserializers(self, deserializers):

        if not isinstance(deserializers, list):
            deserializers = [deserializers]

        # todo: should this prevent duplicates for same mime-type?

        for new_deserializer in deserializers:

            if not isinstance(new_deserializer, deserializer.Base):
                msg = "registered deserializer %s does not inherit from prestans.serializer.DeSerializer" % (
                      new_deserializer.__class__.__name__
                )
                raise TypeError(msg)

        self._deserializers = self._deserializers + deserializers
8.
i3visio/osrframework · utils.py
Match rating: 54.69% · See similar code snippets
python logo
def from_json(cls, json_str):
        """Deserialize the object from a JSON string."""
        d = json.loads(json_str)
        return cls.from_dict(d)
9.
erikvw/django-collect-offline · transaction_deserializer.py
Match rating: 54.48% · See similar code snippets
python logo
def deserialize_transactions(self, transactions=None, deserialize_only=None):
        """Deserializes the encrypted serialized model
        instances, tx, in a queryset of transactions.

        Note: each transaction instance contains encrypted JSON text
        that represents just ONE model instance.
        """

        if (
            not self.allow_self
            and transactions.filter(producer=socket.gethostname()).exists()
        ):
            raise TransactionDeserializerError(
                f"Not deserializing own transactions. Got "
                f"allow_self=False, hostname={socket.gethostname()}"
            )
        for transaction in transactions:
            json_text = self.aes_decrypt(cipher_text=transaction.tx)
            json_text = self.custom_parser(json_text)
            deserialized = next(self.deserialize(json_text=json_text))
            if not deserialize_only:
                if transaction.action == DELETE:
                    deserialized.object.delete()
                else:
                    self.save(obj=deserialized.object, m2m_data=deserialized.m2m_data)
                transaction.is_consumed = True
                transaction.save()
10.
Azure/Azure-MachineLearning-ClientLibrary-Python · services.py
Match rating: 53.94% · See similar code snippets
python logo
def _decode_inner(value):
    val_type = value['type']
    deserializer = _deserializers.get(value['type'])
    if deserializer is None:
        raise ValueError("unsupported type: " + value['type'])
    
    return deserializer(value)