Create a new model using raw API response.
339421
def process_raw_data(cls, raw_data):
        """"""
        properties = raw_data.get("properties", {})

        raw_content = properties.get("statistics", None)
        if raw_content is not None:
            statistics = BGPPeersStatistics.from_raw_data(raw_content)
            properties["statistics"] = statistics

        return super(BGPPeers, cls).process_raw_data(raw_data)
1328094
function newRecordInstance (raw) {
    // return raw data
    if (this.query.args.raw) {
        return raw
    }
    // return new model instance
    else {
        return this.query.model.newInstance({
            model: this.query.model,
            plain: this.query.args.plain,
            raw: raw,
            session: this.query.session,
        })
    }
}
354053
def build_model(self):
        """"""
        with tf.variable_scope(
                "model", reuse=None, initializer=self.initializer):
            self._create_placeholders()
            self._create_rnn_cells()
            self._create_initstate_and_embeddings()
            self._create_rnn_architecture()
            self._create_optimizer_node()
1141966
def process_raw_data(cls, raw_data):
        """"""
        properties = raw_data.get("properties", {})

        raw_metadata = raw_data.get("resourceMetadata", None)
        if raw_metadata is not None:
            metadata = ResourceMetadata.from_raw_data(raw_metadata)
            raw_data["resourceMetadata"] = metadata

        raw_state = properties.get("configurationState", None)
        if raw_state is not None:
            configuration = ConfigurationState.from_raw_data(raw_state)
            properties["configurationState"] = configuration

        return super(_BaseHNVModel, cls).process_raw_data(raw_data)
11441
def create_response(self, data=None):
        
        frame = deepcopy(self)
        if data is not None:
            frame.data = data
        frame.length = 2 + len(frame.data)
        return frame
1346641
def new(self, name=None, stack='cedar', region=None):
        """"""

        payload = {}

        if name:
            payload['app[name]'] = name

        if stack:
            payload['app[stack]'] = stack

        if region:
            payload['app[region]'] = region

        r = self._h._http_resource(
            method='POST',
            resource=('apps',),
            data=payload
        )

        name = json.loads(r.content).get('name')
        return self._h.apps.get(name)
518662
def from_raw(raw):
        """"""
        if not isinstance(raw, bytes):
            raise PyVLXException("Position::raw_must_be_bytes")
        if len(raw) != 2:
            raise PyVLXException("Position::raw_must_be_two_bytes")
        if raw != Position.from_int(Position.CURRENT_POSITION) and \
                raw != Position.from_int(Position.UNKNOWN_VALUE) and \
                Position.to_int(raw) > Position.MAX:
            raise PyVLXException("position::raw_exceed_limit", raw=raw)
        return raw
1267415
def to_instance(self, response):
        
        klass = self.schema['title']
        cls = get_model_class(klass, api=self.__api__)
        jdict = json.loads(response.content, encoding="utf-8")
        ### check if we have a response
        properties_dict = jdict[self.schema['title']]
        # @todo: find a way to handle the data
        # validation fails if the none values are not removed
        new_dict = helpers.remove_properties_containing_None(properties_dict)
        #jdict[self.schema['title']] = new_dict
        obj = cls(new_dict)
        #obj.links = jdict[self.schema['title']]['links']
        return obj
83580
async def create(self, **kwargs):
        '''
        
        '''
        try:
            # create model
            obj = self._meta.object_class()
            # deserialize data from request body
            self.data.update(kwargs)
            await obj.deserialize(self.data)
            # create document in DB
            await obj.insert(db=self.db)
            # serialize object for response
            return await obj.serialize()
        except Exception as ex:
            logger.exception(ex)
            raise BadRequest(ex)
1179218
def create_from_dictionary(self, datas):
        
        if "code" not in datas:
            raise ValueError("A response code must contain a code in \"%s\"." % repr(datas))

        code = ObjectResponseCode()
        self.set_common_datas(code, str(datas["code"]), datas)

        code.code = int(datas["code"])
        if "message" in datas:
            code.message = str(datas["message"])
        elif code.code in self.default_messages.keys():
            code.message = self.default_messages[code.code]
        if "generic" in datas:
            code.generic = to_boolean(datas["generic"])

        return code
