'Parses an HTTP WWW-Authentication Bearer challenge from a server.'

def __init__(self, request_uri, challenge):

    self.source_authority = self._validate_request_uri(request_uri)
    self.source_uri = request_uri
    self._parameters = {}
    trimmed_challenge = self._validate_challenge(challenge)
    for item in trimmed_challenge.split(','):
        comps = item.split('=')
        if (len(comps) == 2):
            key = comps[0].strip('    "')
            value = comps[1].strip('    "')
            if key:
                self._parameters[key] = value
    if (not self._parameters):
        raise ValueError('Invalid    challenge    parameters')
    if (('authorization' not in self._parameters) and ('authorization_uri' not in self._parameters)):
        raise ValueError('Invalid    challenge    parameters')
