当前位置: 首页>>代码示例>>Python>>正文


Python aiohttp.AsyncResolver方法代码示例

本文整理汇总了Python中aiohttp.AsyncResolver方法的典型用法代码示例。如果您正苦于以下问题:Python aiohttp.AsyncResolver方法的具体用法?Python aiohttp.AsyncResolver怎么用?Python aiohttp.AsyncResolver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在aiohttp的用法示例。


在下文中一共展示了aiohttp.AsyncResolver方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import AsyncResolver [as 别名]
def __init__(
        self,
        session=None,
        user_agent=DEFAULT_USER_AGENT,
        request_timeout=30,
        max_content_length=10 * 1024 * 1024,
        allow_private_address=False,
        allow_non_webpage=False,
        rss_proxy_url=None,
        rss_proxy_token=None,
        dns_service: DNSService = DNS_SERVICE,
    ):
        self._close_session = session is None
        self.session = session
        self.resolver: aiohttp.AsyncResolver = None
        self.user_agent = user_agent() if callable(user_agent) else user_agent
        self.request_timeout = request_timeout
        self.max_content_length = max_content_length
        self.allow_private_address = allow_private_address
        self.allow_non_webpage = allow_non_webpage
        self.rss_proxy_url = rss_proxy_url
        self.rss_proxy_token = rss_proxy_token
        self.dns_service = dns_service 
开发者ID:anyant,项目名称:rssant,代码行数:25,代码来源:async_reader.py

示例2: _recreate

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import AsyncResolver [as 别名]
def _recreate(self) -> None:
        """Re-create the connector, aiohttp session, the APIClient and the Redis session."""
        # Use asyncio for DNS resolution instead of threads so threads aren't spammed.
        # Doesn't seem to have any state with regards to being closed, so no need to worry?
        self._resolver = aiohttp.AsyncResolver()

        # Its __del__ does send a warning but it doesn't always show up for some reason.
        if self._connector and not self._connector._closed:
            log.warning(
                "The previous connector was not closed; it will remain open and be overwritten"
            )

        if self.redis_session and not self.redis_session.closed:
            log.warning(
                "The previous redis pool was not closed; it will remain open and be overwritten"
            )

        # Create the redis session
        self.loop.create_task(self._create_redis_session())

        # Use AF_INET as its socket family to prevent HTTPS related problems both locally
        # and in production.
        self._connector = aiohttp.TCPConnector(
            resolver=self._resolver,
            family=socket.AF_INET,
        )

        # Client.login() will call HTTPClient.static_login() which will create a session using
        # this connector attribute.
        self.http.connector = self._connector

        # Its __del__ does send a warning but it doesn't always show up for some reason.
        if self.http_session and not self.http_session.closed:
            log.warning(
                "The previous session was not closed; it will remain open and be overwritten"
            )

        self.http_session = aiohttp.ClientSession(connector=self._connector)
        self.api_client.recreate(force=True, connector=self._connector) 
开发者ID:python-discord,项目名称:bot,代码行数:41,代码来源:bot.py

示例3: run

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import AsyncResolver [as 别名]
def run(target, threads, tout, wdlist, redir, sslv, dserv, output, data, filext):
	global responses
	tasks = []
	if len(filext) == 0:
		url = target + '/{}'
		resolver = aiohttp.AsyncResolver(nameservers=[dserv])
		conn = aiohttp.TCPConnector(limit=threads, resolver=resolver, family=socket.AF_INET, verify_ssl=sslv)
		timeout = aiohttp.ClientTimeout(total=None, sock_connect=tout, sock_read=tout)
		async with aiohttp.ClientSession(connector=conn, timeout=timeout) as session:
			with open(wdlist, 'r') as wordlist:
				for word in wordlist:
					word = word.strip()
					task = asyncio.create_task(fetch(url.format(word), session, redir, sslv))
					tasks.append(task)
					await asyncio.sleep(0)
			responses = await asyncio.gather(*tasks)
	else:
		filext = ',' + filext
		filext = filext.split(',')
		for ext in filext:
			ext = ext.strip()
			if len(ext) == 0:
				url = target + '/{}'
			else:
				url = target + '/{}.' + ext
			resolver = aiohttp.AsyncResolver(nameservers=[dserv])
			conn = aiohttp.TCPConnector(limit=threads, resolver=resolver, family=socket.AF_INET, verify_ssl=sslv)
			timeout = aiohttp.ClientTimeout(total=None, sock_connect=tout, sock_read=tout)
			async with aiohttp.ClientSession(connector=conn, timeout=timeout) as session:
				with open(wdlist, 'r') as wordlist:
					for word in wordlist:
						word = word.strip()
						task = asyncio.create_task(fetch(url.format(word), session, redir, sslv))
						tasks.append(task)
						await asyncio.sleep(0)
				responses = await asyncio.gather(*tasks) 