1128821
def validate_api_call(schema, raw_request, raw_response):
    
    request = normalize_request(raw_request)

    with ErrorDict() as errors:
        try:
            validate_request(
                request=request,
                schema=schema,
            )
        except ValidationError as err:
            errors['request'].add_error(err.messages or getattr(err, 'detail'))
            return

        response = normalize_response(raw_response, raw_request)

        try:
            validate_response(
                response=response,
                request_method=request.method,
                schema=schema
            )
        except ValidationError as err:
            errors['response'].add_error(err.messages or getattr(err, 'detail'))
1164254
def _produce_instance(self, response):
        ''''''
        new_instance = self._stamp_out_core()
        # Post-process the response
        new_instance._local_update(response.json())

        # Allow for example files, which are KindTypeMismatches
        if hasattr(new_instance, 'selfLink'):
            if new_instance.kind != new_instance._meta_data[
                'required_json_kind'] \
                    and new_instance.kind != "tm:transaction:commandsstate" \
                    and 'example' not in new_instance.selfLink.split('/')[-1]:
                error_message = "For instances of type '%r' the corresponding" \
                                " kind must be '%r' but creation returned JSON with kind: %r" \
                                % (new_instance.__class__.__name__,
                                   new_instance._meta_data[
                                       'required_json_kind'],
                                   new_instance.kind)
                raise KindTypeMismatch(error_message)
        else:
            if new_instance.kind != new_instance._meta_data[
                'required_json_kind'] \
                    and new_instance.kind != "tm:transaction:commandsstate":
                error_message = "For instances of type '%r' the corresponding" \
                                " kind must be '%r' but creation returned JSON with kind: %r" \
                                % (new_instance.__class__.__name__,
                                   new_instance._meta_data[
                                       'required_json_kind'],
                                   new_instance.kind)
                raise KindTypeMismatch(error_message)

        # Update the object to have the correct functional uri.
        new_instance._activate_URI(new_instance.selfLink)
        return new_instance
472145
def _create_response(self, datapath, port, req):
        """"""
        src = datapath.ports[port].hw_addr
        res_ether = ethernet.ethernet(
            slow.SLOW_PROTOCOL_MULTICAST, src, ether.ETH_TYPE_SLOW)
        res_lacp = self._create_lacp(datapath, port, req)
        res_pkt = packet.Packet()
        res_pkt.add_protocol(res_ether)
        res_pkt.add_protocol(res_lacp)
        res_pkt.serialize()
        return res_pkt
1320247
def construct(cls: Type['Model'], values: 'DictAny', fields_set: 'SetStr') -> 'Model':
        
        m = cls.__new__(cls)
        object.__setattr__(m, '__values__', values)
        object.__setattr__(m, '__fields_set__', fields_set)
        return m
535512
def process_raw_data(cls, raw_data):
        """"""
        properties = raw_data["properties"]

        raw_content = properties.get("accessControlList", None)
        if raw_content is not None:
            resource = Resource.from_raw_data(raw_content)
            properties["accessControlList"] = resource

        # TODO(alexcoman): Add model for ServiceInsertion
        raw_content = properties.get("serviceInsertion", None)
        if raw_content is not None:
            resource = Resource.from_raw_data(raw_content)
            properties["serviceInsertion"] = resource

        raw_content = properties.get("routeTable", None)
        if raw_content is not None:
            resource = Resource.from_raw_data(raw_content)
            properties["routeTable"] = resource

        ip_configurations = []
        for raw_config in properties.get("ipConfigurations", []):
            ip_configurations.append(Resource.from_raw_data(raw_config))
        properties["ipConfigurations"] = ip_configurations

        return super(SubNetworks, cls).process_raw_data(raw_data)
844814
def create(self):
        
        if not self.can_create():
            self._tcex.handle_error(905, [self.type])

        response = self.tc_requests.create(self.api_type, self.api_sub_type, self._data, self.owner)

        if self.tc_requests.success(response):
            self._set_unique_id(response.json().get('data').get(self.api_entity))

        return response
984628
def data_raw(self):
    """"""
    return self._client.send(data=sc_pb.RequestData(
        ability_id=True, unit_type_id=True))