Parse response text like the one returned by http://jsonip.com/.
349031
def _parser_jsonip(text):
    """"""
    import json
    try:
        return str(json.loads(text).get("ip"))
    except ValueError as exc:
        LOG.debug("Text '%s' could not be parsed", exc_info=exc)
        return None
1128374
def _parse_request_reply(self):
        ""
        # we need at least 6 bytes of data: 4 for the "header", such
        # as it is, and 2 more if it's DOMAINNAME (for the size) or 4
        # or 16 more if it's an IPv4/6 address reply. plus there's 2
        # bytes on the end for the bound port.
        if len(self._data) < 8:
            return
        msg = self._data[:4]

        # not changing self._data yet, in case we've not got
        # enough bytes so far.
        (version, reply, _, typ) = struct.unpack('BBBB', msg)

        if version != 5:
            self.reply_error(SocksError(
                "Expected version 5, got {}".format(version)))
            return

        if reply != self.SUCCEEDED:
            self.reply_error(_create_socks_error(reply))
            return

        reply_dispatcher = {
            self.REPLY_IPV4: self._parse_ipv4_reply,
            self.REPLY_HOST: self._parse_domain_name_reply,
            self.REPLY_IPV6: self._parse_ipv6_reply,
        }
        try:
            method = reply_dispatcher[typ]
        except KeyError:
            self.reply_error(SocksError(
                "Unexpected response type {}".format(typ)))
            return
        method()
284567
def wrapped_resource(response):
    
    # decode response text, assuming utf-8 if unset
    response_content = response.content.decode(response.encoding or 'utf-8')

    try:
        content = json.loads(response_content)
    except ValueError:
        # not JSON
        content = response_content
    if isinstance(content, list):
        result = ResourceList(content)
    else:
        result = Resource(content)
        if hasattr(result, 'collection'):
            result.collection = ResourceList(result.collection)
    result.raw_data = response_content

    for attr in ('encoding', 'url', 'status_code', 'reason'):
        setattr(result, attr, getattr(response, attr))

    return result
1106608
function (response, expectedResponseType) {
            if (expectedResponseType == "text") {
                if (!response.responseText && response.responseJSON != null) {
                    // convert JSON to text
                    if (ariaUtilsType.isString(response.responseJSON)) {
                        // this case is important for JSON-P services which return a simple string
                        // we simply use that string as text
                        // (could be useful to load templates through JSON-P, for example)
                        response.responseText = response.responseJSON;
                    } else {
                        // really convert the JSON structure to a string
                        response.responseText = ariaUtilsJson.convertToJsonString(response.responseJSON);
                    }
                }
            } else if (expectedResponseType == "json") {
                if (response.responseJSON == null && response.responseText != null) {
                    // convert text to JSON
                    var errorMsg = (require("../utils/String")).substitute(this.JSON_PARSING_ERROR, [response.url,
                            response.responseText]);
                    if (response.responseText === "") {
                        var undef;
                        response.responseJSON = undef;
                    } else {
                        response.responseJSON = ariaUtilsJson.load(response.responseText, this, errorMsg);
                    }
                }
            }

        }
172696
def parse_encrypted_response(self, response):
        
        content_type = response.headers['Content-Type']
        if 'protocol="{0}"'.format(self.protocol_string.decode()) in content_type:
            host = urlsplit(response.request.url).hostname
            msg = self._decrypt_response(response, host)
        else:
            msg = response.text

        return msg
1364987
def parse_info(response):
    ''''''
    info = {}
    response = response.decode('utf-8')

    def get_value(value):
        if ',' and '=' not in value:
            return value
        sub_dict = {}
        for item in value.split(','):
            k, v = item.split('=')
            try:
                sub_dict[k] = int(v)
            except ValueError:
                sub_dict[k] = v
        return sub_dict
    data = info
    for line in response.splitlines():
        keyvalue = line.split(':')
        if len(keyvalue) == 2:
            key, value = keyvalue
            try:
                data[key] = int(value)
            except ValueError:
                data[key] = get_value(value)
        else:
            data = {}
            info[line[2:]] = data
    return info
1036369
def _as_json(self, response):
        
        # Assume ClientResponse has "body", and otherwise it's a requests.Response
        content = response.text() if hasattr(response, "body") else response.text
        try:
            return json.loads(content)
        except ValueError:
            raise DeserializationError(
                "Error occurred in deserializing the response body.")
335913
def parse(self, response):
        
        self.headers = response.headers

        if 'xml' in self.headers.get('Content-Type'):
            # Got an XML response, likely an error code.
            xml = xmltodict.parse(response.text)
            self.analyze_reply_code(xml_response_dict=xml)

        lines = response.text.split('\r\n')
        if len(lines) < 3:
            lines = response.text.split('\n')

        for line in lines:
            line = line.strip()

            name, value = self.read_line(line)
            if name:
                if name in self.valid_transactions or re.match(pattern='/^X\-/', string=name):
                    self.capabilities[name] = value
                else:
                    self.details[name] = value
811802
def _parse_response(self, response):
        

        response_dict = {}
        for line in response.splitlines():
            key, value = response.split("=", 1)
            response_dict[key] = value
        return response_dict