开发者ID:thewhiteh4t,项目名称:FinalRecon,代码行数:38,代码来源:dirrec.py

示例4: wayback

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import AsyncResolver [as 别名]
def wayback(dserv, tout):
	global found
	print('\n' + Y + '[!]' + C + ' Requesting Wayback Machine...' + W + '\n')
	tasks = []
	resolver = aiohttp.AsyncResolver(nameservers=[dserv])
	conn = aiohttp.TCPConnector(limit=10)
	timeout = aiohttp.ClientTimeout(total=None, sock_connect=tout, sock_read=tout)
	async with aiohttp.ClientSession(connector=conn, timeout=timeout) as session:
		for f_url in found:
			tasks.append(asyncio.create_task(wm_fetch(f_url, session)))
		await asyncio.gather(*tasks) 
开发者ID:thewhiteh4t,项目名称:FinalRecon,代码行数:13,代码来源:dirrec.py

示例5: startup

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import AsyncResolver [as 别名]
def startup(self) -> None:
        """Initialize the crawler manager's redis connection and
        http session used to make requests to shepherd
        """
        self.loop = get_event_loop()
        self.redis = await init_redis(
            env('REDIS_URL', default=DEFAULT_REDIS_URL), self.loop
        )
        self.session = ClientSession(
            connector=TCPConnector(
                resolver=AsyncResolver(loop=self.loop), loop=self.loop
            ),
            json_serialize=partial(json.dumps, ensure_ascii=False),
            loop=self.loop,
        ) 
开发者ID:webrecorder,项目名称:browsertrix,代码行数:17,代码来源:crawl.py

示例6: aiohttp_client_session

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import AsyncResolver [as 别名]
def aiohttp_client_session(*, timeout=None, resolver=None, **kwargs):
    """use aiodns and support number timeout"""
    if timeout is None:
        timeout = 30
    if isinstance(timeout, (int, float)):
        timeout = aiohttp.ClientTimeout(total=timeout)
    if resolver is None:
        resolver = aiohttp.AsyncResolver()
    # Fix: No route to host. https://github.com/saghul/aiodns/issues/22
    family = socket.AF_INET
    connector = aiohttp.TCPConnector(resolver=resolver, family=family)
    return aiohttp.ClientSession(connector=connector, timeout=timeout, **kwargs) 
开发者ID:anyant,项目名称:rssant,代码行数:14,代码来源:helper.py

示例7: _async_init

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import AsyncResolver [as 别名]
def _async_init(self):
        if self.resolver is None:
            loop = asyncio.get_event_loop()
            if self.dns_service is None:
                self.resolver = aiohttp.AsyncResolver(loop=loop)
            else:
                self.resolver = self.dns_service.aiohttp_resolver(loop=loop)
        if self.session is None:
            self.session = aiohttp_client_session(
                resolver=self.resolver, timeout=self.request_timeout) 
开发者ID:anyant,项目名称:rssant,代码行数:12,代码来源:async_reader.py

示例8: __init__

# 需要导入模块: import aiohttp [as 别名]
# 或者: from aiohttp import AsyncResolver [as 别名]
def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.http_session = ClientSession(
            connector=TCPConnector(resolver=AsyncResolver(), family=socket.AF_INET)
        )
        self._guild_available = asyncio.Event()

        self.loop.create_task(self.send_log("SeasonalBot", "Connected!")) 
开发者ID:python-discord,项目名称:seasonalbot,代码行数:10,代码来源:bot.py


注:本文中的aiohttp.AsyncResolver方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。