Analyze Zabbix Server response
        Returns a list with number of:
        * processed items
        * failed items
        * total items
        * time spent

        :zbx_answer: Zabbix server response as string
342356
def _handle_response(self, zbx_answer):
        
        zbx_answer = json.loads(zbx_answer)
        if self._logger: # pragma: no cover
            self._logger.info(
                "Anaylizing Zabbix Server's answer"
            )
            if zbx_answer:
                self._logger.debug("Zabbix Server response is: [%s]" % zbx_answer)

        # Default items number in length of th storage list
        nb_item = len(self._items_list)
        if self._config.debug_level >= 4:
            # If debug enabled, force it to 1
            nb_item = 1

        # If dryrun is disabled, we can process answer
        response = zbx_answer.get('response')
        result = re.findall(ZBX_RESP_REGEX, zbx_answer.get('info'))
        processed, failed, total, time = result[0]

        return response, int(processed), int(failed), int(total), float(time)
1153365
def _handle_response(response, command, id_xpath='./id', **kwargs):
    
    _response_switch = {
        'insert': ModifyResponse,
        'replace': ModifyResponse,
        'partial-replace': ModifyResponse,
        'update': ModifyResponse,
        'delete': ModifyResponse,
        'search-delete': SearchDeleteResponse,
        'reindex': Response,
        'backup': Response,
        'restore': Response,
        'clear': Response,
        'status': StatusResponse,
        'search': SearchResponse,
        'retrieve': ListResponse,
        'similar': ListResponse,
        'lookup': LookupResponse,
        'alternatives': AlternativesResponse,
        'list-words': WordsResponse,
        'list-first': ListResponse,
        'list-last': ListResponse,
        'retrieve-last': ListResponse,
        'retrieve-first': ListResponse,
        'show-history': None,
        'list-paths': ListPathsResponse,
        'list-facets': ListFacetsResponse}
    try:
        request_class = _response_switch[command]
    except KeyError:
        request_class = Response
    return request_class(response, id_xpath, **kwargs)
426165
def parse_image_response(self, response):
        
        if 'xml' in response.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)

        multi_parts = self._get_multiparts(response)
        parsed = []
        # go through each part of the multipart message
        for part in multi_parts:
            clean_part = part.strip('\r\n\r\n')
            if '\r\n\r\n' in clean_part:
                header, body = clean_part.split('\r\n\r\n', 1)
            else:
                header = clean_part
                body = None
            part_header_dict = {k.strip(): v.strip() for k, v in (h.split(':', 1) for h in header.split('\r\n'))}

            # Some multipart requests respond with a text/XML part stating an error
            if 'xml' in part_header_dict.get('Content-Type'):
                # Got an XML response, likely an error code.
                # Some rets servers give characters after the closing brace.
                body = body[:body.index('/>') + 2]  if '/>' in body else body
                xml = xmltodict.parse(body)
                try:
                    self.analyze_reply_code(xml_response_dict=xml)
                except RETSException as e:
                    if e.reply_code == '20403':
                        # The requested object_id was not found.
                        continue
                    raise e

            if body:
                obj = self._response_object_from_header(
                    obj_head_dict=part_header_dict,
                    content=body.encode('latin-1') if six.PY3 else body)
            else:
                obj = self._response_object_from_header(obj_head_dict=part_header_dict)
            parsed.append(obj)
        return parsed
483435
def _api_response(response):
    '''
    
    '''
    if response.status_code == 404:
        __context__['retcode'] = salt.defaults.exitcodes.SALT_BUILD_FAIL
        raise CommandExecutionError('Element doesn\'t exists')
    if response.status_code == 401:
        __context__['retcode'] = salt.defaults.exitcodes.SALT_BUILD_FAIL
        raise CommandExecutionError('Bad username or password')
    elif response.status_code == 200 or response.status_code == 500:
        try:
            data = salt.utils.json.loads(response.content)
            if data['exit_code'] != 'SUCCESS':
                __context__['retcode'] = salt.defaults.exitcodes.SALT_BUILD_FAIL
                raise CommandExecutionError(data['message'])
            return data
        except ValueError:
            __context__['retcode'] = salt.defaults.exitcodes.SALT_BUILD_FAIL
            raise CommandExecutionError('The server returned no data')
    else:
        response.raise_for_status()
1055478
def _process_req_txt(req):
    ''''''
    if req.status_code == 404:
        return ''
    if req.status_code != 200:
        raise DapiCommError('Response of the server was {code}'.format(code=req.status_code))
    return req.text
720403
private void parseResponse(ModelNode response, AsyncCallback<Map<String,String>> callback) {

        //System.out.println(response.toString());

        Map<String, String> serverValues = new HashMap<String,String>();

        if(isStandalone)
        {
            serverValues.put("Standalone Server", response.get(RESULT).asString());
        }
        else if(response.hasDefined("server-groups"))
        {

            List<Property> groups = response.get("server-groups").asPropertyList();
            for(Property serverGroup : groups)
            {
                List<Property> hosts = serverGroup.getValue().get("host").asPropertyList();
                for(Property host : hosts)
                {
                    List<Property> servers = host.getValue().asPropertyList();
                    for(Property server : servers)
                    {
                        serverValues.put(server.getName(),
                                server.getValue().get("response").get("result").asString()
                        );
                    }
                }
            }
        }

        callback.onSuccess(serverValues);
    }
