Exemplo n.º 1
0
    def accept(self):
        fd = self.fd
        while True:
            res = socket_accept(fd)
            if res is not None:
                client, addr = res
                notify_opened(client.fileno())

                if not self.is_ssl:
                    return UltraGreenSocket(fd=client), addr

                new_ssl = ssl.SSLSocket(
                    client,
                    keyfile=fd.keyfile,
                    certfile=fd.certfile,
                    server_side=True,
                    cert_reqs=fd.cert_reqs,
                    ssl_version=fd.ssl_version,
                    ca_certs=fd.ca_certs,
                    do_handshake_on_connect=False,
                    suppress_ragged_eofs=fd.suppress_ragged_eofs)
                fd = UltraGreenSocket(fd=new_ssl)
                fd.do_handshake()
                return fd, addr

            self._trampoline(read=True,
                             timeout=self._timeout,
                             timeout_exc=timeout_exc)
Exemplo n.º 2
0
def open(file, flags, mode=0o777):
    """ Wrap os.open
        This behaves identically, but collaborates with
        the hub's notify_opened protocol.
    """
    fd = __original_open__(file, flags, mode)
    hubs.notify_opened(fd)
    return fd
Exemplo n.º 3
0
def open(file, flags, mode=0777):
    """ Wrap os.open
        This behaves identically, but collaborates with
        the hub's notify_opened protocol.
    """
    fd = __original_open__(file, flags, mode)
    hubs.notify_opened(fd)
    return fd
Exemplo n.º 4
0
def open(file, flags, mode=0o777, dir_fd=None):
    """ Wrap os.open
        This behaves identically, but collaborates with
        the hub's notify_opened protocol.
    """
    if dir_fd is not None:
        fd = __original_open__(file, flags, mode, dir_fd=dir_fd)
    else:
        fd = __original_open__(file, flags, mode)
    hubs.notify_opened(fd)
    return fd
Exemplo n.º 5
0
def open(file, flags, mode=0o777, dir_fd=None):
    """ Wrap os.open
        This behaves identically, but collaborates with
        the hub's notify_opened protocol.
    """
    if dir_fd is not None:
        fd = __original_open__(file, flags, mode, dir_fd=dir_fd)
    else:
        fd = __original_open__(file, flags, mode)
    hubs.notify_opened(fd)
    return fd
Exemplo n.º 6
0
def open(*args):
    global __opening
    result = __original_open(*args)
    if not __opening:
        # This is incredibly ugly. 'open' is used under the hood by
        # the import process. So, ensure we don't wind up in an
        # infinite loop.
        __opening = True
        hubs.notify_opened(result.fileno())
        __opening = False
    return result
Exemplo n.º 7
0
def open(*args, **kwargs):
    global __opening
    result = __original_open(*args, **kwargs)
    if not __opening:
        # This is incredibly ugly. 'open' is used under the hood by
        # the import process. So, ensure we don't wind up in an
        # infinite loop.
        __opening = True
        hubs.notify_opened(result.fileno())
        __opening = False
    return result
Exemplo n.º 8
0
    def __init__(self, family=socket.AF_INET, *args, **kwargs):
        self._closed = True
        self._timeout = kwargs.pop('timeout', None)

        fd = kwargs.pop('fd', None)
        if fd is None:
            fd = socket.socket(family, *args, **kwargs)
            # Notify the hub that this is a newly-opened socket.
            notify_opened(fd.fileno())

        self._setup(fd, self._timeout)
Exemplo n.º 9
0
 def accept(self):
     if self.act_non_blocking:
         res = self.fd.accept()
         notify_opened(res[0].fileno())
         return res
     fd = self.fd
     _timeout_exc = socket_timeout('timed out')
     while True:
         res = socket_accept(fd)
         if res is not None:
             client, addr = res
             notify_opened(client.fileno())
             set_nonblocking(client)
             return type(self)(client), addr
         self._trampoline(fd, read=True, timeout=self.gettimeout(), timeout_exc=_timeout_exc)
Exemplo n.º 10
0
 def accept(self):
     if self.act_non_blocking:
         res = self.fd.accept()
         notify_opened(res[0].fileno())
         return res
     fd = self.fd
     _timeout_exc = socket_timeout('timed out')
     while True:
         res = socket_accept(fd)
         if res is not None:
             client, addr = res
             notify_opened(client.fileno())
             set_nonblocking(client)
             return type(self)(client), addr
         self._trampoline(fd, read=True, timeout=self.gettimeout(), timeout_exc=_timeout_exc)
Exemplo n.º 11
0
    def __init__(self, name, mode='r', closefd=True, opener=None):
        if isinstance(name, int):
            fileno = name
            self._name = "<fd:%d>" % fileno
        else:
            assert isinstance(name, six.string_types)
            with open(name, mode) as fd:
                self._name = fd.name
                fileno = _original_os.dup(fd.fileno())

        notify_opened(fileno)
        self._fileno = fileno
        self._mode = mode
        self._closed = False
        set_nonblocking(self)
        self._seekable = None
