當前位置: 首頁>>代碼示例>>Python>>正文


Python netutil.Resolver方法代碼示例

本文整理匯總了Python中tornado.netutil.Resolver方法的典型用法代碼示例。如果您正苦於以下問題:Python netutil.Resolver方法的具體用法?Python netutil.Resolver怎麽用?Python netutil.Resolver使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tornado.netutil的用法示例。


在下文中一共展示了netutil.Resolver方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from tornado import netutil [as 別名]
# 或者: from tornado.netutil import Resolver [as 別名]
def __init__(self, io_loop, request):
        self.connect_future = TracebackFuture()
        self.read_future = None
        self.read_queue = collections.deque()
        self.key = base64.b64encode(os.urandom(16))

        scheme, sep, rest = request.url.partition(':')
        scheme = {'ws': 'http', 'wss': 'https'}[scheme]
        request.url = scheme + sep + rest
        request.headers.update({
            'Upgrade': 'websocket',
            'Connection': 'Upgrade',
            'Sec-WebSocket-Key': self.key,
            'Sec-WebSocket-Version': '13',
        })

        self.resolver = Resolver(io_loop=io_loop)
        super(WebSocketClientConnection, self).__init__(
            io_loop, None, request, lambda: None, self._on_http_response,
            104857600, self.resolver) 
開發者ID:viewfinderco,項目名稱:viewfinder,代碼行數:22,代碼來源:websocket.py

示例2: raw_fetch

# 需要導入模塊: from tornado import netutil [as 別名]
# 或者: from tornado.netutil import Resolver [as 別名]
def raw_fetch(self, headers, body):
        with closing(Resolver(io_loop=self.io_loop)) as resolver:
            with closing(SimpleAsyncHTTPClient(self.io_loop,
                                               resolver=resolver)) as client:
                conn = RawRequestHTTPConnection(
                    self.io_loop, client,
                    httpclient._RequestProxy(
                        httpclient.HTTPRequest(self.get_url("/")),
                        dict(httpclient.HTTPRequest._DEFAULTS)),
                    None, self.stop,
                    1024 * 1024, resolver)
                conn.set_request(
                    b"\r\n".join(headers +
                                 [utf8("Content-Length: %d\r\n" % len(body))]) +
                    b"\r\n" + body)
                response = self.wait()
                response.rethrow()
                return response 
開發者ID:viewfinderco,項目名稱:viewfinder,代碼行數:20,代碼來源:httpserver_test.py

示例3: initialize

# 需要導入模塊: from tornado import netutil [as 別名]
# 或者: from tornado.netutil import Resolver [as 別名]
def initialize(self, io_loop=None):
        self.io_loop = io_loop or IOLoop.current()
        # partial copy of twisted.names.client.createResolver, which doesn't
        # allow for a reactor to be passed in.
        self.reactor = tornado.platform.twisted.TornadoReactor(io_loop)

        host_resolver = twisted.names.hosts.Resolver('/etc/hosts')
        cache_resolver = twisted.names.cache.CacheResolver(reactor=self.reactor)
        real_resolver = twisted.names.client.Resolver('/etc/resolv.conf',
                                                      reactor=self.reactor)
        self.resolver = twisted.names.resolve.ResolverChain(
            [host_resolver, cache_resolver, real_resolver]) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:14,代碼來源:twisted.py

示例4: __init__

# 需要導入模塊: from tornado import netutil [as 別名]
# 或者: from tornado.netutil import Resolver [as 別名]
def __init__(self, resolver=None, io_loop=None):
        self.io_loop = io_loop or IOLoop.current()
        if resolver is not None:
            self.resolver = resolver
            self._own_resolver = False
        else:
            self.resolver = Resolver(io_loop=io_loop)
            self._own_resolver = True 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:10,代碼來源:tcpclient.py

示例5: setUp

# 需要導入模塊: from tornado import netutil [as 別名]
# 或者: from tornado.netutil import Resolver [as 別名]
def setUp(self):
        # Dummy Resolver subclass that never invokes its callback.
        class BadResolver(Resolver):
            def resolve(self, *args, **kwargs):
                pass

        super(ResolveTimeoutTestCase, self).setUp()
        self.http_client = SimpleAsyncHTTPClient(
            self.io_loop,
            resolver=BadResolver()) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:12,代碼來源:simple_httpclient_test.py

