Python errno.ENOTSOCK Examples
The following are 30
code examples of errno.ENOTSOCK().
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
errno
, or try the search function
.
Example #1
Source File: core.py From daemonocle with MIT License | 6 votes |
def _is_socket(cls, stream): """Check if the given stream is a socket.""" try: fd = stream.fileno() except ValueError: # If it has no file descriptor, it's not a socket return False sock = socket.fromfd(fd, socket.AF_INET, socket.SOCK_RAW) try: # This will raise a socket.error if it's not a socket sock.getsockopt(socket.SOL_SOCKET, socket.SO_TYPE) except socket.error as ex: if ex.args[0] != errno.ENOTSOCK: # It must be a socket return True else: # If an exception wasn't raised, it's a socket return True
Example #2
Source File: libirc.py From tg-irc-relay with GNU Lesser General Public License v3.0 | 6 votes |
def send(self, sendbuf=None): '''Flush the send buffer.''' self.acquire_lock() try: if not self.sock: e = socket.error( '[errno %d] Socket operation on non-socket' % errno.ENOTSOCK) e.errno = errno.ENOTSOCK raise e try: if sendbuf is None: if self.sendbuf: self.sock.sendall(self.sendbuf) self.sendbuf = b'' elif sendbuf: self.sock.sendall(sendbuf) except socket.error as e: try: self.sock.close() finally: self.sock = None raise self.quit('Network error.', wait=False) finally: self.lock.release()
Example #3
Source File: linux.py From manticore with GNU Affero General Public License v3.0 | 6 votes |
def sys_recv(self, sockfd: int, buf: int, count: int, flags: int, trace_str="_recv") -> int: if not self.current.memory.access_ok(slice(buf, buf + count), "w"): logger.info("RECV: buf within invalid memory. Returning -errno.EFAULT") return -errno.EFAULT try: sock = self._get_fdlike(sockfd) except FdError: return -errno.EBADF if not isinstance(sock, Socket): return -errno.ENOTSOCK data = sock.read(count) if len(data) == 0: return 0 self.syscall_trace.append((trace_str, sockfd, data)) self.current.write_bytes(buf, data) return len(data)
Example #4
Source File: daemon.py From luscan-devel with GNU General Public License v2.0 | 6 votes |
def is_socket(fd): """ Determine if the file descriptor is a socket. Return ``False`` if querying the socket type of `fd` raises an error; otherwise return ``True``. """ result = False file_socket = socket.fromfd(fd, socket.AF_INET, socket.SOCK_RAW) try: socket_type = file_socket.getsockopt( socket.SOL_SOCKET, socket.SO_TYPE) except socket.error, exc: exc_errno = exc.args[0] if exc_errno == errno.ENOTSOCK: # Socket operation on non-socket pass else: # Some other socket error result = True
Example #5
Source File: test_llcp_llc.py From nfcpy with European Union Public License 1.1 | 6 votes |
def test_accept_connect(self, llc, ldl, dlc, peer_miu, send_miu): with pytest.raises(nfc.llcp.Error) as excinfo: llc.accept(object()) assert excinfo.value.errno == errno.ENOTSOCK with pytest.raises(nfc.llcp.Error) as excinfo: llc.accept(ldl) assert excinfo.value.errno == errno.EOPNOTSUPP with pytest.raises(nfc.llcp.Error) as excinfo: llc.accept(dlc) assert excinfo.value.errno == errno.EINVAL connect_pdu = nfc.llcp.pdu.Connect(4, 32, peer_miu) threading.Timer(0.01, llc.dispatch, (connect_pdu,)).start() llc.bind(dlc, b'urn:nfc:sn:snep') llc.listen(dlc, 0) sock = llc.accept(dlc) assert isinstance(sock, nfc.llcp.tco.DataLinkConnection) assert llc.getsockopt(sock, nfc.llcp.SO_SNDMIU) == send_miu assert llc.getpeername(sock) == 32 assert llc.getsockname(sock) == 4
Example #6
Source File: test_llcp_llc.py From nfcpy with European Union Public License 1.1 | 6 votes |
def test_listen(self, llc, ldl, dlc, bind): with pytest.raises(nfc.llcp.Error) as excinfo: llc.listen(object(), 0) assert excinfo.value.errno == errno.ENOTSOCK with pytest.raises(nfc.llcp.Error) as excinfo: llc.listen(ldl, 0) assert excinfo.value.errno == errno.EOPNOTSUPP with pytest.raises(TypeError) as excinfo: llc.listen(dlc, 0.1) assert str(excinfo.value) == "backlog must be int type" with pytest.raises(ValueError) as excinfo: llc.listen(dlc, -1) assert str(excinfo.value) == "backlog can not be negative" if bind: llc.bind(dlc) llc.listen(dlc, 0) assert dlc.state.LISTEN is True
Example #7
Source File: llc.py From nfcpy with European Union Public License 1.1 | 6 votes |
def sendto(self, socket, message, dest, flags): if not isinstance(socket, tco.TransmissionControlObject): raise err.Error(errno.ENOTSOCK) if isinstance(socket, tco.RawAccessPoint): if not isinstance(message, pdu.ProtocolDataUnit): raise TypeError("on a raw access point message must be a pdu") if not socket.is_bound: self.bind(socket) # FIXME: set socket send miu when activated socket.send_miu = self.cfg['send-miu'] return socket.send(message, flags) if not isinstance(message, (bytes, bytearray)): raise TypeError("message data must be a bytes-like object") if isinstance(socket, tco.LogicalDataLink): if dest is None: raise err.Error(errno.EDESTADDRREQ) if not socket.is_bound: self.bind(socket) # FIXME: set socket send miu when activated socket.send_miu = self.cfg['send-miu'] return socket.sendto(message, dest, flags) if isinstance(socket, tco.DataLinkConnection): return socket.send(message, flags)
Example #8
Source File: fcgi.py From termite-visualizations with BSD 3-Clause "New" or "Revised" License | 6 votes |
def _setupSocket(self): if self._bindAddress is None: # Run as a normal FastCGI? isFCGI = True sock = socket.fromfd(FCGI_LISTENSOCK_FILENO, socket.AF_INET, socket.SOCK_STREAM) try: sock.getpeername() except socket.error, e: if e[0] == errno.ENOTSOCK: # Not a socket, assume CGI context. isFCGI = False elif e[0] != errno.ENOTCONN: raise # FastCGI/CGI discrimination is broken on Mac OS X. # Set the environment variable FCGI_FORCE_CGI to "Y" or "y" # if you want to run your app as a simple CGI. (You can do # this with Apache's mod_env [not loaded by default in OS X # client, ha ha] and the SetEnv directive.) if not isFCGI or \ os.environ.get('FCGI_FORCE_CGI', 'N').upper().startswith('Y'): req = self.cgirequest_class(self) req.run() sys.exit(0)
Example #9
Source File: error.py From libnl with GNU Lesser General Public License v2.1 | 5 votes |
def nl_syserr2nlerr(error_): """https://github.com/thom311/libnl/blob/libnl3_2_25/lib/error.c#L84.""" error_ = abs(error_) legend = { errno.EBADF: libnl.errno_.NLE_BAD_SOCK, errno.EADDRINUSE: libnl.errno_.NLE_EXIST, errno.EEXIST: libnl.errno_.NLE_EXIST, errno.EADDRNOTAVAIL: libnl.errno_.NLE_NOADDR, errno.ESRCH: libnl.errno_.NLE_OBJ_NOTFOUND, errno.ENOENT: libnl.errno_.NLE_OBJ_NOTFOUND, errno.EINTR: libnl.errno_.NLE_INTR, errno.EAGAIN: libnl.errno_.NLE_AGAIN, errno.ENOTSOCK: libnl.errno_.NLE_BAD_SOCK, errno.ENOPROTOOPT: libnl.errno_.NLE_INVAL, errno.EFAULT: libnl.errno_.NLE_INVAL, errno.EACCES: libnl.errno_.NLE_NOACCESS, errno.EINVAL: libnl.errno_.NLE_INVAL, errno.ENOBUFS: libnl.errno_.NLE_NOMEM, errno.ENOMEM: libnl.errno_.NLE_NOMEM, errno.EAFNOSUPPORT: libnl.errno_.NLE_AF_NOSUPPORT, errno.EPROTONOSUPPORT: libnl.errno_.NLE_PROTO_MISMATCH, errno.EOPNOTSUPP: libnl.errno_.NLE_OPNOTSUPP, errno.EPERM: libnl.errno_.NLE_PERM, errno.EBUSY: libnl.errno_.NLE_BUSY, errno.ERANGE: libnl.errno_.NLE_RANGE, errno.ENODEV: libnl.errno_.NLE_NODEV, } return int(legend.get(error_, libnl.errno_.NLE_FAILURE))
Example #10
Source File: mainwindow.py From tellurium with Apache License 2.0 | 5 votes |
def start_open_files_server(self): self.open_files_server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) port = select_port(default_port=OPEN_FILES_PORT) CONF.set('main', 'open_files_port', port) self.open_files_server.bind(('127.0.0.1', port)) self.open_files_server.listen(20) while 1: # 1 is faster than True try: req, dummy = self.open_files_server.accept() except socket.error as e: # See Issue 1275 for details on why errno EINTR is # silently ignored here. eintr = errno.WSAEINTR if os.name == 'nt' else errno.EINTR # To avoid a traceback after closing on Windows if e.args[0] == eintr: continue # handle a connection abort on close error enotsock = (errno.WSAENOTSOCK if os.name == 'nt' else errno.ENOTSOCK) if e.args[0] in [errno.ECONNABORTED, enotsock]: return raise fname = req.recv(1024) fname = fname.decode('utf-8') self.sig_open_external_file.emit(fname) req.sendall(b' ') # ---- Quit and restart, and reset spyder defaults
Example #11
Source File: mainwindow.py From tellurium with Apache License 2.0 | 5 votes |
def start_open_files_server(self): self.open_files_server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) port = select_port(default_port=OPEN_FILES_PORT) CONF.set('main', 'open_files_port', port) self.open_files_server.bind(('127.0.0.1', port)) self.open_files_server.listen(20) while 1: # 1 is faster than True try: req, dummy = self.open_files_server.accept() except socket.error as e: # See Issue 1275 for details on why errno EINTR is # silently ignored here. eintr = errno.WSAEINTR if os.name == 'nt' else errno.EINTR # To avoid a traceback after closing on Windows if e.args[0] == eintr: continue # handle a connection abort on close error enotsock = (errno.WSAENOTSOCK if os.name == 'nt' else errno.ENOTSOCK) if e.args[0] in [errno.ECONNABORTED, enotsock]: return raise fname = req.recv(1024) fname = fname.decode('utf-8') self.sig_open_external_file.emit(fname) req.sendall(b' ') # ---- Quit and restart, and reset spyder defaults
Example #12
Source File: parallel.py From dataflow with Apache License 2.0 | 5 votes |
def _zmq_catch_error(name): try: yield except zmq.ContextTerminated: logger.info("[{}] Context terminated.".format(name)) raise DataFlowTerminated() except zmq.ZMQError as e: if e.errno == errno.ENOTSOCK: # socket closed logger.info("[{}] Socket closed.".format(name)) raise DataFlowTerminated() else: raise except Exception: raise
Example #13
Source File: daemon.py From virt-who with GNU General Public License v2.0 | 5 votes |
def is_socket(fd): """ Determine if the file descriptor is a socket. Return ``False`` if querying the socket type of `fd` raises an error; otherwise return ``True``. """ result = False file_socket = socket.fromfd(fd, socket.AF_INET, socket.SOCK_RAW) try: file_socket.getsockopt( socket.SOL_SOCKET, socket.SO_TYPE) except socket.error as exc: exc_errno = exc.args[0] if exc_errno == errno.ENOTSOCK: # Socket operation on non-socket pass else: # Some other socket error result = True else: # No error getting socket type result = True return result
Example #14
Source File: select.py From medicare-demo with Apache License 2.0 | 5 votes |
def _getselectable(selectable_object): try: channel = selectable_object.getchannel() except: try: channel = selectable_object.fileno().getChannel() except: raise TypeError("Object '%s' is not watchable" % selectable_object, errno.ENOTSOCK) if channel and not isinstance(channel, java.nio.channels.SelectableChannel): raise TypeError("Object '%s' is not watchable" % selectable_object, errno.ENOTSOCK) return channel
Example #15
Source File: data_provider.py From PoseFix_RELEASE with MIT License | 5 votes |
def _zmq_catch_error(name): try: yield except zmq.ContextTerminated: print("[{}] Context terminated.".format(name)) raise Exception except zmq.ZMQError as e: if e.errno == errno.ENOTSOCK: # socket closed print("[{}] Socket closed.".format(name)) raise Exception else: raise except Exception: raise
Example #16
Source File: parallel.py From ADL with MIT License | 5 votes |
def _zmq_catch_error(name): try: yield except zmq.ContextTerminated: logger.info("[{}] Context terminated.".format(name)) raise DataFlowTerminated() except zmq.ZMQError as e: if e.errno == errno.ENOTSOCK: # socket closed logger.info("[{}] Socket closed.".format(name)) raise DataFlowTerminated() else: raise except Exception: raise
Example #17
Source File: data_provider.py From lighttrack with MIT License | 5 votes |
def _zmq_catch_error(name): try: yield except zmq.ContextTerminated: print("[{}] Context terminated.".format(name)) raise Exception except zmq.ZMQError as e: if e.errno == errno.ENOTSOCK: # socket closed print("[{}] Socket closed.".format(name)) raise Exception else: raise except Exception: raise
Example #18
Source File: linux.py From manticore with GNU Affero General Public License v3.0 | 5 votes |
def sys_send(self, sockfd, buf, count, flags) -> int: try: sock = self.fd_table.get_fdlike(sockfd) except FdError as e: return -e.err if not isinstance(sock, Socket): return -errno.ENOTSOCK data = self.current.read_bytes(buf, count) # XXX(yan): send(2) is currently a nop; we don't communicate yet self.syscall_trace.append(("_send", sockfd, data)) return count
Example #19
Source File: data_provider.py From video-to-pose3D with MIT License | 5 votes |
def _zmq_catch_error(name): try: yield except zmq.ContextTerminated: print("[{}] Context terminated.".format(name)) raise Exception except zmq.ZMQError as e: if e.errno == errno.ENOTSOCK: # socket closed print("[{}] Socket closed.".format(name)) raise Exception else: raise except Exception: raise
Example #20
Source File: linux.py From manticore with GNU Affero General Public License v3.0 | 5 votes |
def _is_sockfd(self, sockfd: int) -> int: try: fd = self._get_fdlike(sockfd) if not isinstance(fd, SocketDesc): return -errno.ENOTSOCK return 0 except IndexError: return -errno.EBADF
Example #21
Source File: parallel.py From tensorpack with Apache License 2.0 | 5 votes |
def _zmq_catch_error(name): try: yield except zmq.ContextTerminated: logger.info("[{}] Context terminated.".format(name)) raise DataFlowTerminated() except zmq.ZMQError as e: if e.errno == errno.ENOTSOCK: # socket closed logger.info("[{}] Socket closed.".format(name)) raise DataFlowTerminated() else: raise except Exception: raise
Example #22
Source File: llc.py From nfcpy with European Union Public License 1.1 | 5 votes |
def close(self, socket): if not isinstance(socket, tco.TransmissionControlObject): raise err.Error(errno.ENOTSOCK) if socket.is_bound: self.sap[socket.addr].remove_socket(socket) else: socket.close()
Example #23
Source File: select.py From jawfish with MIT License | 5 votes |
def _getselectable(selectable_object): try: channel = selectable_object.getchannel() except: try: channel = selectable_object.fileno().getChannel() except: raise TypeError("Object '%s' is not watchable" % selectable_object, errno.ENOTSOCK) if channel and not isinstance(channel, java.nio.channels.SelectableChannel): raise TypeError("Object '%s' is not watchable" % selectable_object, errno.ENOTSOCK) return channel
Example #24
Source File: llc.py From nfcpy with European Union Public License 1.1 | 5 votes |
def setsockopt(self, socket, option, value): if not isinstance(socket, tco.TransmissionControlObject): raise err.Error(errno.ENOTSOCK) if option == nfc.llcp.SO_RCVMIU: value = min(value, self.cfg['recv-miu']) socket.setsockopt(option, value) return socket.getsockopt(option)
Example #25
Source File: llc.py From nfcpy with European Union Public License 1.1 | 5 votes |
def getsockopt(self, socket, option): if not isinstance(socket, tco.TransmissionControlObject): raise err.Error(errno.ENOTSOCK) if isinstance(socket, tco.LogicalDataLink): # FIXME: set socket send miu when activated socket.send_miu = self.cfg['send-miu'] if isinstance(socket, tco.RawAccessPoint): # FIXME: set socket send miu when activated socket.send_miu = self.cfg['send-miu'] return socket.getsockopt(option)
Example #26
Source File: llc.py From nfcpy with European Union Public License 1.1 | 5 votes |
def bind(self, socket, addr_or_name=None): if not isinstance(socket, tco.TransmissionControlObject): raise err.Error(errno.ENOTSOCK) if socket.addr is not None: raise err.Error(errno.EINVAL) if addr_or_name is None: self._bind_by_none(socket) elif isinstance(addr_or_name, int): self._bind_by_addr(socket, addr_or_name) elif isinstance(addr_or_name, (bytes, bytearray)): self._bind_by_name(socket, bytes(addr_or_name)) elif isinstance(addr_or_name, str): self._bind_by_name(socket, addr_or_name.encode('latin')) else: raise err.Error(errno.EFAULT)
Example #27
Source File: llc.py From nfcpy with European Union Public License 1.1 | 5 votes |
def connect(self, socket, dest): if not isinstance(socket, tco.TransmissionControlObject): raise err.Error(errno.ENOTSOCK) if not socket.is_bound: self.bind(socket) socket.connect(dest) log.debug("connected ({0} ===> {1})".format(socket.addr, socket.peer)) if socket.send_miu > self.cfg['send-miu']: log.warning("reducing outbound miu to not exceed the link miu") socket.send_miu = self.cfg['send-miu']
Example #28
Source File: llc.py From nfcpy with European Union Public License 1.1 | 5 votes |
def listen(self, socket, backlog): if not isinstance(socket, tco.TransmissionControlObject): raise err.Error(errno.ENOTSOCK) if not isinstance(socket, tco.DataLinkConnection): raise err.Error(errno.EOPNOTSUPP) if not isinstance(backlog, int): raise TypeError("backlog must be int type") if backlog < 0: raise ValueError("backlog can not be negative") backlog = min(backlog, 16) if not socket.is_bound: self.bind(socket) socket.listen(backlog)
Example #29
Source File: llc.py From nfcpy with European Union Public License 1.1 | 5 votes |
def recvfrom(self, socket): if not isinstance(socket, tco.TransmissionControlObject): raise err.Error(errno.ENOTSOCK) if not (socket.addr and self.sap[socket.addr]): raise err.Error(errno.EBADF) if isinstance(socket, tco.RawAccessPoint): return (socket.recv(), None) if isinstance(socket, tco.LogicalDataLink): return socket.recvfrom() if isinstance(socket, tco.DataLinkConnection): return (socket.recv(), socket.peer)
Example #30
Source File: llc.py From nfcpy with European Union Public License 1.1 | 5 votes |
def poll(self, socket, event, timeout=None): if not isinstance(socket, tco.TransmissionControlObject): raise err.Error(errno.ENOTSOCK) if not (socket.addr and self.sap[socket.addr]): raise err.Error(errno.EBADF) return socket.poll(event, timeout)