Format an RPC call and response.

    Args:
        data (tuple): A tuple containing the address, rpc_id, argument and
            response payloads and any error code.

    Returns:
        str: The formated RPC string.
197584
def format_rpc(data):
    

    address, rpc_id, args, resp, _status = data

    name = rpc_name(rpc_id)

    if isinstance(args, (bytes, bytearray)):
        arg_str = hexlify(args)
    else:
        arg_str = repr(args)

    if isinstance(resp, (bytes, bytearray)):
        resp_str = hexlify(resp)
    else:
        resp_str = repr(resp)

    #FIXME: Check and print status as well
    return "%s called on address %d, payload=%s, response=%s" % (name, address, arg_str, resp_str)
1220845
def format_response(self, response_data):
        """"""

        _addr, length = self.response_info()
        if len(response_data) != length:
            raise HardwareError("Invalid response read length, should be the same as what response_info() returns", expected=length, actual=len(response_data))

        resp, flags, received_length, payload = struct.unpack("<HxBL4x20s", response_data)
        resp = resp & 0xFF
        if flags & (1 << 3):
            raise HardwareError("Could not grab external gate")

        if received_length > 20:
            raise HardwareError("Invalid received payload length > 20 bytes", received_length=received_length)

        payload = payload[:received_length]

        return {
            'status': resp,
            'payload': payload
        }
544598
def _FormatIPToken(self, token_data):
    
    data = ''.join(['{0:02x}'.format(byte) for byte in token_data.data])
    return {'IPv4_Header': data}
734220
def dataReceived(self, data):
        
        self.stompBuffer.appendData(data)

        while True:
           msg = self.stompBuffer.getOneMessage()
           if msg is None:
               break

           returned = self.react(msg)
           if returned:
               self.transport.write(returned)
1343639
def rpc_call(self, request, method=None, **payload):
        
        if not method or self.separator not in method:
            raise AssertionError("Wrong method name: {0}".format(method))

        resource_name, method = method.split(self.separator, 1)
        if resource_name not in self.api.resources:
            raise AssertionError("Unknown method " + method)

        data = QueryDict('', mutable=True)
        data.update(payload.get('data', dict()))
        data['callback'] = payload.get('callback') or request.GET.get(
            'callback') or request.GET.get('jsonp') or 'callback'
        for h, v in payload.get('headers', dict()).iteritems():
            request.META["HTTP_%s" % h.upper().replace('-', '_')] = v

        request.POST = request.PUT = request.GET = data
        delattr(request, '_request')
        request.method = method.upper()
        request.META['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'
        params = payload.pop('params', dict())
        response = self.api.call(resource_name, request, **params)

        if not isinstance(response, SerializedHttpResponse):
            return response

        if response['Content-type'] in self._meta.emitters_dict:
            return HttpResponse(response.content, status=response.status_code)

        if response.status_code == 200:
            return response.response

        raise AssertionError(response.response)
1214649
def format_raw_data(self, tpe, raw_data):
        
        
        if tpe == 'text':
            formatted_raw_data = self.parse_text_to_dict(raw_data)
        elif tpe == 'file':
            formatted_raw_data = self.parse_file_to_dict(raw_data)
        else:
            formatted_raw_data = {'ERROR':'unknown data type', 'data':[raw_data]}
        return formatted_raw_data
568886
def err_response(reqid, code, msg, data=None):
    
    err = { "code": code, "message": msg }
    if data:
        err["data"] = data
    return { "jsonrpc": "2.0", "id": reqid, "error": err }
1008365
def return_data(self, data, format=None):
        
        if format is None:
            format = self.format
        if format == "json":
            formatted_data = json.loads(data)
        else:
            formatted_data = data
        return formatted_data
503533
def create_response(
        self, data: dict = None, response: requests.Response = None, errors: list = None
    ) -> Response:
        
        status = FAILURE_STATUS if errors else SUCCESS_STATUS
        return Response(
            status=status,
            provider=self.name,
            data=data,
            response=response,
            errors=errors,
        )
306703
def parse(self, data):
        
        parsed_data = self.yacc.parse(
            data, lexer=self.lexer.get_yacc_compat_lexer(), debug=self.debug)
        self.errors = self.lexer.errors + self.errors
        return parsed_data, self.errors
547735
def pack_rpc_response(response=None, exception=None):
    

    if response is None:
        response = bytes()

    if exception is None:
        status = (1 << 6)
        if len(response) > 0:
            status |= (1 << 7)
    elif isinstance(exception, (RPCInvalidIDError, RPCNotFoundError)):
        status = 2
    elif isinstance(exception, BusyRPCResponse):
        status = 0
    elif isinstance(exception, TileNotFoundError):
        status = 0xFF
    elif isinstance(exception, RPCErrorCode):
        status = (1 << 6) | (exception.params['code'] & ((1 << 6) - 1))
    else:
        status = 3

    return status, response
150909
def _tuple_repr(data):
    """"""
    if len(data) == 1:
        return "(%s,)" % rpr(data[0])
    else:
        return "(%s)" % ", ".join([rpr(x) for x in data])
1088807
def set_data(self, data: AnyStr) -> None:
        
        if isinstance(data, str):
            bytes_data = data.encode(self.charset)
        else:
            bytes_data = data
        self.response = self.data_body_class(bytes_data)
        if self.automatically_set_content_length:
            self.content_length = len(bytes_data)
1093374
def create_response_pdu(self, data):
        
        log.debug('Create multi bit response pdu {0}.'.format(data))
        fmt = '>BB' + conf.TYPE_CHAR * len(data)

        return struct.pack(fmt, self.function_code, len(data) * 2, *data)
771409
def data(self, data=None):
        
        if data is not None:
            self.response_model.data = data
        return self.response_model.data
1174372
def parse(self, data):
        
        method = getattr(self, '_parse_{0}'.format(self._format))
        return method(data)
1330843
def arp_parse(data):
        
        # Iteratize pkt
        pkt = packet.Packet(data)
        i = iter(pkt)
        eth_pkt = next(i)
        # Ensure it's an ethernet frame.
        assert isinstance(eth_pkt, ethernet.ethernet)

        arp_pkt = next(i)
        if not isinstance(arp_pkt, arp.arp):
            raise ARPPacket.ARPUnknownFormat()

        if arp_pkt.opcode not in (ARP_REQUEST, ARP_REPLY):
            raise ARPPacket.ARPUnknownFormat(
                msg='unsupported opcode %d' % arp_pkt.opcode)

        if arp_pkt.proto != ETH_TYPE_IP:
            raise ARPPacket.ARPUnknownFormat(
                msg='unsupported arp ethtype 0x%04x' % arp_pkt.proto)

        return arp_pkt