@staticmethod
    def from_string(data_string):
        """Deserializes a token from a string like one returned by

        `to_string()`."""

        if not len(data_string):
            raise ValueError("Invalid parameter string.")

        params = parse_qs(data_string, keep_blank_values=False)
        if not len(params):
            raise ValueError("Invalid parameter string.")

        try:
            key = params['oauth_token'][0]
        except Exception:
            raise ValueError("'oauth_token' not found in OAuth request.")

        try:
            secret = params['oauth_token_secret'][0]
        except Exception:
            raise ValueError("'oauth_token_secret' not found in "
                "OAuth request.")

        token = YahooToken(key, secret)

        session_handle = params.get('oauth_session_handle')
        if session_handle:
            setattr(token, 'session_handle', session_handle[0])

        timestamp = params.get('token_creation_timestamp')
        if timestamp:
            setattr(token, 'timestamp', timestamp[0])

        try:
            token.callback_confirmed = params['oauth_callback_confirmed'][0]
        except __HOLE__:
            pass  # 1.0, no callback confirmed.

        return token
dataset/ETHPy150Open project-fondue/python-yql/yql/__init__.py/YahooToken.from_string