示例6: main

# 需要導入模塊: from tornado import netutil [as 別名]
# 或者: from tornado.netutil import Resolver [as 別名]
def main():
    args = parse_command_line()

    if not args:
        args = ['localhost', 'www.google.com',
                'www.facebook.com', 'www.dropbox.com']

    resolvers = [Resolver(), ThreadedResolver()]

    if twisted is not None:
        from tornado.platform.twisted import TwistedResolver
        resolvers.append(TwistedResolver())

    if pycares is not None:
        from tornado.platform.caresresolver import CaresResolver
        resolvers.append(CaresResolver())

    family = {
        'unspec': socket.AF_UNSPEC,
        'inet': socket.AF_INET,
        'inet6': socket.AF_INET6,
        }[options.family]

    for host in args:
        print('Resolving %s' % host)
        for resolver in resolvers:
            addrinfo = yield resolver.resolve(host, 80, family)
            print('%s: %s' % (resolver.__class__.__name__,
                              pprint.pformat(addrinfo)))
        print() 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:32,代碼來源:test_resolvers.py

示例7: __init__

# 需要導入模塊: from tornado import netutil [as 別名]
# 或者: from tornado.netutil import Resolver [as 別名]
def __init__(self, sock):
        self._iostream = IOStream(sock)
        self._resolver = Resolver()
        self._readtimeout = 0
        self._connecttimeout = 0
        self._rbuffer = StringIO(b'')
        self._rbuffer_size = 0 
開發者ID:zhu327,項目名稱:greentor,代碼行數:9,代碼來源:green.py

示例8: initialize

# 需要導入模塊: from tornado import netutil [as 別名]
# 或者: from tornado.netutil import Resolver [as 別名]
def initialize(self) -> None:
        # partial copy of twisted.names.client.createResolver, which doesn't
        # allow for a reactor to be passed in.
        self.reactor = twisted.internet.asyncioreactor.AsyncioSelectorReactor()

        host_resolver = twisted.names.hosts.Resolver("/etc/hosts")
        cache_resolver = twisted.names.cache.CacheResolver(reactor=self.reactor)
        real_resolver = twisted.names.client.Resolver(
            "/etc/resolv.conf", reactor=self.reactor
        )
        self.resolver = twisted.names.resolve.ResolverChain(
            [host_resolver, cache_resolver, real_resolver]
        ) 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:15,代碼來源:twisted.py

示例9: __init__

# 需要導入模塊: from tornado import netutil [as 別名]
# 或者: from tornado.netutil import Resolver [as 別名]
def __init__(self, resolver: Resolver = None) -> None:
        if resolver is not None:
            self.resolver = resolver
            self._own_resolver = False
        else:
            self.resolver = Resolver()
            self._own_resolver = True 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:9,代碼來源:tcpclient.py

示例10: test_connect_timeout

# 需要導入模塊: from tornado import netutil [as 別名]
# 或者: from tornado.netutil import Resolver [as 別名]
def test_connect_timeout(self):
        timeout = 0.1

        cleanup_event = Event()
        test = self

        class TimeoutResolver(Resolver):
            async def resolve(self, *args, **kwargs):
                await cleanup_event.wait()
                # Return something valid so the test doesn't raise during shutdown.
                return [(socket.AF_INET, ("127.0.0.1", test.get_http_port()))]

        with closing(self.create_client(resolver=TimeoutResolver())) as client:
            with self.assertRaises(HTTPTimeoutError):
                yield client.fetch(
                    self.get_url("/hello"),
                    connect_timeout=timeout,
                    request_timeout=3600,
                    raise_error=True,
                )

        # Let the hanging coroutine clean up after itself. We need to
        # wait more than a single IOLoop iteration for the SSL case,
        # which logs errors on unexpected EOF.
        cleanup_event.set()
        yield gen.sleep(0.2) 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:28,代碼來源:simple_httpclient_test.py

示例11: setUp

