Example #1
0
def serve():
    tornado.platform.asyncio.AsyncIOMainLoop().install()

    asyncio.async(cleanup())

    app = make_app(server_settings.DEBUG)

    ssl_options = None
    if server_settings.SSL_CERT_FILE and server_settings.SSL_KEY_FILE:
        ssl_options = {
            'certfile': server_settings.SSL_CERT_FILE,
            'keyfile': server_settings.SSL_KEY_FILE,
        }

    app.listen(
        server_settings.PORT,
        address=server_settings.ADDRESS,
        xheaders=server_settings.XHEADERS,
        max_buffer_size=server_settings.MAX_BUFFER_SIZE,
        ssl_options=ssl_options,
    )

    logger.info("Listening on {0}:{1}".format(server_settings.ADDRESS, server_settings.PORT))

    asyncio.get_event_loop().set_debug(server_settings.DEBUG)
    asyncio.get_event_loop().run_forever()
Example #2
0
	def handleGeneralFailure(self, error):
		""" If everything else fails then call this function as a final resort
		    Its job is to clean up the connection (i.e. cleanly disengage from the
		    bus and then report a complete and final failure to the outer code.
		"""
		asyncio.get_event_loop().call_soon(self.close)
		raise(error)
Example #3
0
    def send_tracked_message(self, body_or_stanza, *,
                             timeout=timedelta(seconds=120)):
        """
        Send a tracked message. The first argument can either be a
        :class:`~.Message` or a mapping compatible with
        :attr:`~.Message.body`.

        Return a :class:`~.tracking.MessageTracker` which tracks the
        message. See the documentation of :class:`~.MessageTracker` and
        :class:`~.MessageState` for more details on tracking in general.

        Tracking a MUC groupchat message supports tracking up to the
        :attr:`~.MessageState.DELIVERED_TO_RECIPIENT` state. If a `timeout` is
        given, it must be a :class:`~datetime.timedelta` indicating the time
        span after which the tracking shall time out. `timeout` may be
        :data:`None` to let the tracking never expire.

        .. warning::

           Some MUC implementations rewrite the ``id`` when the message is
           reflected in the MUC. In that case, tracking cannot succeed beyond
           the :attr:`~.MessageState.DELIVERED_TO_SERVER` state, which is
           provided by the basic tracking interface.

           To support these implementations, the `timeout` defaults at 120
           seconds; this avoids that sending a message becomes a memory leak.

        If the chat is exited in the meantime, the messages are set to
        :attr:`~.MessageState.UNKNOWN` state. This also happens on suspension
        and resumption.
        """
        if isinstance(body_or_stanza, aioxmpp.stanza.Message):
            message = body_or_stanza
            message.type_ = aioxmpp.structs.MessageType.GROUPCHAT
            message.to = self.mucjid
        else:
            message = aioxmpp.stanza.Message(
                type_=aioxmpp.structs.MessageType.GROUPCHAT,
                to=self.mucjid
            )
            message.body.update(body_or_stanza)

        tracker = aioxmpp.tracking.MessageTracker()
        token = self.service.client.stream.enqueue_stanza(
            message,
            on_state_change=tracker.on_stanza_state_change
        )
        tracker.token = token

        self._tracking[message.id_] = tracker

        if timeout is not None:
            asyncio.get_event_loop().call_later(
                timeout.total_seconds(),
                self._tracking_timeout,
                message.id_,
                tracker
            )

        return tracker
Example #4
0
    async def handler(self):
        """Handle the lifetime of the connection. Receive all messages from the
        stream and send them to the appropriate partner."""
        await self.send(
            b'Server: Welcome to TCP chat roulette! '
            b'You will be matched with a partner.\n'
            b'Server: What is your name?\n')

        # Main client read loop. Read lines until disconnection.
        while True:
            if self.name is not None and self.name not in clients:
                # We have been removed from client list by self.disconnected(),
                # so shut down this task.
                return
            try:
                data = await self.reader.readline()
                if not data:
                    await self.disconnected()
                elif self.name is None:
                    # First interaction with client is to set their name.
                    if await self.set_name(data):
                        # Successful onboarding; match client.
                        clients[self.name] = self
                        asyncio.get_event_loop().create_task(self.match())
                    else:
                        continue
                elif data.startswith(b'/'):
                    await self.handle_cmd(data)
                else:
                    await self.message_partner(data)
            except OSError:
                await self.disconnected()
Example #5
0
 def callback():
     if self.method == 'stop':
         get_event_loop().stop()
     elif self.method == 'exit':
         sys.exit()
     else:
         raise BaseException('this should crash the application')
Example #6
0
 def _create_pubsub_handler(cls):
     if cls._tcp_service:
         asyncio.get_event_loop().run_until_complete(
             cls._tcp_service.pubsub_bus.create_pubsub_handler(cls.pubsub_host, cls.pubsub_port))
     if cls._http_service:
         asyncio.get_event_loop().run_until_complete(
             cls._http_service.pubsub_bus.create_pubsub_handler(cls.pubsub_host, cls.pubsub_port))
Example #7
0
def sync_main(args=None):
    # interactive mode is a little messy, that's why this is not using aiocoap.util.cli yet
    if args is None:
        args = sys.argv[1:]

    if '--interactive' not in args:
        try:
            asyncio.get_event_loop().run_until_complete(single_request(args))
        except KeyboardInterrupt:
                sys.exit(3)
    else:
        if len(args) != 1:
            print("No other arguments must be specified when entering interactive mode", file=sys.stderr)
            sys.exit(1)

        loop = asyncio.get_event_loop()
        task = asyncio.Task(interactive())

        while not task.done():
            try:
                loop.run_until_complete(task)
            except KeyboardInterrupt:
                if not interactive_expecting_keyboard_interrupt.done():
                    interactive_expecting_keyboard_interrupt.set_result(None)
            except SystemExit:
                continue # asyncio/tasks.py(242) raises those after setting them as results, but we particularly want them back in the loop
Example #8
0
    def periodic_aggregated_stats_logger(cls):
        hostname = socket.gethostbyname(socket.gethostname())

        logd = cls._stats.to_dict()
        logs = []
        for server_type in ['http', 'tcp']:
            try:
                server_type_d = logd['sub'][server_type]['sub']
            except KeyError:
                continue
            for k, v in server_type_d.items():
                d = dict({
                    'method': k,
                    'server_type': server_type,
                    'hostname': hostname,
                    'service_name': cls._service_name,
                    'average_response_time': v['average'],
                    'total_request_count': v['count'],
                    'success_count': v['success_count']
                })
                for k2, v2 in v['sub'].items():
                    d['CODE_{}'.format(k2)] = v2['count']
                logs.append(d)

        _logger = logging.getLogger('stats')
        for logd in logs:
            _logger.info(dict(logd))

        asyncio.get_event_loop().call_later(300, cls.periodic_aggregated_stats_logger)
