tornado.netutil — Miscellaneous network utilities 杂项网络工具

E文较渣 翻译一篇试试

鸣谢GOOGLE翻译

原文地址

tornado.netutil — Miscellaneous network utilities

Miscellaneous network utility code.

杂项网络工具代码

tornado.netutil.bind_sockets(port,address=None, family=0, backlog=128, flags=None)[source]

Creates listening sockets bound to the given port and address.

创建监听套接字,然后绑定到提供的端口和地址。

Returns a list of socket objects (multiple sockets are returned if the given address maps to multiple IP addresses, which is most common for mixed IPv4 and IPv6 use).

返回一个套接字对象列表(如果给定的地址映射多个IP地址将返回多个套接字,其中最常见的是IPv4和IPv6混合使用)。

Address may be either an IP address or hostname. If it’s a hostname,the server will listen on all IP addresses associated with the name. Address may be an empty string or None to listen on all available interfaces. Family may be set to either socket.AF_INETorsocket.AF_INET6 to restrict to IPv4 or IPv6 addresses, otherwise both will be used if available.

地址可以是一个IP地址或者主机名。如果它是一个主机名,服务器将监听所有与这个主机名相关联的IP地址。 地址可能是一个空字符串或者不能监听可用接口。 family可设置成socket.AF_INETsocket.AF_INET6来限制使用的是IPv4或IPv6地址,否则都将被使用(如果可用的话)。

The backlog argument has the same meaning as forsocket.listen().

backlogsocket.listen() 含义相同

flags is a bit mask of AI_* flags togetaddrinfo, likesocket.AI_PASSIVE| socket.AI_NUMERICHOST.

flags是AI_ *flagsgetaddrinfo位掩码socket.AI_PASSIVE | socket.AI_NUMERICHOST。
tornado.netutil.bind_unix_socket(file,mode=384, backlog=128)[source]

Creates a listening unix socket.

创建一个Unix监听套接字

If a socket with the given name already exists, it will be deleted.If any other file with that name exists, an exception will beraised.

如果创建套接字的名称已经存在,原来的将会被删除。如果与其他(已存在的)文件同名,将引发异常。

