Parse token and secret from raw token response.
491255
def parse_raw_token(self, raw_token):
        """"""
        if raw_token is None:
            return (None, None, None)
        qs = parse_qs(raw_token)
        token = qs.get('oauth_token', [None])[0]
        token_secret = qs.get('oauth_token_secret', [None])[0]
        return (token, token_secret, None)
1226522
def user_parse(data):
        """"""
        _user = data.get('oauth', {}).get('user', {})
        yield 'id', _user.get('id')
        yield 'username', _user.get('username')
        first_name, _, last_name = _user.get('display_name').partition(' ')
        yield 'first_name', first_name
        yield 'last_name', last_name
607315
def parse_ACCT(chunk, encryption_key):
    
    # TODO: Make a test case that covers secure note account

    io = BytesIO(chunk.payload)
    id = read_item(io)
    name = decode_aes256_plain_auto(read_item(io), encryption_key)
    group = decode_aes256_plain_auto(read_item(io), encryption_key)
    url = decode_hex(read_item(io))
    notes = decode_aes256_plain_auto(read_item(io), encryption_key)
    skip_item(io, 2)
    username = decode_aes256_plain_auto(read_item(io), encryption_key)
    password = decode_aes256_plain_auto(read_item(io), encryption_key)
    skip_item(io, 2)
    secure_note = read_item(io)

    # Parse secure note
    if secure_note == b'1':
        parsed = parse_secure_note_server(notes)

        if parsed.get('type') in ALLOWED_SECURE_NOTE_TYPES:
            url = parsed.get('url', url)
            username = parsed.get('username', username)
            password = parsed.get('password', password)

    return Account(id, name, username, password, url, group, notes)
500588
def parse_digest_response(digest_response_string):
    '''
    
    '''

    parts = parse_parts(digest_response_string, defaults={'algorithm': 'MD5'})
    if not _check_required_parts(parts, _REQUIRED_DIGEST_RESPONSE_PARTS):
        return None

    if not parts['nc'] or [c for c in parts['nc'] if not c in '0123456789abcdefABCDEF']:
        return None
    parts['nc'] = int(parts['nc'], 16)

    digest_response = _build_object_from_parts(parts, _REQUIRED_DIGEST_RESPONSE_PARTS)
    if ('MD5', 'auth') != (digest_response.algorithm, digest_response.qop):
        return None

    return digest_response
1358536
private function parseToken()
    {
        // Provided as a token param.
        $this->token = trim($this->request->get('token'));
        if (!$this->token) {
            // Provided as a token header.
            $this->token = trim($this->request->headers->get('token'));
            if (!$this->token) {
                // Provided as a X-Auth-Token header.
                $this->token = trim($this->request->headers->get('X-Auth-Token'));
                if (!$this->token) {
                    // Provided as a password header.
                    $this->token = trim($this->request->headers->get('password'));
                    if (!$this->token) {
                        // Various ways a token may come in via authorization headers.
                        $auth = $this->request->headers->get('authorization');
                        if ($auth) {
                            if (false !== strpos($auth, 'Bearer ')) {
                                // Provided as a bearer token.
                                $this->token = trim(str_ireplace('Bearer ', '', $auth));
                            } elseif (false !== strpos($auth, 'Basic ')) {
                                // Provided as a password.
                                $userPass = base64_decode(trim(str_ireplace('Basic ', '', $auth)));
                                if (strpos($userPass, ':') > 0) {
                                    $userPassParts = explode(':', $userPass);
                                    if (!empty($userPassParts[1])) {
                                        $this->token = $userPassParts[1];
                                    }
                                }
                            }
                        }
                        // Re-use the last token provided for this user for this source.
                        if (!$this->token && $this->sourceId) {
                            $tokens = $this->session->get('mautic.contactSource.tokens');
                            if ($tokens && !empty($tokens[$this->sourceId])) {
                                $this->token           = $tokens[$this->sourceId];
                                $this->errors['token'] = 'Token was supplied earlier in your session, but missing in this request. Please provide your authentication "token" parameter with every request.';
                            }
                        }
                    }
                }
            }
        }
        if (!$this->token) {
            throw new ContactSourceException(
                'The token was not supplied for this request or session. Please provide your authentication "token" parameter with every request.',
                Codes::HTTP_UNAUTHORIZED,
                null,
                Stat::TYPE_INVALID,
                'token'
            );
        }
    }
231713
def get_dict(parser, token):
    
    bits = token.contents.split(' ')
    return GetDict(bits[1], bits[2], ((len(bits) > 3) and bits[3]) or '', ((len(bits) > 4) and bits[4]) or '', ((len(bits) > 5) and bits[5]) or '')
471177
def from_text(textring):
    """"""

    keyring = {}
    for keytext in textring:
        keyname = dns.name.from_text(keytext)
        secret = base64.decodestring(textring[keytext])
        keyring[keyname] = secret
    return keyring