Example #9
0
    def quit(self):
        """Quit snipe."""

        for w in self.fe.get_windows():
            w.quit_hook()

        asyncio.get_event_loop().stop()
Example #10
0
async def test_app_make_handler_access_log_class(mocker) -> None:
    class Logger:
        pass

    app = web.Application()

    with pytest.raises(TypeError):
        app._make_handler(access_log_class=Logger)

    class Logger(AbstractAccessLogger):

        def log(self, request, response, time):
            self.logger.info('msg')

    srv = mocker.patch('aiohttp.web_app.Server')

    app._make_handler(access_log_class=Logger)
    srv.assert_called_with(app._handle,
                           access_log_class=Logger,
                           request_factory=app._make_request,
                           loop=asyncio.get_event_loop(),
                           debug=mock.ANY)

    app = web.Application(handler_args={'access_log_class': Logger})
    app._make_handler(access_log_class=Logger)
    srv.assert_called_with(app._handle,
                           access_log_class=Logger,
                           request_factory=app._make_request,
                           loop=asyncio.get_event_loop(),
                           debug=mock.ANY)
Example #11
0
 def connection_made(self, transport):
     self.transport = transport
     # I couldn't find a good way to close the socket,
     # so have to schedule a call to do that
     asyncio.get_event_loop().call_later(3, self.transport.close)
     logging.debug('querying ' + byte_2_domain(self.query_data[12:]))
     self.transport.sendto(self.query_data)
Example #12
0
def main():
    loop = asyncio.get_event_loop()
    coro = serial.aio.create_serial_connection(loop, serPort, url='/dev/arduino', baudrate=38400)
    ser_task = asyncio.ensure_future(coro)
    loop.run_until_complete(coro)
    ###print("ser_task result: {}".format(ser_task.result()))
    ser_transport = ser_task.result()[0]
    ser_protocol = ser_task.result()[1]
    ###writer = asyncio.StreamWriter(ser_transport, ser_protocol, reader, loop)
    ###print(ser_transport)

    #loop = asyncio.get_event_loop()
    #coro  = serial.aio.create_serial_connection(loop, serPort, '/dev/arduino',baudrate=38400)
    #ser_task = asyncio.ensure_future(coro)
    #loop.run_until_complete(coro)
    #print("ser_task result 0: {}".format(ser_task.result()[0]))
    #print("ser_task result 1: {}".format(ser_task.result()[1].data_received))
    #newtask = loop.create_task(ser_task.result()[1].data_received)
    #print(newtask)
    #print("is coroutine function? {!s}".format(asyncio.iscoroutinefunction(ser_task.result()[1].data_received))
    #print("is coroutine? {}".format( asyncio.iscoroutine(ser_task.result()[1].data_received) )
    #print(asyncio.iscoroutinefunction(ser_task.result()[1].data_received))
    
    myhandler = functools.partial(handler,mytasks=[],mycallbacks=[ser_transport.write],ser=ser_protocol)
    #myhandler = functools.partial(handler,mytasks=[ser_task.result()[1].data_received])
    start_server = websockets.serve(myhandler, 'localhost', 8765)
    ws_task = asyncio.ensure_future(start_server)
    asyncio.get_event_loop().run_until_complete(start_server)
    print("ws_task results: {}".format(ws_task.result()))
    ws_serv = ws_task.result()

    #loop = asyncio.get_event_loop()
    #coro = serial.aio.create_serial_connection(loop, serPort, '/dev/arduino',baudrate=38400,timeout=0.2)
    #loop.run_until_complete(coro)
    asyncio.get_event_loop().run_forever()
Example #13
0
def wallet_fetch(path, args):
    early_timestamp = calendar.timegm(args.date)

    print(path)
    print("wallet. Fetching.")
    network = MAINNET

    addresses = [a[:-1] for a in open(os.path.join(path, "watch_addresses")).readlines()]

    keychain = Keychain(addresses)

    sql_db = sqlite3.Connection(os.path.join(path, "wallet.db"))
    persistence = SQLite3Persistence(sql_db)
    wallet = SQLite3Wallet(keychain, persistence, desired_spendable_count=20)

    bcv_json = persistence.get_global("blockchain_view") or "[]"

    blockchain_view = BlockChainView.from_json(bcv_json)

    element_count = len(addresses)
    false_positive_probability = 0.0001

    filter_size = filter_size_required(element_count, false_positive_probability)
    hash_function_count = hash_function_count_required(filter_size, element_count)
    bloom_filter = BloomFilter(filter_size, hash_function_count=hash_function_count, tweak=1)

    print("%d elements; filter size: %d bytes; %d hash functions" % (element_count, filter_size, hash_function_count))

    for a in addresses:
        bloom_filter.add_address(a)

    merkle_block_index_queue = asyncio.Queue()
    host_port_q = None
    USE_LOCAL_HOST = False
    if USE_LOCAL_HOST:
        # use a local host instead of going to DNS
        host_port_q = asyncio.Queue()
        host_port_q.put_nowait(("127.0.0.1", 8333))
    filter_f = lambda idx, h: h.timestamp >= early_timestamp
    spv = SPVClient(
        network, blockchain_view, bloom_filter, merkle_block_index_queue, host_port_q=host_port_q,
        filter_f=filter_f)

    @asyncio.coroutine
    def process_updates(merkle_block_index_queue):
        while True:
            merkle_block, index = yield from merkle_block_index_queue.get()
            wallet._add_block(merkle_block, index, merkle_block.txs)
            bcv_json = blockchain_view.as_json()
            persistence.set_global("blockchain_view", bcv_json)
            if len(merkle_block.txs) > 0:
                print("got block %06d: %s... with %d transactions" % (
                    index, merkle_block.id()[:32], len(merkle_block.txs)))
            if index % 1000 == 0:
                print("at block %06d (%s)" % (index, datetime.datetime.fromtimestamp(merkle_block.timestamp)))
            if merkle_block_index_queue.empty():
                persistence.commit()

    t = asyncio.Task(process_updates(merkle_block_index_queue))
    asyncio.get_event_loop().run_forever()