Exemplo n.º 12
0
    def __init__(self, name, mode='r', closefd=True, opener=None):
        if isinstance(name, int):
            fileno = name
            self._name = "<fd:%d>" % fileno
        else:
            assert isinstance(name, six.string_types)
            with open(name, mode) as fd:
                self._name = fd.name
                fileno = _original_os.dup(fd.fileno())

        notify_opened(fileno)
        self._fileno = fileno
        self._mode = mode
        self._closed = False
        set_nonblocking(self)
        self._seekable = None
Exemplo n.º 13
0
Arquivo: os.py Projeto: Liu0330/zufang
def open(file, flags, mode=0o777, dir_fd=None):
    """ Wrap os.open
        This behaves identically, but collaborates with
        the hub's notify_opened protocol.
    """
    # pathlib workaround #534 pathlib._NormalAccessor wraps `open` in
    # `staticmethod` for py < 3.7 but not 3.7. That means we get here with
    # `file` being a pathlib._NormalAccessor object, and the other arguments
    # shifted.  Fortunately pathlib doesn't use the `dir_fd` argument, so we
    # have space in the parameter list. We use some heuristics to detect this
    # and adjust the parameters (without importing pathlib)
    if type(file).__name__ == '_NormalAccessor':
        file, flags, mode, dir_fd = flags, mode, dir_fd, None

    if dir_fd is not None:
        fd = __original_open__(file, flags, mode, dir_fd=dir_fd)
    else:
        fd = __original_open__(file, flags, mode)
    hubs.notify_opened(fd)
    return fd
Exemplo n.º 14
0
    def __init__(self, family=socket.AF_INET, *args, **kwargs):
        should_set_nonblocking = kwargs.pop('set_nonblocking', True)
        if isinstance(family, six.integer_types):
            fd = _original_socket(family, *args, **kwargs)
            # Notify the hub that this is a newly-opened socket.
            notify_opened(fd.fileno())
        else:
            fd = family

        # import timeout from other socket, if it was there
        try:
            self._timeout = fd.gettimeout() or socket.getdefaulttimeout()
        except AttributeError:
            self._timeout = socket.getdefaulttimeout()

        # Filter fd.fileno() != -1 so that won't call set non-blocking on
        # closed socket
        if should_set_nonblocking and fd.fileno() != -1:
            set_nonblocking(fd)
        self.fd = fd
        # when client calls setblocking(0) or settimeout(0) the socket must
        # act non-blocking
        self.act_non_blocking = False

        # Copy some attributes from underlying real socket.
        # This is the easiest way that i found to fix
        # https://bitbucket.org/eventlet/eventlet/issue/136
        # Only `getsockopt` is required to fix that issue, others
        # are just premature optimization to save __getattr__ call.
        self.bind = fd.bind
        self.close = fd.close
        self.fileno = fd.fileno
        self.getsockname = fd.getsockname
        self.getsockopt = fd.getsockopt
        self.listen = fd.listen
        self.setsockopt = fd.setsockopt
        self.shutdown = fd.shutdown
        self._closed = False
Exemplo n.º 15
0
    def __init__(self, family=socket.AF_INET, *args, **kwargs):
        should_set_nonblocking = kwargs.pop('set_nonblocking', True)
        if isinstance(family, six.integer_types):
            fd = _original_socket(family, *args, **kwargs)
            # Notify the hub that this is a newly-opened socket.
            notify_opened(fd.fileno())
        else:
            fd = family

        # import timeout from other socket, if it was there
        try:
            self._timeout = fd.gettimeout() or socket.getdefaulttimeout()
        except AttributeError:
            self._timeout = socket.getdefaulttimeout()

        # Filter fd.fileno() != -1 so that won't call set non-blocking on
        # closed socket
        if should_set_nonblocking and fd.fileno() != -1:
            set_nonblocking(fd)
        self.fd = fd
        # when client calls setblocking(0) or settimeout(0) the socket must
        # act non-blocking
        self.act_non_blocking = False

        # Copy some attributes from underlying real socket.
        # This is the easiest way that i found to fix
        # https://bitbucket.org/eventlet/eventlet/issue/136
        # Only `getsockopt` is required to fix that issue, others
        # are just premature optimization to save __getattr__ call.
        self.bind = fd.bind
        self.close = fd.close
        self.fileno = fd.fileno
        self.getsockname = fd.getsockname
        self.getsockopt = fd.getsockopt
        self.listen = fd.listen
        self.setsockopt = fd.setsockopt
        self.shutdown = fd.shutdown
        self._closed = False
Exemplo n.º 16
0
 def __init__(self, fileno):
     self._fileno = fileno
     notify_opened(fileno)
     self._closed = False
Exemplo n.º 17
0
 def __init__(self, *args, **kwargs):
     super(file, self).__init__(*args, **kwargs)
     hubs.notify_opened(self.fileno())
Exemplo n.º 18
0
 def __init__(self, fileno):
     self._fileno = fileno
     notify_opened(fileno)
     self._closed = False
Exemplo n.º 19
0
 def __init__(self, semaphore=True):
     self._fd = int(
         eventfd_create(0,
                        EV_FLAGS if semaphore else eventfd_c.EFD_NONBLOCK))
     notify_opened(self._fd)
Exemplo n.º 20
0
 def __init__(self, *args, **kwargs):
     super(file, self).__init__(*args, **kwargs)
     hubs.notify_opened(self.fileno())