Build response ADU from meta data and response PDU and return it.

        :param meta_data: A dict with meta data.
        :param request_pdu: A bytearray containing request PDU.
        :return: A bytearray containing request ADU.
775204
def create_response_adu(self, meta_data, response_pdu):
        
        first_part_adu = struct.pack('>B', meta_data['unit_id']) + response_pdu
        return first_part_adu + get_crc(first_part_adu)
194727
def _metadata_endpoint(self, context):
        
        satosa_logging(logger, logging.DEBUG, "Sending metadata response", context.state)

        metadata_string = create_metadata_string(None, self.sp.config, 4, None, None, None, None,
                                                 None).decode("utf-8")
        return Response(metadata_string, content="text/xml")
1022601
def get_response(request)
      begin
        data = @transport.recv(@max_bytes)
        message = Message.decode(data, @mib)
        response = message.pdu
      end until request.request_id == response.request_id
      response
    end
664742
def build_request(self, input_data=None, *args, **kwargs):
        
        if input_data is not None:
            self.input_data = input_data
        if self.input_data is None:
            raise ValueError('Input data is None')
        if self.uo is None:
            raise ValueError('UO is None')

        self.request = RequestHolder()
        self.request.nonce = get_random_vector(EBConsts.FRESHNESS_NONCE_LEN)
        self.request.api_object = EBUtils.build_api_object(self.uo)
        self.request.endpoint = self.uo.resolve_endpoint()
        self.request.configuration = self.configuration
        self.request.api_method = EBConsts.REQUEST_PROCESS_DATA

        # Build plaintext plain_buffer
        plain_buffer = \
            to_bytes(31, 1) + to_bytes(self.uo.uo_id, 4) + \
            to_bytes(self.request.nonce, EBConsts.FRESHNESS_NONCE_LEN) + to_bytes(self.input_data)

        plain_buffer = PKCS7.pad(plain_buffer)

        # Encrypt-then-mac
        ciphertext = aes_enc(self.uo.enc_key, plain_buffer)
        mac = cbc_mac(self.uo.mac_key, ciphertext)

        # Result request body
        self.request.body = {
            "data": "Packet0_%s_0000%s" % (EBUtils.get_request_type(self.uo), to_hex(ciphertext + mac))}
        return self.request
621977
def encode_consumermetadata_request(cls, client_id, correlation_id,
                                        consumer_group):
        
        message = cls._encode_message_header(client_id, correlation_id,
                                             KafkaCodec.CONSUMER_METADATA_KEY)
        message += write_short_ascii(consumer_group)
        return message
152278
def _response(self, pdu):
        """"""
        if _debug: UDPDirector._debug("_response %r", pdu)

        # get the destination
        addr = pdu.pduSource

        # get the peer
        peer = self.peers.get(addr, None)
        if not peer:
            peer = self.actorClass(self, addr)

        # send the message
        peer.response(pdu)
253746
def get_meta_data(self, request_adu):
        "
        try:
            transaction_id, protocol_id, length, unit_id = \
                unpack_mbap(request_adu[:7])
        except struct.error:
            raise ServerDeviceFailureError()

        return {
            'transaction_id': transaction_id,
            'protocol_id': protocol_id,
            'length': length,
            'unit_id': unit_id,
        }
1374238
def getMetadataId(self, metadata):
        
        return str(datamodel.VariantSetMetadataCompoundId(
            self.getCompoundId(), 'metadata:' + metadata.key))
740732
def _GceMetadataRequest(relative_url, use_metadata_ip=False):
    """"""
    if use_metadata_ip:
        base_url = os.environ.get('GCE_METADATA_IP', '169.254.169.254')
    else:
        base_url = os.environ.get(
            'GCE_METADATA_ROOT', 'metadata.google.internal')
    url = 'http://' + base_url + '/computeMetadata/v1/' + relative_url
    # Extra header requirement can be found here:
    # https://developers.google.com/compute/docs/metadata
    headers = {'Metadata-Flavor': 'Google'}
    request = urllib.request.Request(url, headers=headers)
    opener = urllib.request.build_opener(urllib.request.ProxyHandler({}))
    try:
        response = opener.open(request)
    except urllib.error.URLError as e:
        raise exceptions.CommunicationError(
            'Could not reach metadata service: %s' % e.reason)
    return response