def test_eof():
    peer = BitcoinPeerProtocol(MAGIC_HEADER)
    pt = PeerTransport(None)
    peer.connection_made(pt)

    COUNT = 0
    @asyncio.coroutine
    def async_listen(next_message):
        count = 0
        try:
            while True:
                name, data = yield from next_message()
                count += 1
        except EOFError:
            pass
        assert count == 2
        nonlocal COUNT
        COUNT += 1

    tasks = [asyncio.Task(async_listen(peer.new_get_next_message_f())) for i in range(50)]

    peer.data_received(VERSION_MSG_BIN)
    peer.data_received(VERACK_MSG_BIN)
    # end of stream
    peer.connection_lost(None)

    # give everyone a chance to run (but no one finishes)
    asyncio.get_event_loop().run_until_complete(asyncio.wait(tasks))

    assert COUNT == 50
Example #15
0
    def test_run(self):

        @asyncio.coroutine
        def aiotest():

            from aiorm import registry
            from aiorm.orm.query import statements as stmt

            driver.DummyCursor.return_many = [[range(3),
                                               range(10, 13)],
                                              ]

            yield from registry.connect('/sample')
            groups = yield from (stmt.Select(sample.Group)
                                     .join(sample.User)
                                     .left_join(sample.UserPreference,
                                                sample.User.id ==
                                                sample.UserPreference.user_id)
                                     .where(Mock()).run()
                                     )
            yield from registry.disconnect('sample')

            groups = [group for group in groups]
            self.assertEqual(len(groups), 2)
            self.assertEqual(groups[0].to_dict(),
                             {'id': 1, 'created_at': 0, 'name': 2})
            self.assertEqual(groups[1].to_dict(),
                             {'id': 11, 'created_at': 10, 'name': 12})

        asyncio.get_event_loop().run_until_complete(aiotest())
Example #16
0
    def test_rfc(self):
        user = "******"
        password = "******"

        smmock = aiosasl.SASLStateMachine(SASLInterfaceMock(
            self,
            [
                ("auth;PLAIN",
                 b"\0tim\0tanstaaftanstaaf",
                 "success",
                 None)
            ]))

        @asyncio.coroutine
        def provide_credentials(*args):
            return user, password

        def run():
            plain = aiosasl.PLAIN(provide_credentials)
            result = yield from plain.authenticate(
                smmock,
                "PLAIN")
            self.assertTrue(result)

        asyncio.get_event_loop().run_until_complete(run())

        smmock.interface.finalize()
Example #17
0
    def test_fail_on_protocol_violation(self):
        user = "******"
        password = "******"

        smmock = aiosasl.SASLStateMachine(SASLInterfaceMock(
            self,
            [
                ("auth;PLAIN",
                 b"\0tim\0tanstaaftanstaaf",
                 "challenge",
                 b"foo")
            ]))

        @asyncio.coroutine
        def provide_credentials(*args):
            return user, password

        def run():
            plain = aiosasl.PLAIN(provide_credentials)
            yield from plain.authenticate(
                smmock,
                "PLAIN")

        with self.assertRaisesRegexp(aiosasl.SASLFailure,
                                     "protocol violation") as ctx:
            asyncio.get_event_loop().run_until_complete(run())

        self.assertEqual(
            None,
            ctx.exception.opaque_error
        )

        smmock.interface.finalize()
Example #18
0
 def __init__(self, max_loops=20):
     self.log = []
     self.max_loops = max_loops
     self._finished = asyncio.Event()
     self._next = asyncio.Event()
     self.wait = self._finished.wait
     asyncio.get_event_loop().call_later(5, self._watchdog)
Example #19
0
async def service_callback():
    async with websockets.connect('ws://localhost:9090') as websocket:

        # advertise the message/topic
        await websocket.send("{ \"op\": \"advertise\",\
                          \"type\": \"vision_service/msg/NewFacialFeatures\",\
                          \"topic\": \"/roboy/cognition/vision/NewFacialFeatures\"\
                        }")

        i = 1  # counter for the service request IDs

        while True:

                    float64[128] ff = 0

                    message["values"] = ff
                    message["op"] = "service_response"
                    message["id"] = "message:/roboy/cognition/vision/coordinates:" + str(i)
                    message["service"] = "/roboy/cognition/vision/coordinates"
                    i += 1

                    await websocket.send(json.dumps(message))

                except Exception as e:
                    logging.exception("Oopsie! Got an exception in vision/NewFacialFeatures")

        logging.basicConfig(level=logging.INFO)
        asyncio.get_event_loop().run_until_complete(service_callback())
Example #20
0
def connect(host='localhost', port=5672, login='******', password='******',
            virtualhost='/', ssl=False, login_method='AMQPLAIN', insist=False,
            protocol_factory=AmqpProtocol, **kwargs):
    """Convenient method to connect to an AMQP broker

        @host:          the host to connect to
        @port:          broker port
        @login:         login
        @password:      password
        @virtualhost:   AMQP virtualhost to use for this connection
        @login_method:  AMQP auth method
        @insist:        Insist on connecting to a server

        @kwargs:        Arguments to be given to the protocol_factory instance

        Returns:        a tuple (transport, protocol) of an AmqpProtocol instance
    """
    if kwargs:
        transport, protocol = yield from asyncio.get_event_loop().create_connection(
        lambda: protocol_factory(**kwargs), host, port)

    else:
        transport, protocol = yield from asyncio.get_event_loop().create_connection(
        protocol_factory, host, port)

    yield from protocol.start_connection(host, port, login, password, virtualhost, ssl=ssl,
        login_method=login_method, insist=insist)

    return (transport, protocol)
Example #21
0
 def shutdown(self):
     for t in [self.new_task] + self.backfillers:
         t.cancel()
         # this is kludgy, but make sure the task runs a tick to
         # process its cancellation
         asyncio.get_event_loop().run_until_complete(t)
     super().shutdown()
def main():
    # Tell prompt_toolkit to use asyncio.
    use_asyncio_event_loop()

    # Run application async.
    asyncio.get_event_loop().run_until_complete(
        application.run_async().to_asyncio_future())
