Python _socket.AF_INET Examples
The following are 21
code examples of _socket.AF_INET().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
_socket
, or try the search function
.
Example #1
Source File: baseserver.py From PokemonGo-DesktopMap with MIT License | 6 votes |
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))
Example #2
Source File: baseserver.py From PokemonGo-DesktopMap with MIT License | 6 votes |
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))
Example #3
Source File: baseserver.py From satori with Apache License 2.0 | 6 votes |
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))
Example #4
Source File: baseserver.py From PhonePi_SampleServer with MIT License | 6 votes |
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))
Example #5
Source File: server.py From PhonePi_SampleServer with MIT License | 6 votes |
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
Example #6
Source File: server.py From PhonePi_SampleServer with MIT License | 5 votes |
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
Example #7
Source File: baseserver.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def _extract_family(host): if host.startswith('[') and host.endswith(']'): host = host[1:-1] return _socket.AF_INET6, host return _socket.AF_INET, host
Example #8
Source File: server.py From PokemonGo-DesktopMap with MIT License | 5 votes |
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
Example #9
Source File: baseserver.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def _extract_family(host): if host.startswith('[') and host.endswith(']'): host = host[1:-1] return _socket.AF_INET6, host return _socket.AF_INET, host
Example #10
Source File: server.py From PokemonGo-DesktopMap with MIT License | 5 votes |
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
Example #11
Source File: server.py From PokemonGo-DesktopMap with MIT License | 5 votes |
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
Example #12
Source File: baseserver.py From PhonePi_SampleServer with MIT License | 5 votes |
def _extract_family(host): if host.startswith('[') and host.endswith(']'): host = host[1:-1] return _socket.AF_INET6, host return _socket.AF_INET, host
Example #13
Source File: test__socket.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_inet_ntop(self): '''Tests _socket.inet_ntop''' #negative self.assertRaises(_socket.error, _socket.inet_ntop, _socket.AF_INET, "garbage dkfjdkfjdkfj")
Example #14
Source File: test__socket.py From ironpython3 with Apache License 2.0 | 5 votes |
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")
Example #15
Source File: test__socket.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_inet_ntop(self): '''Tests _socket.inet_ntop''' #negative self.assertRaises(ValueError, _socket.inet_ntop, _socket.AF_INET, b"garbage dkfjdkfjdkfj")
Example #16
Source File: websocket_gevent_impl.py From haven with MIT License | 5 votes |
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)
Example #17
Source File: gevent_impl.py From haven with MIT License | 5 votes |
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)
Example #18
Source File: baseserver.py From satori with Apache License 2.0 | 5 votes |
def _extract_family(host): if host.startswith('[') and host.endswith(']'): host = host[1:-1] return _socket.AF_INET6, host return _socket.AF_INET, host
Example #19
Source File: server.py From satori with Apache License 2.0 | 5 votes |
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
Example #20
Source File: server.py From satori with Apache License 2.0 | 5 votes |
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
Example #21
Source File: test__socket.py From ironpython2 with Apache License 2.0 | 5 votes |
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")