Python trio.run() Examples
The following are 30
code examples of trio.run().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
trio
, or try the search function
.
Example #1
Source File: util.py From douyin_downloader with GNU Lesser General Public License v3.0 | 6 votes |
def get_sign(self, token, query): '''使用拼装参数签名 post https://api.appsign.vip:2688/sign --> { "token":"TOKEN", "query":"通过参数生成的加签字符串" } >>> data, res = trio.run(SignUtil().get_sign, 'aaa', {"aaa":"aaa"}) >>> print(res) {'success': False, 'error': 'token is error'} ''' assert isinstance(query, dict) url = f"{_API}/sign" resp = await self.s.post(url, json={"token": token, "query": params2str(query)}, verify=False) logging.debug(f"post response from {url} is {resp} with body: {trim(resp.text)}") return resp.json().get('data', {}), resp.json()
Example #2
Source File: __main__.py From burp-ui with BSD 3-Clause "New" or "Revised" License | 6 votes |
def monitor(options=None): import trio from burpui_monitor.engines.monitor import MonitorPool from burpui_monitor.utils import lookup_file if not options: options = parse_args(name='bui-monitor') conf = ['buimonitor.cfg', 'buimonitor.sample.cfg'] if options.config: conf = lookup_file(options.config, guess=False) else: conf = lookup_file(conf) check_config(conf) monitor = MonitorPool(conf, options.log, options.logfile) trio.run(monitor.run)
Example #3
Source File: parallel.py From burp-ui with BSD 3-Clause "New" or "Revised" License | 6 votes |
def restore_files(self, name=None, backup=None, files=None, strip=None, archive='zip', password=None, agent=None): return trio.run(self._async_restore_files, name, backup, files, strip, archive, password, agent) # Same as in Burp1 backend # def read_conf_cli(self, agent=None): # def read_conf_srv(self, agent=None): # def store_conf_cli(self, data, agent=None): # def store_conf_srv(self, data, agent=None): # def get_parser_attr(self, attr=None, agent=None): # Make every "Burp" method async
Example #4
Source File: parallel.py From burp-ui with BSD 3-Clause "New" or "Revised" License | 6 votes |
def restore_files(self, name=None, backup=None, files=None, strip=None, archive='zip', password=None, agent=None): return trio.run(self._async_restore_files, name, backup, files, strip, archive, password, agent) # Same as in Burp1 backend # def read_conf_cli(self, agent=None): # def read_conf_srv(self, agent=None): # def store_conf_cli(self, data, agent=None): # def store_conf_srv(self, data, agent=None): # def get_parser_attr(self, attr=None, agent=None): # Make every "Burp" method async
Example #5
Source File: __main__.py From burp-ui with BSD 3-Clause "New" or "Revised" License | 6 votes |
def agent(options=None): import trio from burpui_agent.engines.agent import BUIAgent as Agent from burpui_agent.utils import lookup_file from burpui_agent._compat import patch_json patch_json() if not options: options = parse_args(name='bui-agent') conf = ['buiagent.cfg', 'buiagent.sample.cfg'] if options.config: conf = lookup_file(options.config, guess=False) else: conf = lookup_file(conf) check_config(conf) agent = Agent(conf, options.log, options.logfile) trio.run(agent.run)
Example #6
Source File: test_pipeline.py From msrest-for-python with MIT License | 6 votes |
def test_sans_io_exception(): class BrokenSender(AsyncHTTPSender): async def send(self, request, **config): raise ValueError("Broken") async def __aexit__(self, exc_type, exc_value, traceback): """Raise any exception triggered within the runtime context.""" return None pipeline = AsyncPipeline([SansIOHTTPPolicy()], BrokenSender()) req = ClientRequest('GET', '/') with pytest.raises(ValueError): await pipeline.run(req) class SwapExec(SansIOHTTPPolicy): def on_exception(self, requests, **kwargs): exc_type, exc_value, exc_traceback = sys.exc_info() raise NotImplementedError(exc_value) pipeline = AsyncPipeline([SwapExec()], BrokenSender()) with pytest.raises(NotImplementedError): await pipeline.run(req)
Example #7
Source File: __main__.py From burp-ui with BSD 3-Clause "New" or "Revised" License | 6 votes |
def monitor(options=None): import trio from burpui.engines.monitor import MonitorPool from burpui.utils import lookup_file if not options: options, _ = parse_args(mode=False, name='bui-agent') conf = ['buimonitor.cfg', 'buimonitor.sample.cfg'] if options.config: conf = lookup_file(options.config, guess=False) else: conf = lookup_file(conf) check_config(conf) monitor = MonitorPool(conf, options.log, options.logfile) trio.run(monitor.run)
Example #8
Source File: __main__.py From burp-ui with BSD 3-Clause "New" or "Revised" License | 6 votes |
def agent(options=None): import trio from burpui.engines.agent import BUIAgent as Agent from burpui.utils import lookup_file if not options: options, _ = parse_args(mode=False, name='bui-agent') conf = ['buiagent.cfg', 'buiagent.sample.cfg'] if options.config: conf = lookup_file(options.config, guess=False) else: conf = lookup_file(conf) check_config(conf) agent = Agent(conf, options.log, options.logfile) trio.run(agent.run)
Example #9
Source File: parallel.py From burp-ui with BSD 3-Clause "New" or "Revised" License | 6 votes |
def restore_files(self, name=None, backup=None, files=None, strip=None, archive='zip', password=None, agent=None): return trio.run(self._async_restore_files, name, backup, files, strip, archive, password, agent) # Same as in Burp1 backend # def read_conf_cli(self, agent=None): # def read_conf_srv(self, agent=None): # def store_conf_cli(self, data, agent=None): # def store_conf_srv(self, data, agent=None): # def get_parser_attr(self, attr=None, agent=None): # Make every "Burp" method async
Example #10
Source File: parallel.py From burp-ui with BSD 3-Clause "New" or "Revised" License | 5 votes |
def server_version(self): return trio.run(self.get_server_version)
Example #11
Source File: test_pipeline.py From msrest-for-python with MIT License | 5 votes |
def test_conf_async_trio_requests(): async def do(): conf = Configuration("http://bing.com/") request = ClientRequest("GET", "http://bing.com/") policies = [ UserAgentPolicy("myusergant") ] async with AsyncPipeline(policies, AsyncPipelineRequestsHTTPSender(AsyncTrioRequestsHTTPSender(conf))) as pipeline: return await pipeline.run(request) response = trio.run(do) assert response.http_response.status_code == 200
Example #12
Source File: test_pipeline.py From msrest-for-python with MIT License | 5 votes |
def test_basic_aiohttp(): request = ClientRequest("GET", "http://bing.com") policies = [ UserAgentPolicy("myusergant") ] async with AsyncPipeline(policies) as pipeline: response = await pipeline.run(request) assert pipeline._sender.driver._session.closed assert response.http_response.status_code == 200
Example #13
Source File: test_pipeline.py From msrest-for-python with MIT License | 5 votes |
def test_basic_async_requests(): request = ClientRequest("GET", "http://bing.com") policies = [ UserAgentPolicy("myusergant") ] async with AsyncPipeline(policies, AsyncPipelineRequestsHTTPSender()) as pipeline: response = await pipeline.run(request) assert response.http_response.status_code == 200
Example #14
Source File: parallel.py From burp-ui with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_counters(self, name=None, agent=None): """See :func:`burpui.misc.backend.interface.BUIbackend.get_counters`""" return trio.run(self._async_get_counters, name)
Example #15
Source File: test_pipeline.py From msrest-for-python with MIT License | 5 votes |
def test_conf_async_requests(): conf = Configuration("http://bing.com/") request = ClientRequest("GET", "http://bing.com/") policies = [ UserAgentPolicy("myusergant") ] async with AsyncPipeline(policies, AsyncPipelineRequestsHTTPSender(AsyncRequestsHTTPSender(conf))) as pipeline: response = await pipeline.run(request) assert response.http_response.status_code == 200
Example #16
Source File: parallel.py From burp-ui with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_clients_report(self, clients, agent=None): """See :func:`burpui.misc.backend.interface.BUIbackend.get_clients_report`""" return trio.run(self._async_get_clients_report, clients)
Example #17
Source File: parallel.py From burp-ui with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_client(self, name=None, agent=None): """See :func:`burpui.misc.backend.interface.BUIbackend.get_client`""" return trio.run(self._async_get_client, name)
Example #18
Source File: parallel.py From burp-ui with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _parse_backup_log(self, number, client): """The :func:`burpui.misc.backend.burp2.Burp._parse_backup_log` function helps you determine if the backup is protocol 2 or 1 and various useful details. :param number: Backup number to work on :type number: int :param client: Client name to work on :type client: str :returns: a dict with some useful details """ return trio.run(self._async_parse_backup_log, number, client)
Example #19
Source File: util.py From douyin_downloader with GNU Lesser General Public License v3.0 | 5 votes |
def get_token(self): '''获取Token: 有效期60分钟 get https://api.appsign.vip:2688/token/douyin -> { "token":"5826aa5b56614ea798ca42d767170e74", "success":true } >>> token = trio.run(SignUtil().get_token) # doctest: +ELLIPSIS >>> print(len(token)) 32 ''' url = f"{_API}/token/douyin/version/{self.version}" if self.version else f"{_API}/token/douyin" resp = await self.s.get(url, verify=False) logging.debug(f"get response from {url} is {resp} with body: {trim(resp.text)}") return resp.json().get('token', '')
Example #20
Source File: parallel.py From burp-ui with BSD 3-Clause "New" or "Revised" License | 5 votes |
def status(self, query='c:\n', timeout=None, cache=True, agent=None): """See :func:`burpui.misc.backend.interface.BUIbackend.status`""" return trio.run(self._async_status, query, timeout, cache)
Example #21
Source File: parallel.py From burp-ui with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_server_version(self, agent=None): if self._server_version is None: try: self._server_version = trio.run(self._async_request, 'server_version') except BUIserverException: return '' return self._server_version or ''
Example #22
Source File: parallel.py From burp-ui with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_client_version(self, agent=None): if self._client_version is None: try: self._client_version = trio.run(self._async_request, 'client_version') except BUIserverException: return '' return self._client_version or ''
Example #23
Source File: parallel.py From burp-ui with BSD 3-Clause "New" or "Revised" License | 5 votes |
def statistics(self, agent=None): return json.loads(trio.run(self._async_request, 'statistics'))
Example #24
Source File: parallel.py From burp-ui with BSD 3-Clause "New" or "Revised" License | 5 votes |
def batch_list_supported(self): if self._batch_list_supported is None: self._batch_list_supported = json.loads(trio.run(self._async_request, 'batch_list_supported')) return self._batch_list_supported
Example #25
Source File: parallel.py From burp-ui with BSD 3-Clause "New" or "Revised" License | 5 votes |
def server_version(self): return trio.run(self.get_server_version)
Example #26
Source File: parallel.py From burp-ui with BSD 3-Clause "New" or "Revised" License | 5 votes |
def client_version(self): return trio.run(self.get_client_version)
Example #27
Source File: parallel.py From burp-ui with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_client_labels(self, client=None, agent=None): """See :func:`burpui.misc.backend.interface.BUIbackend.get_client_labels` """ return trio.run(self._async_get_client_labels, client)
Example #28
Source File: parallel.py From burp-ui with BSD 3-Clause "New" or "Revised" License | 5 votes |
def is_backup_deletable(self, name=None, backup=None, agent=None): """See :func:`burpui.misc.backend.interface.BUIbackend.is_backup_deletable` """ return trio.run(self._async_is_backup_deletable, name, backup)
Example #29
Source File: parallel.py From burp-ui with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_client_filtered(self, name=None, limit=-1, page=None, start=None, end=None, agent=None): """See :func:`burpui.misc.backend.interface.BUIbackend.get_client_filtered`""" return trio.run(self._async_get_client_filtered, name, limit, page, start, end)
Example #30
Source File: parallel.py From burp-ui with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _get_last_backup(self, name, working=True): """Return the last backup of a given client :param name: Name of the client :type name: str :param working: Also return uncomplete backups :type working: bool :returns: The last backup """ return trio.run(self._async_get_last_backup, name, working)