Example #23
0
def main():
    loop = asyncio.get_event_loop()
    # loop.set_debug(True)
    main = asyncio.ensure_future(async_main())
    loop.add_signal_handler(signal.SIGHUP, list_all_tasks)
    loop.add_signal_handler(signal.SIGINT, main.cancel)

    try:
        loop.run_until_complete(main)
    except:
        log.exception('Main failed')
        pass
    print("MAIN COMPLETE")

    def check_task(task):
        return task.done() and not task.cancelled() and not task.exception()

    tasks = asyncio.Task.all_tasks(asyncio.get_event_loop())
    retrieved_tasks = set()
    while any((not check_task(task) for task in tasks)):
        task_list = FutureList((task for task in tasks if not check_task(task)))
        log.info("Pending Loop. Has %d items", len(task_list))
        for task in task_list.as_completed():
            try:
                loop.run_until_complete(task)
            except:
                log.exception('Task raised exception %r', task)
                pass
        retrieved_tasks = retrieved_tasks | tasks
        tasks = asyncio.Task.all_tasks(asyncio.get_event_loop()) - retrieved_tasks
        log.info("Pending Loop. Has %d new items", len([task for task in tasks if not check_task(task)]))


    loop.close()
Example #24
0
 def __init__(self, db):
     self._db = db
     self._db.execute('create table if not exists objects (hash unique, brink, expires, data)')
     self.on_add_object = []
     self.on_remove_object = []
     asyncio.get_event_loop().call_soon(self._cleanup)
     self.on_stats_changed = []
Example #25
0
def testWebsocketTransport():
	@asyncio.coroutine
	def serverRoutine(websocket, path):
		print("new connection")
		receiver = TransportGateway(enc, WebsocketTransport(websocket), debugMode = True)
		receiver.exposeObjectImplementation(TestImplementation)
		yield from asyncio.sleep(0.5)
		a = yield from  (receiver << Test.requestNew(1))
		print(a)
		b = yield from a.echo("asd")
		print(b)
		b = yield from a.echo("asd")
		print(b)
		b = yield from a.echo("asd")
		print(b)

		#yield from receiver.serverMode()
		print("connection closed")


	@asyncio.coroutine
	def clientRoutine():
		websocket = yield from websockets.connect('ws://localhost:8765/')
		return TransportGateway(enc, WebsocketTransport(websocket), debugMode = True)
		

	start_server = websockets.serve(serverRoutine, 'localhost', 8765)
	asyncio.get_event_loop().run_until_complete(start_server)
	asyncio.get_event_loop().run_forever()
Example #26
0
    def test_hadle_request_index(self):
        rand = mock.Mock()
        rand.return_value = [x for x in range(10)]

        with mock.patch('aiohttp.Response.write', self.m, create=True):
            with mock.patch('aiohttp.Response.write_eof', self.m_eof, create=True):
                message = mock.Mock()
                message.headers = []
                message.path = '/event'
                message.version = (1, 1)

                @asyncio.coroutine
                def foobar():
                    return b'{"method":"GET","path":"/index.html"}'

                payload = mock.Mock()
                payload.read = foobar

                asyncio.get_event_loop().run_until_complete(self.handler.handle_request(message, payload))

                content = b''.join([c[1][0] for c in list(self.m.mock_calls)]).decode('utf-8')
                content = json.loads(content)

                assert_content = dict(
                    version=1,
                    response=dict(message=dict(detection=dict(name='index', order=1)))
                )

                self.assertDictEqual(content, assert_content)
Example #27
0
def test_get_date_address_tuples():
    peer1, peer2 = create_peers()

    DA_TUPLES = [(1392770000+i, PeerAddress(1, "127.0.0.%d" % i, 8000+i)) for i in range(100)]

    from pycoinnet.message import pack_from_data
    msg_data = pack_from_data("addr", date_address_tuples=DA_TUPLES)

    @asyncio.coroutine
    def run_peer1():
        yield from standards.initial_handshake(peer1, VERSION_MSG)
        next_message = peer1.new_get_next_message_f()
        name, data = yield from next_message()
        peer1.send_msg("addr", date_address_tuples=DA_TUPLES)
        return name, data

    @asyncio.coroutine
    def run_peer2():
        yield from standards.initial_handshake(peer2, VERSION_MSG_2)
        date_address_tuples = yield from standards.get_date_address_tuples(peer2)
        return DA_TUPLES

    f1 = asyncio.Task(run_peer1())
    f2 = asyncio.Task(run_peer2())

    asyncio.get_event_loop().run_until_complete(asyncio.wait([f1, f2]))

    name, data = f1.result()
    assert name == 'getaddr'
    assert data == {}

    date_address_tuples = f2.result()
    assert date_address_tuples == DA_TUPLES
Example #28
0
 def commit_msg(self, seqno):
     # This will raise IndexError if we attempt to commit when
     # nothing is in flight
     txn_seqno, write_future, offset, size \
         = self._txns_in_flight.popleft()
     while txn_seqno != seqno:
         # Can't commit out of order; wait our turn
         with (yield from self._txn_committed):
             yield from self._txn_committed.wait()
         txn_seqno, write_future, offset, size \
             = self._txns_in_flight.popleft()
     assert txn_seqno == seqno
     # Wait for our local write to be done; raise exception if
     # there was one
     #yield from write_future
     # Write to the index file; this marks it as committed locally.
     if USE_EXECUTOR:
         asyncio.get_event_loop().run_in_executor(
             self._executor,
             self.idxfile.write,
             IdxEntry.pack(seqno, offset, size))
     elif DO_WRITES:
         self.idxfile.write(
             IdxEntry.pack(seqno, offset, size))
     with (yield from self._txn_committed):
         self._txn_committed.notify_all()
     #self.updated_cb()
     return
Example #29
0
    def test_handle_request_rfi(self):
        rand = mock.Mock()
        rand.return_value = [x for x in range(10)]
        self.handler.base_handler.emulators['rfi'].handle = mock.Mock(return_value=(lambda: (yield None))())

        with mock.patch('aiohttp.Response.write', self.m, create=True):
            with mock.patch('aiohttp.Response.write_eof', self.m_eof, create=True):
                message = mock.Mock()
                message.headers = []
                message.path = '/event'
                message.version = (1, 1)

                @asyncio.coroutine
                def foobar():
                    return b'{"method":"GET","path":"/vuln_page.php?file=http://attacker_site/malicous_page"}'

                payload = mock.Mock()
                payload.read = foobar

                asyncio.get_event_loop().run_until_complete(self.handler.handle_request(message, payload))

                content = b''.join([c[1][0] for c in list(self.m.mock_calls)]).decode('utf-8')
                content = json.loads(content)

                assert_content = dict(
                    version=1,
                    response=dict(message=dict(detection=dict(name='rfi', order=2, payload=None)))
                )

                self.assertDictEqual(content, assert_content)
