當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。