authomatic/core.py
def deserialize(cls, config, credentials):
        """
        A *class method* which reconstructs credentials created by
        :meth:`serialize`. You can also pass it a :class:`.Credentials`
        instance.

        :param dict config:
            The same :doc:`config` used in the :func:`.login` to get the
            credentials.
        :param str credentials:
            :class:`string` The serialized credentials or
            :class:`.Credentials` instance.

        :returns:
            :class:`.Credentials`

        """

        # Accept both serialized and normal.
        if isinstance(credentials, Credentials):
            return credentials

        decoded = parse.unquote(credentials)

        split = decoded.split('\n')

        # We need the provider ID to move forward.
        if split[0] is None:
            raise CredentialsError(
                'To deserialize credentials you need to specify a unique '
                'integer under the "id" key in the config for each provider!')

        # Get provider config by short name.
        provider_name = id_to_name(config, int(split[0]))
        cfg = config.get(provider_name)

        # Get the provider class.
        ProviderClass = resolve_provider_class(cfg.get('class_'))

        deserialized = Credentials(config)

        deserialized.provider_id = provider_id
        deserialized.provider_type = ProviderClass.get_type()
        deserialized.provider_type_id = split[1]
        deserialized.provider_class = ProviderClass
        deserialized.provider_name = provider_name
        deserialized.provider_class = ProviderClass

        # Add provider type specific properties.
        return ProviderClass.reconstruct(split[2:], deserialized, cfg)
def deserialize(cls, config, credentials):
        """
        A *class method* which reconstructs credentials created by
        :meth:`serialize`. You can also pass it a :class:`.Credentials`
        instance.

        :param dict config:
            The same :doc:`config` used in the :func:`.login` to get the
            credentials.
        :param str credentials:
            :class:`string` The serialized credentials or
            :class:`.Credentials` instance.

        :returns:
            :class:`.Credentials`

        """

        # Accept both serialized and normal.
        if isinstance(credentials, Credentials):
            return credentials

        decoded = parse.unquote(credentials)

        split = decoded.split('\n')

        # We need the provider ID to move forward.
        if split[0] is None:
            raise CredentialsError(
                'To deserialize credentials you need to specify a unique '
                'integer under the "id" key in the config for each provider!')

        # Get provider config by short name.
        provider_name = id_to_name(config, int(split[0]))
        cfg = config.get(provider_name)

        # Get the provider class.
        ProviderClass = resolve_provider_class(cfg.get('class_'))

        deserialized = Credentials(config)

        deserialized.provider_id = provider_id
        deserialized.provider_type = ProviderClass.get_type()
        deserialized.provider_type_id = split[1]
        deserialized.provider_class = ProviderClass
        deserialized.provider_name = provider_name
        deserialized.provider_class = ProviderClass

        # Add provider type specific properties.
        return ProviderClass.reconstruct(split[2:], deserialized, cfg)
A *class method* which reconstructs credentials created by
        :meth:`serialize`. You can also pass it a :class:`.Credentials`
        instance.

        :param dict config:
            The same :doc:`config` used in the :func:`.login` to get the
            credentials.
        :param str credentials:
            :class:`string` The serialized credentials or
            :class:`.Credentials` instance.

        :returns:
            :class:`.Credentials`