Read update from stream and deserialize it.

        :param bot: bot instance. You an get it from Dispatcher
        :return: :class:`aiogram.types.Update`
421874
async def parse_update(self, bot):
        
        data = await self.request.json()
        update = types.Update(**data)
        return update
539261
async def read(self, amt=None):
        
        # botocore to aiohttp mapping
        chunk = await self.__wrapped__.read(amt if amt is not None else -1)
        self._self_amount_read += len(chunk)
        if amt is None or (not chunk and amt > 0):
            # If the server sends empty contents or
            # we ask to read all of the contents, then we know
            # we need to verify the content length.
            self._verify_content_length()
        return chunk
127240
async def receive_updates(self, request: Request):
        

        body = await request.read()

        try:
            content = ujson.loads(body)
        except ValueError:
            return json_response({
                'error': True,
                'message': 'Cannot decode body',
            }, status=400)

        logger.debug('Received from Telegram: %s', content)

        message = TelegramMessage(content, self)
        responder = TelegramResponder(content, self)
        await self._notify(message, responder)

        return json_response({
            'error': False,
        })
778229
def from_message(bot, message):
        
        chat = message["chat"]
        return Chat(bot, chat["id"], chat["type"], message)
394991
def get(self, request, bot_id, hook_id, id, format=None):
        
        bot = self.get_bot(bot_id, request.user)
        hook = self.get_hook(hook_id, bot, request.user)
        recipient = self.get_recipient(id, hook, request.user)
        serializer = self.serializer(recipient)
        return Response(serializer.data)
1244404
def update(self, mini_batch, num_sequences):
        

        feed_dict = {self.model.dropout_rate: self.update_rate,
                     self.model.batch_size: num_sequences,
                     self.model.sequence_length: self.sequence_length}
        if self.use_continuous_act:
            feed_dict[self.model.true_action] = mini_batch['actions']. \
                reshape([-1, self.brain.vector_action_space_size[0]])
        else:
            feed_dict[self.model.true_action] = mini_batch['actions'].reshape(
                [-1, len(self.brain.vector_action_space_size)])
            feed_dict[self.model.action_masks] = np.ones(
                (num_sequences, sum(self.brain.vector_action_space_size)))
        if self.use_vec_obs:
            apparent_obs_size = self.brain.vector_observation_space_size * \
                                self.brain.num_stacked_vector_observations
            feed_dict[self.model.vector_in] = mini_batch['vector_obs'] \
                .reshape([-1,apparent_obs_size])
        for i, _ in enumerate(self.model.visual_in):
            visual_obs = mini_batch['visual_obs%d' % i]
            feed_dict[self.model.visual_in[i]] = visual_obs
        if self.use_recurrent:
            feed_dict[self.model.memory_in] = np.zeros([num_sequences, self.m_size])
        run_out = self._execute_model(feed_dict, self.update_dict)
        return run_out
664264
def decode(stream, *args, **kwargs):
    
    encoding = kwargs.pop('encoding', DEFAULT_ENCODING)
    decoder = get_decoder(encoding, stream, *args, **kwargs)

    return decoder
1291499
def get_dispatcher(self):
        
        dp = self.request.app[BOT_DISPATCHER_KEY]
        try:
            from aiogram import Bot, Dispatcher
            Dispatcher.set_current(dp)
            Bot.set_current(dp.bot)
        except RuntimeError:
            pass
        return dp
681997
def load_stream(cls, st):
        """"""
        y = yaml.load(st)
        return [ Automaton(k, v) for k, v in y.iteritems() ]
1203494
def _read(cls, **kwargs):
        
        pd_obj = pandas.read_csv(**kwargs)
        if isinstance(pd_obj, pandas.DataFrame):
            return cls.from_pandas(pd_obj)
        if isinstance(pd_obj, pandas.io.parsers.TextFileReader):
            # Overwriting the read method should return a ray DataFrame for calls
            # to __next__ and get_chunk
            pd_read = pd_obj.read
            pd_obj.read = lambda *args, **kwargs: cls.from_pandas(
                pd_read(*args, **kwargs)
            )
        return pd_obj
180913
def deserialize(self, response, response_type):
        
        # handle file downloading
        # save response body into a tmp file and return the instance
        if "file" == response_type:
            return self.__deserialize_file(response)

        # fetch data from response object
        try:
            data = json.loads(response.data)
        except ValueError:
            data = response.data

        return self.__deserialize(data, response_type)
16993
def _update(self, **kwargs):
        
        updated = False
        if 'proxy_server' in kwargs:
            proxy_server = kwargs.get('proxy_server')
            if not proxy_server and self._inspected_service_ref:
                self.protocol_agent_values.pop('inspected_service_ref', None)
                updated = True
            elif isinstance(proxy_server, ProxyServer):
                # Need the inspected service reference for the protocol
                enabled_services = {svc.name:svc.href for svc in proxy_server.inspected_services}
                
                if self.protocol_agent.name not in enabled_services:
                    raise MissingDependency('The specified ProxyServer %r does not enable '
                        'the required protocol %s' % (proxy_server.name, self.protocol_agent.name))
                
                if self._inspected_service_ref != enabled_services.get(self.protocol_agent.name):
                    self.protocol_agent_values['inspected_service_ref'] = enabled_services.get(
                        self.protocol_agent.name)
                    updated = True
        return updated
1087924
def Deserialize(self, reader):
        
        self.__hash = None
        self.DeserializeUnsigned(reader)
        byt = reader.ReadByte()
        if int(byt) != 1:
            raise Exception('Incorrect format')

        witness = Witness()
        witness.Deserialize(reader)
        self.Script = witness
410712
def put(self, request, id, format=None):
        
        bot = self.get_bot(id, request.user)
        serializer = BotUpdateSerializer(bot, data=request.data)
        if serializer.is_valid():
            try:
                bot = serializer.save()
            except:
                return Response(status=status.HTTP_400_BAD_REQUEST)
            else:
                return Response(BotSerializer(bot).data)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
577197
async def _incoming_from_rtm(
        self, url: str, bot_id: str
    ) -> AsyncIterator[events.Event]:
        
        async for data in self._rtm(url):
            event = events.Event.from_rtm(json.loads(data))
            if sansio.need_reconnect(event):
                break
            elif sansio.discard_event(event, bot_id):
                continue
            else:
                yield event
973862
def deserialize(stream_or_string, **options):
    '''
    
    '''

    try:
        if not isinstance(stream_or_string, (bytes, six.string_types)):
            return toml.load(stream_or_string, **options)

        if isinstance(stream_or_string, bytes):
            stream_or_string = stream_or_string.decode('utf-8')

        return toml.loads(stream_or_string)
    except Exception as error:
        raise DeserializationError(error)
212614
def get(self, request, bot_id, id, format=None):
                
        return super(StateDetail, self).get(request, bot_id, id, format)