68774
def get_validated_token(self, raw_token):
        
        messages = []
        for AuthToken in api_settings.AUTH_TOKEN_CLASSES:
            try:
                return AuthToken(raw_token)
            except TokenError as e:
                messages.append({'token_class': AuthToken.__name__,
                                 'token_type': AuthToken.token_type,
                                 'message': e.args[0]})

        raise InvalidToken({
            'detail': _('Given token not valid for any token type'),
            'messages': messages,
        })
706236
def decode_token(self, token):
        """"""
        key = current_app.secret_key
        if key is None:
            if current_app.debug:
                current_app.logger.debug("app.secret_key not set")
            return None
        try:
            return jwt.decode(
                token, key,
                algorithms=[self.config["algorithm"]],
                options={'require_exp': True}
            )
        except jwt.InvalidTokenError:
            return None
544857
def parse_message(self):
		""""""
		parser = parse_chain(self.parse_net32int,  # authid
							lambda *_: self.parse_net32int(),  # authlen
							lambda *_: self.parse_net32int(),  # opcode
							lambda *_: self.parse_net32int(),  # handle
							lambda *_: self.parse_net32int(),  # tid
							lambda *_: self.parse_net32int(),  # rid
							lambda *_: self.parse_bindict(),  # message
							lambda *_: self.parse_bindict(),  # object
							lambda *args: self.parse_fixedbuffer(args[1]))  # signature
		return parse_map(lambda args:  # skip authlen in args:
				OmapiMessage(*(args[0:1] + args[2:])), parser)
1324007
def parse_info(response):
    ""
    info = {}
    response = nativestr(response)

    def get_value(value):
        if ',' not in value or '=' not in value:
            try:
                if '.' in value:
                    return float(value)
                else:
                    return int(value)
            except ValueError:
                return value
        else:
            sub_dict = {}
            for item in value.split(','):
                k, v = item.rsplit('=', 1)
                sub_dict[k] = get_value(v)
            return sub_dict

    for line in response.splitlines():
        if line and not line.startswith('#'):
            if line.find(':') != -1:
                key, value = line.split(':', 1)
                info[key] = get_value(value)
            else:
                # if the line isn't splittable, append it to the "__raw__" key
                info.setdefault('__raw__', []).append(line)

    return info
940834
def parse(cls, backend, ik, spk, spk_signature, otpks):
        

        ik = backend.decodePublicKey(ik)[0]

        spk["key"] = backend.decodePublicKey(spk["key"])[0]

        otpks = list(map(lambda otpk: {
            "key" : backend.decodePublicKey(otpk["key"])[0],
            "id"  : otpk["id"]
        }, otpks))

        return cls(ik, spk, spk_signature, otpks)
21748
def parse(self):
        """"""
        node = self.program()
        if self.token.nature != Nature.EOF:
            self._error()

        return node
1328482
def auth(self):
        """"""
        self.send(nsq.auth(self.auth_secret))
        frame, data = self.read_response()

        if frame == nsq.FRAME_TYPE_ERROR:
            raise data

        try:
            response = json.loads(data.decode('utf-8'))
        except ValueError:
            self.close_stream()
            raise errors.NSQException(
                'failed to parse AUTH response JSON from nsqd: '
                '{!r}'.format(data))

        self.on_auth.send(self, response=response)
        return response
774765
def _decode_header(auth_header, client_id, client_secret):
    
    try:
        token = auth_header.split()[1]
        payload = jwt.decode(
            token,
            client_secret,
            audience=client_id)
    except jwt.ExpiredSignature:
        raise exceptions.NotAuthorizedException(
            'Token has expired, please log in again.')
    # is valid client
    except jwt.InvalidAudienceError:
        message = 'Incorrect audience, expected: {}'.format(
            client_id)
        raise exceptions.NotAuthorizedException(message)
    # is valid token
    except jwt.DecodeError:
        raise exceptions.NotAuthorizedException(
            'Token signature could not be validated.')
    except Exception as e:
        raise exceptions.NotAuthorizedException(
            'Token signature was malformed. {}'.format(e.message))
    return token, payload
1243037
def parse_account_key():
    """"""
    LOGGER.info("Parsing account key...")
    cmd = [
        'openssl', 'rsa',
        '-in', os.path.join(gettempdir(), 'account.key'),
        '-noout',
        '-text'
    ]
    devnull = open(os.devnull, 'wb')
    return subprocess.check_output(cmd, stderr=devnull)
1039436
def parse(contents, tokens=None):
    """"""
    # Shortcut for users who are interested in tokens
    if tokens is None:
        tokens = [t for t in tokenize(contents)]

    token_index, body = _ast_worker(tokens, len(tokens), 0, None)

    assert token_index == len(tokens)
    assert body.arguments == []

    return ToplevelBody(statements=body.statements)