662078
def build(self, response):
        
        response_json = response.json()

        # Special case for ticket audits.
        if get_endpoint_path(self.api, response).startswith('/ticket_audits.json'):
            return TicketAuditGenerator(self, response_json)

        zenpy_objects = self.deserialize(response_json)

        # Collection of objects (eg, users/tickets)
        plural_object_type = as_plural(self.api.object_type)
        if plural_object_type in zenpy_objects:
            return ZendeskResultGenerator(self, response_json, response_objects=zenpy_objects[plural_object_type])

        # Here the response matches the API object_type, seems legit.
        if self.api.object_type in zenpy_objects:
            return zenpy_objects[self.api.object_type]

        # Could be anything, if we know of this object then return it.
        for zenpy_object_name in self.object_mapping.class_mapping:
            if zenpy_object_name in zenpy_objects:
                return zenpy_objects[zenpy_object_name]

        # Maybe a collection of known objects?
        for zenpy_object_name in self.object_mapping.class_mapping:
            plural_zenpy_object_name = as_plural(zenpy_object_name)
            if plural_zenpy_object_name in zenpy_objects:
                return ZendeskResultGenerator(self, response_json, object_type=plural_zenpy_object_name)

        # Bummer, bail out.
        raise ZenpyException("Unknown Response: " + str(response_json))
324669
def _get_buffered_response(self):
        

        response = self._get_response()

        if response.request.method == 'DELETE' and response.status_code == 204:
            return [{'status': 'record deleted'}], 1

        result = self._response.json().get('result', None)

        if result is None:
            raise MissingResult('The expected `result` key was missing in the response. Cannot continue')

        length = 0

        if isinstance(result, list):
            length = len(result)
        elif isinstance(result, dict):
            result = [result]
            length = 1

        return result, length
460764
def analyze_reply_code(self, xml_response_dict):
        
        if 'RETS-STATUS' in xml_response_dict:
            attributes = self.get_attributes(xml_response_dict['RETS-STATUS'])
            reply_code = attributes['ReplyCode']
            reply_text = attributes.get('ReplyText', 'RETS did not supply a Reply Text.')

            logger.debug("Received ReplyCode of {0!s} from the RETS Server: {0!s}".format(reply_code, reply_text))
            if reply_code != '0':
                raise RETSException(reply_text, reply_code)

        elif 'RETS' not in xml_response_dict:  # pragma: no cover
            raise RETSException("The <RETS> tag was expected in the response XML but it was not found.")

        attributes = self.get_attributes(input_dict=xml_response_dict['RETS'])
        if 'ReplyCode' not in attributes:  # pragma: no cover
            # The RETS server did not return a response code.
            return True

        reply_code = attributes['ReplyCode']
        reply_text = attributes.get('ReplyText', 'RETS did not supply a Reply Text.')

        logger.debug("Received ReplyCode of {0!s} from the RETS Server: {0!s}".format(reply_code, reply_text))
        if reply_code != '0':
            raise RETSException(reply_text, reply_code)
816580
def _read_response(self):
        
        try:
            line = self.readline()
        except RuntimeError:
            Dut._logger.warning("Failed to read PIPE", extra={'type': '!<-'})
            return -1
        if line:
            if self.store_traces:
                self.traces.append(line)
                self.response_traces.append(line)
            EventObject(EventTypes.DUT_LINE_RECEIVED, self, line)
            match = re.search(r"^\[([\w\W]{4})\]\[([\W\w]{4,}?)\]\: (.*)", line)
            if match:
                self.logger.debug(line, extra={'type': '<<<'})
            else:
                self.logger.info(line, extra={'type': '<--'})

            retcode = self.check_retcode(line)
            if retcode is not None:
                resp = CliResponse()
                resp.retcode = retcode
                resp.traces = self.response_traces
                resp.lines = self.response_traces
                self.response_traces = []
                return resp
        return None
109971
def _list_response(self, response):
        
        if type(response) is list:
            return response
        if type(response) is dict:
            return [response]
185738
def _getResponse(self):
        
        resp_dict= dict()
        resp_str = self._conn.read_until("\r\n\r\n", connTimeout)
        for line in resp_str.split("\r\n"):
            mobj = re.match('(\w+):\s*(\S.*)$', line);
            if mobj:
                resp_dict[mobj.group(1)] = mobj.group(2)
            else:
                mobj = re.match('(.*)--END COMMAND--\s*$', line, flags=re.DOTALL)
                if mobj:
                    resp_dict['command_response'] = mobj.group(1)
        return resp_dict
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()
764125
def analyses(self):
        
        response = self._request("tasks/list")

        return json.loads(response.content.decode('utf-8'))['tasks']
399144
def __respond_with_list(self, data):
        
        response = []
        if isinstance(data, dict):
            data.pop('seq', None)
            data = list(data.values())

        for item in data:
            values = item
            if isinstance(item, list) or isinstance(item, dict):
                values = self.__respond_with_list(item)

            if isinstance(values, list) and len(values) == 1:
                response.extend(values)
            else:
                response.append(values)

        return response
1002291
def get_nb_strings(self):
        
        nb = 0
        seen = []
        for digest, dx in self.analyzed_vms.items():
            if dx in seen:
                continue
            seen.append(dx)
            nb += len(dx.get_strings_analysis())
        return nb
318839
def process_response(self, request, response):
        """"""

        # For debug only.
        if not settings.DEBUG:
            return response

        # Check for responses where the data can't be inserted.
        content_encoding = response.get('Content-Encoding', '')
        content_type = response.get('Content-Type', '').split(';')[0]
        if any((getattr(response, 'streaming', False),
                'gzip' in content_encoding,
                content_type not in _HTML_TYPES)):
            return response

        content = force_text(response.content, encoding=settings.DEFAULT_CHARSET)

        pattern = re.escape('</body>')
        bits = re.split(pattern, content, flags=re.IGNORECASE)

        if len(bits) > 1:
            bits[-2] += debug_payload(request, response, self.view_data)
            response.content = "</body>".join(bits)
            if response.get('Content-Length', None):
                response['Content-Length'] = len(response.content)

        return response