Example #30
0
 def __init__(self, db):
     self._db = db
     self._db.execute('create table if not exists worker (obj, trials, extra, timestamp)')
     self._executor = concurrent.futures.ProcessPoolExecutor()
     for obj, trials, extra, timestamp in self._db.execute('select * from worker'):
         asyncio.get_event_loop().create_task(self._run(packet.Object.from_bytes(obj), trials, extra, timestamp))
     self.on_object_done = []
def test_1():
    loop = asyncio.get_event_loop()
    assert not loop.is_closed()
Example #32
0
 def __init__(self):
     self.event_loop = asyncio.get_event_loop()
     self.broadcast_tasks = dict()
     # parallel dict to broadcast_tasks that tracks stats
     self.local_hostname = get_local_host()
     self.stats_mgr = BroadcastWebsocketStatsManager(self.event_loop, self.local_hostname)
Example #33
0
    async def startup(self, sockets=None):
        await self.lifespan.startup()
        if self.lifespan.should_exit:
            self.should_exit = True
            return

        config = self.config

        create_protocol = functools.partial(config.http_protocol_class,
                                            config=config,
                                            server_state=self.server_state)

        loop = asyncio.get_event_loop()

        if sockets is not None:
            # Explicitly passed a list of open sockets.
            # We use this when the server is run from a Gunicorn worker.

            def _share_socket(sock: socket) -> socket:
                # Windows requires the socket be explicitly shared across
                # multiple workers (processes).
                from socket import fromshare  # type: ignore

                sock_data = sock.share(os.getpid())  # type: ignore
                return fromshare(sock_data)

            self.servers = []
            for sock in sockets:
                if config.workers > 1 and platform.system() == "Windows":
                    sock = _share_socket(sock)
                server = await loop.create_server(create_protocol,
                                                  sock=sock,
                                                  ssl=config.ssl,
                                                  backlog=config.backlog)
                self.servers.append(server)

        elif config.fd is not None:
            # Use an existing socket, from a file descriptor.
            sock = socket.fromfd(config.fd, socket.AF_UNIX, socket.SOCK_STREAM)
            server = await loop.create_server(create_protocol,
                                              sock=sock,
                                              ssl=config.ssl,
                                              backlog=config.backlog)
            message = "Uvicorn running on socket %s (Press CTRL+C to quit)"
            logger.info(message % str(sock.getsockname()))
            self.servers = [server]

        elif config.uds is not None:
            # Create a socket using UNIX domain socket.
            uds_perms = 0o666
            if os.path.exists(config.uds):
                uds_perms = os.stat(config.uds).st_mode
            server = await loop.create_unix_server(create_protocol,
                                                   path=config.uds,
                                                   ssl=config.ssl,
                                                   backlog=config.backlog)
            os.chmod(config.uds, uds_perms)
            message = "Uvicorn running on unix socket %s (Press CTRL+C to quit)"
            logger.info(message % config.uds)
            self.servers = [server]

        else:
            # Standard case. Create a socket from a host/port pair.
            addr_format = "%s://%s:%d"
            if config.host and ":" in config.host:
                # It's an IPv6 address.
                addr_format = "%s://[%s]:%d"

            try:
                server = await loop.create_server(
                    create_protocol,
                    host=config.host,
                    port=config.port,
                    ssl=config.ssl,
                    backlog=config.backlog,
                )
            except OSError as exc:
                logger.error(exc)
                await self.lifespan.shutdown()
                sys.exit(1)
            port = config.port
            if port == 0:
                port = server.sockets[0].getsockname()[1]
            protocol_name = "https" if config.ssl else "http"
            message = f"Uvicorn running on {addr_format} (Press CTRL+C to quit)"
            color_message = ("Uvicorn running on " +
                             click.style(addr_format, bold=True) +
                             " (Press CTRL+C to quit)")
            logger.info(
                message,
                protocol_name,
                config.host,
                port,
                extra={"color_message": color_message},
            )
            self.servers = [server]

        self.started = True
Example #34
0
 def run(self, sockets=None):
     self.config.setup_event_loop()
     loop = asyncio.get_event_loop()
     loop.run_until_complete(self.serve(sockets=sockets))
Example #35
0
        await asyncio.sleep(1.0)

        for brightness in range(256):
            print(f"Set Brightness to {brightness}...")
            await client.write_gatt_char(
                BRIGHTNESS_CHARACTERISTIC,
                bytearray(
                    [
                        brightness,
                    ]
                ),
            )
            await asyncio.sleep(0.2)

        print(f"Set Brightness to {40}...")
        await client.write_gatt_char(
            BRIGHTNESS_CHARACTERISTIC,
            bytearray(
                [
                    40,
                ]
            ),
        )


if __name__ == "__main__":
    address = "EB:F0:49:21:95:4F"
    loop = asyncio.get_event_loop()
    loop.set_debug(True)
    loop.run_until_complete(run(address, True))
            LATITUDE,
            LONGITUDE,
            altitude=ALTITUDE,
            session=session,
            use_async=True,
        )

        start = time.time()

        try:
            # Get current UV info:
            _LOGGER.info("CURRENT UV DATA:")
            _LOGGER.info(await client.uv_index())

            # Get forecasted UV info:
            _LOGGER.info("FORECASTED UV DATA:")
            _LOGGER.info(await client.uv_forecast())

            # Get UV protection window:
            _LOGGER.info("UV PROTECTION WINDOW:")
            _LOGGER.info(await client.uv_protection_window())
        except OpenUvError as err:
            _LOGGER.info(err)

    end = time.time()

    _LOGGER.info("Execution time: %s seconds", end - start)


asyncio.get_event_loop().run_until_complete(main())
Example #37
0
def main():
    asyncio.get_event_loop().run_until_complete(go())
    print("DONE")
Example #38
0

async def unregister(websocket):
    USERS.remove(websocket)
    await notify_users()


async def counter(websocket, path):
    # register(websocket) sends user_event() to websocket
    await register(websocket)
    try:
        await websocket.send(state_event())
        async for message in websocket:
            data = json.loads(message)
            if data["action"] == "minus":
                STATE["value"] -= 1
                await notify_state()
            elif data["action"] == "plus":
                STATE["value"] += 1
                await notify_state()
            else:
                logging.error("unsupported event: {}", data)
    finally:
        await unregister(websocket)