Returns a socket object (not a list of socket objects likebind_sockets)

         返回一个套接字对象(而不是一个套接字对象列表,如bind_sockets
tornado.netutil.add_accept_handler(sock,callback, io_loop=None)[source]

Adds an IOLoop event handler to accept new connections onsock.

添加一个IOLoop的事件处理程序来接受在sock上的新连接。

When a connection is accepted, callback(connection, address) willbe run (connection is a socket object, andaddress is the address of the other end of the connection). Note that this signature is different from thecallback(fd, events) signature used forIOLoop handlers.

         当一个连接被接受,回调(callback(connection,address)将会运行connection是一个套接字对象和address的另一端连接的地址)。请注意,该签名不同于callback(fd,events)用于IOLoop处理程序的签名。


tornado.netutil.is_valid_ip(ip)[source]

Returns true if the given string is a well-formed IP address.

如果给定的字符串是一个正确的IP地址将返回true

Supports IPv4 and IPv6.

         支持IPv4和IPv6。
classtornado.netutil.Resolver[source]

Configurable asynchronous DNS resolver interface.

配置异步DNS解析器接口。

By default, a blocking implementation is used (which simply callssocket.getaddrinfo). An alternative implementation can be chosen with the Resolver.configureclass method:

默认情况下,将会使用拥塞进行实现(这只需调用socket.getaddrinfo )。 另一种可以选择的实现是Resolver.configure类方法:

Resolver.configure('tornado.netutil.ThreadedResolver')

The implementations of this interface included with Tornado are

Tornado中此接口的实现包含

resolve(host,port, family=0, callback=None)[source]

Resolves an address.

解析一个地址。

The host argument is a string which may be a hostname or a literal IP address.

host是一个表示主机名或文字式的IP地址的字符串。

Returns a Future whose result is a list of (family,address) pairs, where address is a tuple suitable to pass tosocket.connect (i.e. a (host,port) pair for IPv4; additional fields may be present for IPv6). If acallback is passed, it will be run with the result as an argument when it is complete.

返回一个Future (一个(family,address)对的列表)其中address是一个传递给socket.connect的元组(如一个IPv4的(host,port),增加额外的字段将支持IPv6)如果传进来一个callback当它是完整的时候,将作为一个参数来运行这个结果


close()[source]

Closes the Resolver, freeing any resources used.

关闭的解析器 ,释放所有使用资源。

New in version 3.1.

             版本3.1中新加的
classtornado.netutil.ExecutorResolver[source]

Resolver implementation using a concurrent.futures.Executor.

解析器使用concurrent.futures.Executor实现。

Use this instead of ThreadedResolver when you require additional control over the executor being used.

用此代替ThreadedResolver,当你需要额外的控制权来越过正在使用的执行者时。

The executor will be shut down when the resolver is closed unlessclose_resolver=False; use this if you want to reuse the same executor else where.

        解析器关闭时,执行者将被关闭。除非close_resolver = FALSE;当你想在其他地方重复使用相同的执行者时使用此法。
classtornado.netutil.BlockingResolver[source]

Default Resolver implementation, usingsocket.getaddrinfo.

默认解析器的实现将使用socket.getaddrinfo

The IOLoop will be blocked during the resolution, although the callback will not be run until the nextIOLoop iteration.

         解析过程中IOLoop塞的,尽管回调将会在下一个IOLoop迭代中执行
classtornado.netutil.ThreadedResolver[source]

Multithreaded non-blocking Resolver implementation.

多线程的非阻塞解析器实现。

Requires the concurrent.futures package to be installed(available in the standard library since Python 3.2,installable withpip installfutures in older versions).

需要concurrent.futures包进行安装(在Python 3.2以上的标准库中可以支持,旧版本使用pipinstall futures进行安装)

The thread pool size can be configured with:

线程池的大小可通过以下方法进行配置:

Resolver.configure('tornado.netutil.ThreadedResolver',
                   num_threads=10)

Changed in version 3.1:All ThreadedResolvers share a single thread pool, whose size is set by the first one to be created.

在3.1版本中的改变:所有ThreadedResolvers共享一个单线程池,其大小在创建第一个时被设置。
classtornado.netutil.OverrideResolver[source]

Wraps a resolver with a mapping of overrides.

通过覆盖的映射来包装解析器。

This can be used to make local DNS changes (e.g. for testing)without modifying system-wide settings.

无需修改系统范围内的设置就可以修改本地的DNS(例如测试时)。

The mapping can contain either host strings or host-port pairs.

         映射包含的主机字符串或主机端口对。
tornado.netutil.ssl_options_to_context(ssl_options)[source]

Try to convert an ssl_options dictionary to anSSLContext object.

尝试转换一个ssl_options字典成SSLContext对象。

The ssl_options dictionary contains keywords to be passed tossl.wrap_socket. In Python 3.2+, ssl.SSLContext objects can be used instead. This function converts the dict form to itsSSLContext equivalent, and may be used when a component which accepts both forms needs to upgrade to theSSLContext version to use features like SNI or NPN.

ssl_options字典包含要传递给ssl.wrap_socket的关键字在Python 3.2及更高版本中, ssl.SSLContext可以被替换。此函数可用来将字典等价转换成SSLContext,也可在一个能接受两种形式的组件需要升级到SSLContext版本(如SNI或NPN)时使用。

tornado.netutil.ssl_wrap_socket(socket,ssl_options, server_hostname=None, **kwargs)[source]

Returns an ssl.SSLSocket wrapping the given socket.

返回一个包装了提供的套接字的ssl.SSLSocket

ssl_options may be either a dictionary (as accepted byssl_options_to_context) or an ssl.SSLContext object.Additional keyword arguments are passed towrap_socket(either theSSLContext method or thessl module functionas appropriate).

ssl_options可以是一个字典(ssl_options_to_context可以接受)或一个ssl.SSLContext对象。额外的关键字参数将传递给wrap_socket适当于SSLContext方法和SSL模块函数)。

tornado.netutil.ssl_match_hostname(cert,hostname)[source]

Verify that cert (in decoded format as returned by SSLSocket.getpeercert()) matches thehostname. RFC 2818 rules are mostly followed, but IP addresses are not accepted forhostname.

验证cert(在通过SSLSocket.getpeercert()返回的解码格式中)是否与hostname匹配。尽管大多数遵循RFC 2818规则,但hostname不接受IP地址。

CertificateError is raised on failure. On success, the function returns nothing.

失败时会抛出CertificateError(证书错误)成功时,函数什么都不返回。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值