'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`'

@classmethod
def deserialize(cls, config, credentials):

    if isinstance(credentials, Credentials):
        return credentials
    decoded = parse.unquote(credentials)
    split = decoded.split('\n')
    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!')
    provider_name = id_to_name(config, int(split[0]))
    cfg = config.get(provider_name)
    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
    return ProviderClass.reconstruct(split[2:], deserialized, cfg)
