Python _socket.error() Examples
The following are 30
code examples of _socket.error().
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: 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 #2
Source File: test__socket.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_makefile_refcount(self): "Ensures that the _socket stays open while there's still a file associated" def echoer(port): s = socket.socket() s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) # prevents an "Address already in use" error when the socket is in a TIME_WAIT state s.bind(('localhost', port)) s.listen(5) (s2, ignore) = s.accept() s2.send(s2.recv(10)) port = 50008 _thread.start_new_thread(echoer, (port, )) time.sleep(1) s = socket.socket() s.connect(('localhost', port)) f1 = s.makefile('r') f2 = s.makefile('w') s.close() test_msg = 'abc\n' f2.write(test_msg) f2.flush() str = f1.readline() self.assertEqual(str, test_msg)
Example #3
Source File: aid.py From pycopia with Apache License 2.0 | 6 votes |
def systemcall(meth): """Decorator to make system call methods safe from EINTR.""" # have to import this way to avoid a circular import from _socket import error as SocketError def systemcallmeth(*args, **kwargs): while 1: try: rv = meth(*args, **kwargs) except EnvironmentError as why: if why.args and why.args[0] == EINTR: continue else: raise except SocketError as why: if why.args and why.args[0] == EINTR: continue else: raise else: break return rv return systemcallmeth
Example #4
Source File: resolver_ares.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def __call__(self, source): self.count -= 1 if source.exception is None: self.values.append(source.value) else: self.error = source.exception if self.count <= 0: self.waiter.switch()
Example #5
Source File: resolver_ares.py From PhonePi_SampleServer with MIT License | 5 votes |
def get(self): self.waiter.get() if self.values: return self.values else: assert error is not None raise self.error # pylint:disable=raising-bad-type
Example #6
Source File: resolver_ares.py From PhonePi_SampleServer with MIT License | 5 votes |
def _resolve_special(hostname, family): if hostname == '': result = getaddrinfo(None, 0, family, SOCK_DGRAM, 0, AI_PASSIVE) if len(result) != 1: raise error('wildcard resolved to multiple address') return result[0][4][0] return hostname
Example #7
Source File: baseserver.py From PhonePi_SampleServer with MIT License | 5 votes |
def _formatinfo(self): if hasattr(self, 'socket'): try: fileno = self.socket.fileno() except Exception as ex: fileno = str(ex) result = 'fileno=%s ' % fileno else: result = '' try: if isinstance(self.address, tuple) and len(self.address) == 2: result += 'address=%s:%s' % self.address else: result += 'address=%s' % (self.address, ) except Exception as ex: result += str(ex) or '<error>' handle = self.__dict__.get('handle') if handle is not None: fself = getattr(handle, '__self__', None) try: if fself is self: # Checks the __self__ of the handle in case it is a bound # method of self to prevent recursivly defined reprs. handle_repr = '<bound method %s.%s of self>' % ( self.__class__.__name__, handle.__name__, ) else: handle_repr = repr(handle) result += ' handle=' + handle_repr except Exception as ex: result += str(ex) or '<error>' return result
Example #8
Source File: server.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def do_read(self): try: client_socket, address = self.socket.accept() except _socket.error as err: if err.args[0] == EWOULDBLOCK: return raise sockobj = socket(_sock=client_socket) if PYPY: client_socket._drop() return sockobj, address
Example #9
Source File: server.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def do_read(self): try: data, address = self._socket.recvfrom(8192) except _socket.error as err: if err.args[0] == EWOULDBLOCK: return raise return data, address
Example #10
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 #11
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 #12
Source File: resolver_ares.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def __init__(self, hub, count): self.count = count self.values = [] self.error = None self.waiter = Waiter(hub)
Example #13
Source File: resolver_ares.py From PhonePi_SampleServer with MIT License | 5 votes |
def __call__(self, source): self.count -= 1 if source.exception is None: self.values.append(source.value) else: self.error = source.exception if self.count <= 0: self.waiter.switch()
Example #14
Source File: resolver_ares.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def _resolve_special(hostname, family): if hostname == '': result = getaddrinfo(None, 0, family, SOCK_DGRAM, 0, AI_PASSIVE) if len(result) != 1: raise error('wildcard resolved to multiple address') return result[0][4][0] return hostname
Example #15
Source File: baseserver.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def _formatinfo(self): if hasattr(self, 'socket'): try: fileno = self.socket.fileno() except Exception as ex: fileno = str(ex) result = 'fileno=%s ' % fileno else: result = '' try: if isinstance(self.address, tuple) and len(self.address) == 2: result += 'address=%s:%s' % self.address else: result += 'address=%s' % (self.address, ) except Exception as ex: result += str(ex) or '<error>' handle = self.__dict__.get('handle') if handle is not None: fself = getattr(handle, '__self__', None) try: if fself is self: # Checks the __self__ of the handle in case it is a bound # method of self to prevent recursivly defined reprs. handle_repr = '<bound method %s.%s of self>' % ( self.__class__.__name__, handle.__name__, ) else: handle_repr = repr(handle) result += ' handle=' + handle_repr except Exception as ex: result += str(ex) or '<error>' return result
Example #16
Source File: baseserver.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def is_fatal_error(self, ex): return isinstance(ex, _socket.error) and ex.args[0] in self.fatal_errors
Example #17
Source File: server.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def do_read(self): try: data, address = self._socket.recvfrom(8192) except _socket.error as err: if err.args[0] == EWOULDBLOCK: return raise return data, address
Example #18
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 #19
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 #20
Source File: resolver_ares.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def _getnameinfo(self, sockaddr, flags): if not isinstance(flags, int): raise TypeError('an integer is required') if not isinstance(sockaddr, tuple): raise TypeError('getnameinfo() argument 1 must be a tuple') address = sockaddr[0] if not PY3 and isinstance(address, text_type): address = address.encode('ascii') if not isinstance(address, string_types): raise TypeError('sockaddr[0] must be a string, not %s' % type(address).__name__) port = sockaddr[1] if not isinstance(port, int): raise TypeError('port must be an integer, not %s' % type(port)) waiter = Waiter(self.hub) result = self._getaddrinfo(address, str(sockaddr[1]), family=AF_UNSPEC, socktype=SOCK_DGRAM) if not result: reraise(*sys.exc_info()) elif len(result) != 1: raise error('sockaddr resolved to multiple addresses') family, socktype, proto, name, address = result[0] if family == AF_INET: if len(sockaddr) != 2: raise error("IPv4 sockaddr must be 2 tuple") elif family == AF_INET6: address = address[:2] + sockaddr[2:] self.ares.getnameinfo(waiter, address, flags) node, service = waiter.get() if service is None: service = '0' return node, service
Example #21
Source File: resolver_ares.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def __call__(self, source): self.count -= 1 if source.exception is None: self.values.append(source.value) else: self.error = source.exception if self.count <= 0: self.waiter.switch()
Example #22
Source File: resolver_ares.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def _resolve_special(hostname, family): if hostname == '': result = getaddrinfo(None, 0, family, SOCK_DGRAM, 0, AI_PASSIVE) if len(result) != 1: raise error('wildcard resolved to multiple address') return result[0][4][0] return hostname
Example #23
Source File: baseserver.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def _formatinfo(self): if hasattr(self, 'socket'): try: fileno = self.socket.fileno() except Exception as ex: fileno = str(ex) result = 'fileno=%s ' % fileno else: result = '' try: if isinstance(self.address, tuple) and len(self.address) == 2: result += 'address=%s:%s' % self.address else: result += 'address=%s' % (self.address, ) except Exception as ex: result += str(ex) or '<error>' handle = self.__dict__.get('handle') if handle is not None: fself = getattr(handle, '__self__', None) try: if fself is self: # Checks the __self__ of the handle in case it is a bound # method of self to prevent recursivly defined reprs. handle_repr = '<bound method %s.%s of self>' % ( self.__class__.__name__, handle.__name__, ) else: handle_repr = repr(handle) result += ' handle=' + handle_repr except Exception as ex: result += str(ex) or '<error>' return result
Example #24
Source File: baseserver.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def is_fatal_error(self, ex): return isinstance(ex, _socket.error) and ex.args[0] in self.fatal_errors
Example #25
Source File: resolver_ares.py From satori with Apache License 2.0 | 5 votes |
def _resolve_special(hostname, family): if hostname == '': result = getaddrinfo(None, 0, family, SOCK_DGRAM, 0, AI_PASSIVE) if len(result) != 1: raise error('wildcard resolved to multiple address') return result[0][4][0] return hostname
Example #26
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 #27
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")
Example #28
Source File: server.py From satori with Apache License 2.0 | 5 votes |
def do_read(self): try: client_socket, address = self.socket.accept() except _socket.error as err: if err.args[0] == EWOULDBLOCK: return raise sockobj = socket(_sock=client_socket) if PYPY: client_socket._drop() return sockobj, address
Example #29
Source File: server.py From satori with Apache License 2.0 | 5 votes |
def do_read(self): try: data, address = self._socket.recvfrom(8192) except _socket.error as err: if err.args[0] == EWOULDBLOCK: return raise return data, address
Example #30
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