# 需要導入模塊: from tornado import netutil [as 別名]
# 或者: from tornado.netutil import Resolver [as 別名]
def setUp(self):
        self.cleanup_event = Event()
        test = self

        # Dummy Resolver subclass that never finishes.
        class BadResolver(Resolver):
            @gen.coroutine
            def resolve(self, *args, **kwargs):
                yield test.cleanup_event.wait()
                # Return something valid so the test doesn't raise during cleanup.
                return [(socket.AF_INET, ("127.0.0.1", test.get_http_port()))]

        super(ResolveTimeoutTestCase, self).setUp()
        self.http_client = SimpleAsyncHTTPClient(resolver=BadResolver()) 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:16,代碼來源:simple_httpclient_test.py

示例12: initialize

# 需要導入模塊: from tornado import netutil [as 別名]
# 或者: from tornado.netutil import Resolver [as 別名]
def initialize(self, io_loop, max_clients=10,
                   hostname_mapping=None, max_buffer_size=104857600,
                   resolver=None, defaults=None):
        """Creates a AsyncHTTPClient.

        Only a single AsyncHTTPClient instance exists per IOLoop
        in order to provide limitations on the number of pending connections.
        force_instance=True may be used to suppress this behavior.

        max_clients is the number of concurrent requests that can be
        in progress.  Note that this arguments are only used when the
        client is first created, and will be ignored when an existing
        client is reused.

        hostname_mapping is a dictionary mapping hostnames to IP addresses.
        It can be used to make local DNS changes when modifying system-wide
        settings like /etc/hosts is not possible or desirable (e.g. in
        unittests).

        max_buffer_size is the number of bytes that can be read by IOStream. It
        defaults to 100mb.
        """
        super(SimpleAsyncHTTPClient, self).initialize(io_loop,
                                                      defaults=defaults)
        self.max_clients = max_clients
        self.queue = collections.deque()
        self.active = {}
        self.max_buffer_size = max_buffer_size
        if resolver:
            self.resolver = resolver
            self.own_resolver = False
        else:
            self.resolver = Resolver(io_loop=io_loop)
            self.own_resolver = True
        if hostname_mapping is not None:
            self.resolver = OverrideResolver(resolver=self.resolver,
                                             mapping=hostname_mapping) 
開發者ID:viewfinderco,項目名稱:viewfinder,代碼行數:39,代碼來源:simple_httpclient.py

示例13: initialize

# 需要導入模塊: from tornado import netutil [as 別名]
# 或者: from tornado.netutil import Resolver [as 別名]
def initialize(self):
        # partial copy of twisted.names.client.createResolver, which doesn't
        # allow for a reactor to be passed in.
        self.reactor = tornado.platform.twisted.TornadoReactor()

        host_resolver = twisted.names.hosts.Resolver('/etc/hosts')
        cache_resolver = twisted.names.cache.CacheResolver(reactor=self.reactor)
        real_resolver = twisted.names.client.Resolver('/etc/resolv.conf',
                                                      reactor=self.reactor)
        self.resolver = twisted.names.resolve.ResolverChain(
            [host_resolver, cache_resolver, real_resolver]) 
開發者ID:tp4a,項目名稱:teleport,代碼行數:13,代碼來源:twisted.py

示例14: __init__

# 需要導入模塊: from tornado import netutil [as 別名]
# 或者: from tornado.netutil import Resolver [as 別名]
def __init__(self, resolver=None):
        if resolver is not None:
            self.resolver = resolver
            self._own_resolver = False
        else:
            self.resolver = Resolver()
            self._own_resolver = True 
開發者ID:tp4a,項目名稱:teleport,代碼行數:9,代碼來源:tcpclient.py

示例15: test_connect_timeout

# 需要導入模塊: from tornado import netutil [as 別名]
# 或者: from tornado.netutil import Resolver [as 別名]
def test_connect_timeout(self):
        timeout = 0.1

        class TimeoutResolver(Resolver):
            def resolve(self, *args, **kwargs):
                return Future()  # never completes

        with closing(self.create_client(resolver=TimeoutResolver())) as client:
            with self.assertRaises(HTTPTimeoutError):
                yield client.fetch(self.get_url('/hello'),
                                   connect_timeout=timeout,
                                   request_timeout=3600,
                                   raise_error=True) 
開發者ID:tp4a,項目名稱:teleport,代碼行數:15,代碼來源:simple_httpclient_test.py


注:本文中的tornado.netutil.Resolver方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。