start_server = websockets.serve(counter, "localhost", 6789)

asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()
Example #39
0
def start_parse():
    data = get_from_rss()
    asyncio.get_event_loop().run_until_complete(load_to_db(data))
    return True
Example #40
0
 def wrapper(*args, **kwargs):
     return asyncio.get_event_loop().run_until_complete(f(*args, **kwargs))
Example #41
0
def get_event_loop():
    return asyncio.get_event_loop()
Example #42
0
File: case.py Project: yinjiayi/jd4
        open_output = partial(
            zip_file.open, canonical_dict[path.join('output', output.lower())])
        yield LegacyCase(open_input, open_output, float(time_sec_str), mem_kb,
                         int(score_str))


if __name__ == '__main__':

    async def main():
        try_init_cgroup()
        sandbox = await create_sandbox()
        gcc = Compiler('/usr/bin/gcc',
                       ['gcc', '-std=c99', '-o', '/out/foo', '/in/foo.c'],
                       'foo.c', 'foo', ['foo'])
        await gcc.prepare(
            sandbox, b"""#include <stdio.h>
int main(void) {
    int a, b;
    scanf("%d%d", &a, &b);
    printf("%d\\n", a + b);
}""")
        package, _ = await gcc.build(sandbox)
        for case in read_legacy_cases('examples/1000.zip'):
            logger.info(await case.judge(sandbox, package))
        for i in range(10):
            logger.info(await
                        APlusBCase(randint(0, 32767),
                                   randint(0, 32767)).judge(sandbox, package))

    get_event_loop().run_until_complete(main())
Example #43
0
def serve(
    files,
    immutable,
    host,
    port,
    reload,
    cors,
    sqlite_extensions,
    inspect_file,
    metadata,
    template_dir,
    plugins_dir,
    static,
    memory,
    config,
    secret,
    root,
    get,
    version_note,
    help_config,
    pdb,
    open_browser,
    return_instance=False,
):
    """Serve up specified SQLite database files with a web UI"""
    if help_config:
        formatter = formatting.HelpFormatter()
        with formatter.section("Config options"):
            formatter.write_dl(
                [
                    (option.name, "{} (default={})".format(option.help, option.default))
                    for option in CONFIG_OPTIONS
                ]
            )
        click.echo(formatter.getvalue())
        sys.exit(0)
    if reload:
        import hupper

        reloader = hupper.start_reloader("datasette.cli.serve")
        if immutable:
            reloader.watch_files(immutable)
        if metadata:
            reloader.watch_files([metadata.name])

    inspect_data = None
    if inspect_file:
        inspect_data = json.load(open(inspect_file))

    metadata_data = None
    if metadata:
        metadata_data = parse_metadata(metadata.read())

    kwargs = dict(
        immutables=immutable,
        cache_headers=not reload,
        cors=cors,
        inspect_data=inspect_data,
        metadata=metadata_data,
        sqlite_extensions=sqlite_extensions,
        template_dir=template_dir,
        plugins_dir=plugins_dir,
        static_mounts=static,
        config=dict(config),
        memory=memory,
        secret=secret,
        version_note=version_note,
        pdb=pdb,
    )

    # if files is a single directory, use that as config_dir=
    if 1 == len(files) and os.path.isdir(files[0]):
        kwargs["config_dir"] = pathlib.Path(files[0])
        files = []

    try:
        ds = Datasette(files, **kwargs)
    except SpatialiteNotFound:
        raise click.ClickException("Could not find SpatiaLite extension")

    if return_instance:
        # Private utility mechanism for writing unit tests
        return ds

    # Run the "startup" plugin hooks
    asyncio.get_event_loop().run_until_complete(ds.invoke_startup())

    # Run async sanity checks - but only if we're not under pytest
    asyncio.get_event_loop().run_until_complete(check_databases(ds))

    if get:
        client = TestClient(ds)
        response = client.get(get)
        click.echo(response.text)
        exit_code = 0 if response.status == 200 else 1
        sys.exit(exit_code)
        return

    # Start the server
    url = None
    if root:
        url = "http://{}:{}{}?token={}".format(
            host, port, ds.urls.path("-/auth-token"), ds._root_token
        )
        print(url)
    if open_browser:
        if url is None:
            # Figure out most convenient URL - to table, database or homepage
            path = asyncio.get_event_loop().run_until_complete(
                initial_path_for_datasette(ds)
            )
            url = "http://{}:{}{}".format(host, port, path)
        webbrowser.open(url)
    uvicorn.run(
        ds.app(), host=host, port=port, log_level="info", lifespan="on", workers=1
    )
Example #44
0
async def _(event):
    if event.fwd_from:
        return
    event = mone = await edit_or_reply(event ,"Processing ...")
    if not os.path.isdir(Config.TMP_DOWNLOAD_DIRECTORY):
        os.makedirs(Config.TMP_DOWNLOAD_DIRECTORY)
    if event.reply_to_msg_id:
        start = datetime.now()
        reply_message = await event.get_reply_message()
        try:
            c_time = time.time()
            downloaded_file_name = await borg.download_media(
                reply_message,
                Config.TMP_DOWNLOAD_DIRECTORY,
                progress_callback=lambda d, t: asyncio.get_event_loop().create_task(
                    progress(d, t, mone, c_time, "trying to download")
                )
            )
        except Exception as e:  # pylint:disable=C0103,W0703
            await mone.edit(str(e))
        else:
            end = datetime.now()
            ms = (end - start).seconds
            await mone.edit("Stored the rar to `{}` in {} seconds.".format(downloaded_file_name, ms))
        patoolib.extract_archive(downloaded_file_name, outdir=extracted)
        filename = sorted(get_lst_of_files(extracted, []))
        #filename = filename + "/"
        await event.edit("Unraring now")
        # r=root, d=directories, f = files
        for single_file in filename:
            if os.path.exists(single_file):
                # https://stackoverflow.com/a/678242/4723940
                caption_rts = os.path.basename(single_file)
                force_document = True
                supports_streaming = False
                document_attributes = []
                if single_file.endswith((".mp4", ".mp3", ".flac", ".webm")):
                    metadata = extractMetadata(createParser(single_file))
                    duration = 0
                    width = 0
                    height = 0
                    if metadata.has("duration"):
                        duration = metadata.get('duration').seconds
                    if os.path.exists(thumb_image_path):
                        metadata = extractMetadata(createParser(thumb_image_path))
                        if metadata.has("width"):
                            width = metadata.get("width")
                        if metadata.has("height"):
                            height = metadata.get("height")
                    document_attributes = [
                        DocumentAttributeVideo(
                            duration=duration,
                            w=width,
                            h=height,
                            round_message=False,
                            supports_streaming=True
                        )
                    ]
                try:
                    await borg.send_file(
                        event.chat_id,
                        single_file,
                        caption=f"UnRarred `{caption_rts}`",
                        force_document=force_document,
                        supports_streaming=supports_streaming,
                        allow_cache=False,
                        reply_to=event.message.id,
                        attributes=document_attributes,
                        progress_callback=lambda d, t: asyncio.get_event_loop().create_task(
                             progress(d, t, event, c_time, "trying to upload")
                         )
                    )
                except Exception as e:
                    await borg.send_message(
                        event.chat_id,
                        "{} caused `{}`".format(caption_rts, str(e)),
                        reply_to=event.message.id
                    )
                    # some media were having some issues
                    continue
                os.remove(single_file)
        os.remove(downloaded_file_name)
        await event.edit("DONE!!!")
        await asyncio.sleep(5)
        await event.delete()