2933
def GET(self, url):
        """"""
        r = requests.get(url)
        if self.verbose:
            sys.stdout.write("%s %s\n" % (r.status_code, r.encoding))
            sys.stdout.write(str(r.headers) + "\n")
        self.encoding = r.encoding
        return r.text
274079
def extract_data_from_response(self, response, data_key=None):
        """"""
        response_json_data = response.json()
        # Seems to be two types of response, a dict with keys and then lists of data or a flat list data with no key.
        if type(response_json_data) == list:
            # Return the data
            return response_json_data
        elif type(response_json_data) == dict:
            if data_key is None:
                return response_json_data
            else:
                return response_json_data[data_key]
        else:
            raise CanvasAPIError(response)
1147176
def parse_response(response)
      parsed_response = JSON.parse(response.body, :symbolize_names => true)
      if response.code.to_i.between?(400,599)
        raise Monzo::APIError, "#{parsed_response[:code]}: #{parsed_response[:error]}"
      end
      parsed_response
    end
1216215
def parse_response(response):
    
    if response.headers.get('Content-Type', JSON_TYPE).startswith(JSON_TYPE):
        return ResponseObject(json.loads(response.body))
    else:
        return response.body
131967
function parseResponse(response) {
  let text;

  if (response && response.content && (typeof response.content === 'string')) {
    text = response.content;
  }

  if (response && response.text && (typeof response.text === 'string')) {
    text = response.text;
  }

  if (!text) {
    console.error('Did not supply any matching response format. Response is:', text);
    return null;
  }

  try {
    const parsedResponse = JSON.parse(text);

    if (
      parsedResponse
      && parsedResponse.data
      && (parsedResponse.data instanceof Object === true)
    ) {
      return parsedResponse.data;
    }
  } catch (err) {
    console.error('Error while parsing JSON', err);
  }

  return null;
}
937292
def parse(self, response, metadata_type):
        
        xml = xmltodict.parse(response.text)
        self.analyze_reply_code(xml_response_dict=xml)
        base = xml.get('RETS', {}).get('METADATA', {}).get(metadata_type, {})

        if metadata_type == 'METADATA-SYSTEM':
            syst = base.get('System', base.get('SYSTEM'))
            if not syst:
                raise ParseError("Could not get the System key from a METADATA-SYSTEM request.")

            system_obj = {}
            if syst.get('SystemID'):
                system_obj['system_id'] = str(syst['SystemID'])
            if syst.get('SystemDescription'):
                system_obj['system_description'] = str(syst['SystemDescription'])
            if syst.get('Comments'):
                system_obj['comments'] = syst['Comments']
            if base.get('@Version'):
                system_obj['version'] = base['@Version']
            return [system_obj]

        elif metadata_type == 'METADATA-CLASS':
            key = 'class'
        elif metadata_type == 'METADATA-RESOURCE':
            key = 'resource'
        elif metadata_type == 'METADATA-LOOKUP_TYPE':
            key = 'lookuptype'
        elif metadata_type == 'METADATA-OBJECT':
            key = 'object'
        elif metadata_type == 'METADATA-TABLE':
            key = 'field'
        else:
            msg = "Got an unknown metadata type of {0!s}".format(metadata_type)
            raise ParseError(msg)

        # Get the version with the right capitalization from the dictionary
        key_cap = None
        for k in base.keys():
            if k.lower() == key:
                key_cap = k

        if not key_cap:
            msg = 'Could not find {0!s} in the response XML'.format(key)
            raise ParseError(msg)

        if isinstance(base[key_cap], list):
            return base[key_cap]
        else:
            return [base[key_cap]]
470590
def parse_response(self, response):
        
        status = response.status_code
        if response.ok:
            data = response.json()
            return HttpResponse(ok=response.ok, status=status, errors=None, data=data)
        else:
            try:
                errors = response.json()
            except ValueError:
                errors = response.content
            return HttpResponse(ok=response.ok, status=status, errors=errors, data=None)
686883
def parse(response):
        """Split a a=1b=2c=3 string into a dictionary of pairs"""
        tokens = {r[0]: r[1] for r in [r.split('=') for r in response.split("&")]}

        # The odd dummy parameter is of no use to us
        if 'dummy' in tokens:
            del tokens['dummy']

        """
        If we have key names that end in digits, these indicate the result set contains multiple sets
        For example, planet0=Hoth&x=1&y=-10&planet1=Naboo&x=9&y=13 is actually data for two planets

        Elements that end in digits (like tag0, tag1 for planets) are formatted like (tag0_1, tag1_1), so we rstrip
        underscores afterwards.
        """
        if re.match('\D\d+$', tokens.keys()[0]):
            # Produce a list of dictionaries
            set_tokens = []
            for key, value in tokens:
                key = re.match('^(.+\D)(\d+)$', key)
                # If the key isn't in the format (i.e. a failsafe), skip it
                if key is not None:
                    if key.group(1) not in set_tokens:
                        set_tokens[key.group(1)] = {}

                    set_tokens[key.group(1)][key.group(0).rstrip('_')] = value
            tokens = set_tokens

        return tokens