本文整理匯總了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")