387494
def parse_response_adu(resp_adu, req_adu=None):
    
    resp_pdu = resp_adu[7:]
    function = create_function_from_response_pdu(resp_pdu, req_adu)

    return function.data
441385
def to_meta(self, md5=None, file=None):
        """"""
        # from collections import OrderedDict

        if not md5:
            if not file:
                raise ValueError('Must specify either file or md5')

            md5 = md5_for_file(file)
            size = os.stat(file).st_size
        else:
            size = None

        return {
            'id': self.id_,
            'identity': json.dumps(self.dict),
            'name': self.sname,
            'fqname': self.fqname,
            'md5': md5,
            # This causes errors with calculating the AWS signature
            'size': size
        }
304366
def create_from_request_pdu(pdu):

        
        _, starting_address, quantity = struct.unpack('>BHH', pdu)

        instance = ReadHoldingRegisters()
        instance.starting_address = starting_address
        instance.quantity = quantity

        return instance
714667
private JSONObject createResponseMeta(Map<String,String> metaInfo, Set<String> reqMetaInfo, Long ownerId, long requestTime)
            throws EventHandlerException, JSONException, ServiceException {
        JSONObject meta = new JsonObject();
        JSONObject headers = new JsonObject();

        for (String key : metaInfo.keySet()) {
            if (!Listener.AUTHENTICATED_USER_HEADER.equals(key)
                    && !Listener.METAINFO_HTTP_STATUS_CODE.equals(key)
                    && !Listener.METAINFO_ACCEPT.equals(key)
                    && !Listener.METAINFO_DOWNLOAD_FORMAT.equals(key)
                    && !Listener.METAINFO_MDW_REQUEST_ID.equals(key)
                    && !reqMetaInfo.contains(key)) {
                headers.put(key, metaInfo.get(key));
            }
        }

        // these always get populated if present
        if (metaInfo.get(Listener.METAINFO_REQUEST_ID) != null)
            headers.put(Listener.METAINFO_REQUEST_ID, metaInfo.get(Listener.METAINFO_REQUEST_ID));
        if (metaInfo.get(Listener.METAINFO_MDW_REQUEST_ID) != null && !metaInfo.get(Listener.METAINFO_MDW_REQUEST_ID).equals("0"))
            headers.put(Listener.METAINFO_MDW_REQUEST_ID, metaInfo.get(Listener.METAINFO_MDW_REQUEST_ID));
        if (metaInfo.get(Listener.METAINFO_CORRELATION_ID) != null)
            headers.put(Listener.METAINFO_CORRELATION_ID, metaInfo.get(Listener.METAINFO_CORRELATION_ID));
        if (metaInfo.get(Listener.METAINFO_CONTENT_TYPE) != null)
            headers.put(Listener.METAINFO_CONTENT_TYPE, metaInfo.get(Listener.METAINFO_CONTENT_TYPE));

        if (!headers.has(Listener.METAINFO_CONTENT_TYPE))
            headers.put(Listener.METAINFO_CONTENT_TYPE, "application/json");

        meta.put("headers", headers);

        createDocument(JSONObject.class.getName(), meta, OwnerType.LISTENER_RESPONSE_META, ownerId);


        ServiceLocator.getRequestServices().setElapsedTime(OwnerType.LISTENER_RESPONSE, ownerId,
                System.currentTimeMillis() - requestTime);

        return meta;
    }
300974
def create_function_from_request_pdu(pdu):
    
    function_code = get_function_code_from_request_pdu(pdu)
    try:
        function_class = function_code_to_function_map[function_code]
    except KeyError:
        raise IllegalFunctionError(function_code)

    return function_class.create_from_request_pdu(pdu)
126831
def create_build_from_buildrequest(self, build_request):
        
        build_request.set_openshift_required_version(self.os_conf.get_openshift_required_version())
        build = build_request.render()
        response = self.os.create_build(json.dumps(build))
        build_response = BuildResponse(response.json(), self)
        return build_response
1167091
def serialise_packet(self):
        
        if not hasattr(self, '_Meta'):
            raise ReferenceError("Can't serialise a packet that doesn't have an endpoint ID.")
        serialised = self.serialise()
        return struct.pack('!HH', len(serialised), self._Meta['endpoint']) + serialised
968697
def get_table_metadata(self, resource, resource_class):
        
        return self._make_metadata_request(meta_id=resource + ':' + resource_class, metadata_type='METADATA-TABLE')