Example #45
0
 def loop(self):
     if self._loop is None:
         self._loop = asyncio.get_event_loop()
     return self._loop
Example #46
0
 def __init__(self, seq=(), *, after=1, callback=None, loop=None):
     super().__init__(seq)
     self.loop = loop or asyncio.get_event_loop()
     self.after = after
     self.callback = callback
     self._timer = None
Example #47
0
 def __init__(self, loop=None):
     self.loop = loop or aio.get_event_loop()
     self.q = aio.Queue(loop=self.loop)
     self.loop.add_reader(sys.stdin, self.got_input)
def test():
    test_prep()
    loop = asyncio.get_event_loop()
    loop.run_until_complete(do())
    loop.close()
    final_result()
Example #49
0
from asyncio import coroutine, get_event_loop


@coroutine
def coro():
    print('42')


print(type(coro))
print(type(coro()))

loop = get_event_loop()
loop.run_until_complete(coro())
Example #50
0
def run_webrtc_service():
    logging.basicConfig()
    loop = asyncio.get_event_loop()
    loop.create_task(_start_async_server())
    loop.run_forever()
Example #51
0
    global time
    connect_info = {
        'commandType': 'aiEnterRoom',
        'roomId': 101550,
        'accessKey': sys.argv[1],
        'employeeId': int(sys.argv[2])
    }
    print(json.dumps(connect_info))
    async with websockets.connect(uri) as websocket:
        await websocket.send(json.dumps(connect_info))
        while True:
            msg = await websocket.recv()
            msg = json.loads(msg)

            await websocket.send(json.dumps({'commandType': 'fire'}))

            if time % random.randint(1, 20) == 4:
                await websocket.send(
                    json.dumps({
                        'commandType': 'direction',
                        'angle': random.randint(0, 360)
                    }))
            else:
                pass

            time += 1
            print(msg)


asyncio.get_event_loop().run_until_complete(
    hello('wss://tank-match.taobao.com/ai'))
Example #52
0
 def __init__(self, loop=None):
     if loop is None:
         loop = get_event_loop()
     self.loop = loop
     self.futures = []
     self.return_promise = False
Example #53
0
def main():
    loop = asyncio.get_event_loop()
    loop.add_signal_handler(signal.SIGTERM, shutdown)
    tasks = asyncio.ensure_future(tweet())
    loop.run_until_complete(asyncio.gather(tasks))
Example #54
0
def run_coro(coro):
    import asyncio
    return asyncio.get_event_loop().run_until_complete(coro)
Example #55
0
async def download(target_file):
    """ For .download command, download files to the userbot's server. """
    await target_file.edit("Processando ...")
    input_str = target_file.pattern_match.group(1)
    if not os.path.isdir(TEMP_DOWNLOAD_DIRECTORY):
        os.makedirs(TEMP_DOWNLOAD_DIRECTORY)
    if "|" in input_str:
        url, file_name = input_str.split("|")
        url = url.strip()
        # https://stackoverflow.com/a/761825/4723940
        file_name = file_name.strip()
        head, tail = os.path.split(file_name)
        if head:
            if not os.path.isdir(os.path.join(TEMP_DOWNLOAD_DIRECTORY, head)):
                os.makedirs(os.path.join(TEMP_DOWNLOAD_DIRECTORY, head))
                file_name = os.path.join(head, tail)
        downloaded_file_name = TEMP_DOWNLOAD_DIRECTORY + "/" + file_name
        downloader = SmartDL(url, downloaded_file_name, progress_bar=False)
        downloader.start(blocking=False)
        c_time = time.time()
        display_message = None
        while not downloader.isFinished():
            status = downloader.get_status().capitalize()
            total_length = downloader.filesize if downloader.filesize else None
            downloaded = downloader.get_dl_size()
            now = time.time()
            diff = now - c_time
            percentage = downloader.get_progress() * 100
            speed = downloader.get_speed()
            progress_str = "[{0}{1}] `{2}%`".format(
                "".join(["■" for i in range(math.floor(percentage / 10))]),
                "".join(["▨"
                         for i in range(10 - math.floor(percentage / 10))]),
                round(percentage, 2),
            )
            estimated_total_time = downloader.get_eta(human=True)
            try:
                current_message = (
                    f"`Nome` : `{file_name}`\n"
                    "Status"
                    f"\n**{status}**... | {progress_str}"
                    f"\n{humanbytes(downloaded)} of {humanbytes(total_length)}"
                    f" @ {speed}"
                    f"\n`Tempo Estimado` -> {estimated_total_time}")

                if round(diff %
                         10.00) == 0 and current_message != display_message:
                    await target_file.edit(current_message)
                    display_message = current_message
            except Exception as e:
                LOGS.info(str(e))
        if downloader.isSuccessful():
            await target_file.edit(
                "Baixado para `{}` com sucesso !!".format(downloaded_file_name)
            )
        else:
            await target_file.edit("URL incorreto\n{}".format(url))
    elif target_file.reply_to_msg_id:
        try:
            c_time = time.time()
            downloaded_file_name = await target_file.client.download_media(
                await target_file.get_reply_message(),
                TEMP_DOWNLOAD_DIRECTORY,
                progress_callback=lambda d, t: asyncio.get_event_loop().
                create_task(progress(d, t, target_file, c_time, "[DOWNLOAD]")),
            )
        except Exception as e:  # pylint:disable=C0103,W0703
            await target_file.edit(str(e))
        else:
            await target_file.edit(
                "Baixado para `{}` com sucesso !!".format(downloaded_file_name)
            )
    else:
        await target_file.edit(
            "Responda a uma mensagem para fazer o download no meu servidor local."
        )
