本文整理汇总了Python中_socket.AF_INET属性的典型用法代码示例。如果您正苦于以下问题:Python _socket.AF_INET属性的具体用法?Python _socket.AF_INET怎么用?Python _socket.AF_INET使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类_socket
的用法示例。
在下文中一共展示了_socket.AF_INET属性的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _parse_address
# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import AF_INET [as 别名]
def _parse_address(address):
if isinstance(address, tuple):
if ':' in address[0]:
return _socket.AF_INET6, address
return _socket.AF_INET, address
elif isinstance(address, string_types):
if ':' in address:
host, port = address.rsplit(':', 1)
family, host = _extract_family(host)
if host == '*':
host = ''
return family, (host, int(port))
else:
return _socket.AF_INET, ('', int(address))
elif isinstance(address, integer_types):
return _socket.AF_INET, ('', int(address))
else:
raise TypeError('Expected tuple or string, got %s' % type(address))
示例2: _udp_socket
# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import AF_INET [as 别名]
def _udp_socket(address, backlog=50, reuse_addr=None, family=_socket.AF_INET):
# backlog argument for compat with tcp_listener
# pylint:disable=unused-argument
# we want gevent.socket.socket here
sock = socket(family=family, type=_socket.SOCK_DGRAM)
if reuse_addr is not None:
sock.setsockopt(_socket.SOL_SOCKET, _socket.SO_REUSEADDR, reuse_addr)
try:
sock.bind(address)
except _socket.error as ex:
strerror = getattr(ex, 'strerror', None)
if strerror is not None:
ex.strerror = strerror + ': ' + repr(address)
raise
return sock
示例3: _parse_address
# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import AF_INET [as 别名]
def _parse_address(address):
if isinstance(address, tuple):
if not address[0] or ':' in address[0]:
return _socket.AF_INET6, address
return _socket.AF_INET, address
if ((isinstance(address, string_types) and ':' not in address)
or isinstance(address, integer_types)): # noqa (pep8 E129)
# Just a port
return _socket.AF_INET6, ('', int(address))
if not isinstance(address, string_types):
raise TypeError('Expected tuple or string, got %s' % type(address))
host, port = address.rsplit(':', 1)
family, host = _extract_family(host)
if host == '*':
host = ''
return family, (host, int(port))
示例4: test_inet_ntop
# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import AF_INET [as 别名]
def test_inet_ntop(self):
'''Tests _socket.inet_ntop'''
#negative
self.assertRaises(_socket.error, _socket.inet_ntop, _socket.AF_INET, "garbage dkfjdkfjdkfj")
示例5: test_inet_pton
# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import AF_INET [as 别名]
def test_inet_pton(self):
'''Tests _socket.inet_pton'''
#sanity
_socket.inet_pton(_socket.AF_INET, "127.0.0.1")
#negative
self.assertRaises(_socket.error, _socket.inet_pton, _socket.AF_INET, "garbage dkfjdkfjdkfj")
示例6: _tcp_listener
# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import AF_INET [as 别名]
def _tcp_listener(address, backlog=50, reuse_addr=None, family=_socket.AF_INET):
"""A shortcut to create a TCP socket, bind it and put it into listening state."""
sock = socket(family=family)
if reuse_addr is not None:
sock.setsockopt(_socket.SOL_SOCKET, _socket.SO_REUSEADDR, reuse_addr)
try:
sock.bind(address)
except _socket.error as ex:
strerror = getattr(ex, 'strerror', None)
if strerror is not None:
ex.strerror = strerror + ': ' + repr(address)
raise
sock.listen(backlog)
sock.setblocking(0)
return sock
示例7: _udp_socket
# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import AF_INET [as 别名]
def _udp_socket(address, backlog=50, reuse_addr=None, family=_socket.AF_INET):
# we want gevent.socket.socket here
sock = socket(family=family, type=_socket.SOCK_DGRAM)
if reuse_addr is not None:
sock.setsockopt(_socket.SOL_SOCKET, _socket.SO_REUSEADDR, reuse_addr)
try:
sock.bind(address)
except _socket.error as ex:
strerror = getattr(ex, 'strerror', None)
if strerror is not None:
ex.strerror = strerror + ': ' + repr(address)
raise
return sock
示例8: _extract_family
# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import AF_INET [as 别名]
def _extract_family(host):
if host.startswith('[') and host.endswith(']'):
host = host[1:-1]
return _socket.AF_INET6, host
return _socket.AF_INET, host
示例9: _prepare_server
# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import AF_INET [as 别名]
def _prepare_server(self, address):
import _socket
# 只有这样,才能保证在主进程里面,不会启动accept
listener = self.server_class.get_listener(address, backlog=self.backlog, family=_socket.AF_INET)
listener.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
self.server = self.server_class(listener, handle=self._handle_stream)
示例10: _prepare_server
# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import AF_INET [as 别名]
def _prepare_server(self, address):
import _socket
# 只有这样,才能保证在主进程里面,不会启动accept
listener = self.server_class.get_listener(address, backlog=self.backlog, family=_socket.AF_INET)
listener.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
self.server = WebSocketServer(listener, self.wsgi_app)
示例11: test_inet_ntop
# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import AF_INET [as 别名]
def test_inet_ntop(self):
'''Tests _socket.inet_ntop'''
#negative
self.assertRaises(ValueError, _socket.inet_ntop, _socket.AF_INET, b"garbage dkfjdkfjdkfj")
示例12: test_inet_pton
# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import AF_INET [as 别名]
def test_inet_pton(self):
'''Tests _socket.inet_pton'''
#sanity
_socket.inet_pton(_socket.AF_INET, "127.0.0.1")
#negative
self.assertRaises(_socket.error, _socket.inet_pton, _socket.AF_INET, "garbage dkfjdkfjdkfj")