Example #56
0
 async def _start_c2_channel(self, contact):
     loop = asyncio.get_event_loop()
     loop.create_task(contact.start())
     self.contacts.append(contact)
Example #57
0
async def uploadir(udir_event):
    """ For .uploadir command, allows you to upload everything from a folder in the server"""
    input_str = udir_event.pattern_match.group(1)
    if os.path.exists(input_str):
        await udir_event.edit("Processando ...")
        lst_of_files = []
        for r, d, f in os.walk(input_str):
            for file in f:
                lst_of_files.append(os.path.join(r, file))
            for file in d:
                lst_of_files.append(os.path.join(r, file))
        LOGS.info(lst_of_files)
        uploaded = 0
        await udir_event.edit(
            "Encontrados {} arquivos. O upload começará em breve. Por favor, espere!"
            .format(len(lst_of_files)))
        for single_file in lst_of_files:
            if os.path.exists(single_file):
                # https://stackoverflow.com/a/678242/4723940
                caption_rts = os.path.basename(single_file)
                c_time = time.time()
                if not caption_rts.lower().endswith(".mp4"):
                    await udir_event.client.send_file(
                        udir_event.chat_id,
                        single_file,
                        caption=caption_rts,
                        force_document=False,
                        allow_cache=False,
                        reply_to=udir_event.message.id,
                        progress_callback=lambda d, t: asyncio.get_event_loop(
                        ).create_task(
                            progress(d, t, udir_event, c_time, "[UPLOAD]",
                                     single_file)),
                    )
                else:
                    thumb_image = os.path.join(input_str, "thumb.jpg")
                    c_time = time.time()
                    metadata = extractMetadata(createParser(single_file))
                    duration = 0
                    width = 0
                    height = 0
                    if metadata.has("duration"):
                        duration = metadata.get("duration").seconds
                    if metadata.has("width"):
                        width = metadata.get("width")
                    if metadata.has("height"):
                        height = metadata.get("height")
                    await udir_event.client.send_file(
                        udir_event.chat_id,
                        single_file,
                        caption=caption_rts,
                        thumb=thumb_image,
                        force_document=False,
                        allow_cache=False,
                        reply_to=udir_event.message.id,
                        attributes=[
                            DocumentAttributeVideo(
                                duration=duration,
                                w=width,
                                h=height,
                                round_message=False,
                                supports_streaming=True,
                            )
                        ],
                        progress_callback=lambda d, t: asyncio.get_event_loop(
                        ).create_task(
                            progress(d, t, udir_event, c_time, "[UPLOAD]",
                                     single_file)),
                    )
                os.remove(single_file)
                uploaded = uploaded + 1
        await udir_event.edit(
            "Enviados {} arquivos com sucesso !!".format(uploaded))
    else:
        await udir_event.edit("404: Directory Not Found")
Example #58
0
 def __init__(self, config={}):
     super(Exchange, self).__init__(config)
     self.asyncio_loop = self.asyncio_loop or asyncio.get_event_loop()
     self.aiohttp_session = self.aiohttp_session or aiohttp.ClientSession(loop=self.asyncio_loop)
     self.init_rest_rate_limiter()
 def start(self):
     loop = asyncio.get_event_loop()
     self.registerExitListener(lambda reason: loop.call_later(1.0, self.stop))
     AdvancedStdio(self)
Example #60
0
async def uploadas(uas_event):
    """ For .uploadas command, allows you to specify some arguments for upload. """
    await uas_event.edit("Processando ...")
    type_of_upload = uas_event.pattern_match.group(1)
    supports_streaming = False
    round_message = False
    spam_big_messages = False
    if type_of_upload == "stream":
        supports_streaming = True
    if type_of_upload == "vn":
        round_message = True
    if type_of_upload == "all":
        spam_big_messages = True
    input_str = uas_event.pattern_match.group(2)
    thumb = None
    file_name = None
    if "|" in input_str:
        file_name, thumb = input_str.split("|")
        file_name = file_name.strip()
        thumb = thumb.strip()
    else:
        file_name = input_str
        thumb_path = "a_random_f_file_name" + ".jpg"
        thumb = get_video_thumb(file_name, output=thumb_path)
    if os.path.exists(file_name):
        metadata = extractMetadata(createParser(file_name))
        duration = 0
        width = 0
        height = 0
        if metadata.has("duration"):
            duration = metadata.get("duration").seconds
        if metadata.has("width"):
            width = metadata.get("width")
        if metadata.has("height"):
            height = metadata.get("height")
        try:
            if supports_streaming:
                c_time = time.time()
                await uas_event.client.send_file(
                    uas_event.chat_id,
                    file_name,
                    thumb=thumb,
                    caption=input_str,
                    force_document=False,
                    allow_cache=False,
                    reply_to=uas_event.message.id,
                    attributes=[
                        DocumentAttributeVideo(
                            duration=duration,
                            w=width,
                            h=height,
                            round_message=False,
                            supports_streaming=True,
                        )
                    ],
                    progress_callback=lambda d, t: asyncio.get_event_loop().
                    create_task(
                        progress(d, t, uas_event, c_time, "[UPLOAD]", file_name
                                 )),
                )
            elif round_message:
                c_time = time.time()
                await uas_event.client.send_file(
                    uas_event.chat_id,
                    file_name,
                    thumb=thumb,
                    allow_cache=False,
                    reply_to=uas_event.message.id,
                    video_note=True,
                    attributes=[
                        DocumentAttributeVideo(
                            duration=0,
                            w=1,
                            h=1,
                            round_message=True,
                            supports_streaming=True,
                        )
                    ],
                    progress_callback=lambda d, t: asyncio.get_event_loop().
                    create_task(
                        progress(d, t, uas_event, c_time, "[UPLOAD]", file_name
                                 )),
                )
            elif spam_big_messages:
                return await uas_event.edit("TBD: Not (yet) Implemented")
            os.remove(thumb)
            await uas_event.edit("Uploaded com sucesso !!")
        except FileNotFoundError as err:
            await uas_event.edit(str(err))
    else:
        await uas_event.edit("404: File Not Found")