示例#1
0
# Copyright (c) 2018 gevent. See LICENSE for details.
"""
The standard library :mod:`time` module, but :func:`sleep` is
gevent-aware.

.. versionadded:: 1.3a2
"""

from __future__ import absolute_import

__implements__ = [
    'sleep',
]

__all__ = __implements__

import time as __time__

from gevent._util import copy_globals

__imports__ = copy_globals(__time__, globals(), names_to_ignore=__implements__)

from gevent.hub import sleep
sleep = sleep  # pylint
示例#2
0
文件: _ssl3.py 项目: 18965050/gevent
from gevent.socket import timeout as _socket_timeout
from gevent._util import copy_globals

from weakref import ref as _wref

__implements__ = [
    'SSLContext',
    'SSLSocket',
    'wrap_socket',
    'get_server_certificate',
]

# Import all symbols from Python's ssl.py, except those that we are implementing
# and "private" symbols.
__imports__ = copy_globals(__ssl__, globals(),
                           # SSLSocket *must* subclass gevent.socket.socket; see issue 597
                           names_to_ignore=__implements__ + ['socket'],
                           dunder_names_to_keep=())

__all__ = __implements__ + __imports__
if 'namedtuple' in __all__:
    __all__.remove('namedtuple')

orig_SSLContext = __ssl__.SSLContext # pylint:disable=no-member


class SSLContext(orig_SSLContext):
    def wrap_socket(self, sock, server_side=False,
                    do_handshake_on_connect=True,
                    suppress_ragged_eofs=True,
                    server_hostname=None):
        return SSLSocket(sock=sock, server_side=server_side,
示例#3
0
from gevent.event import Event
from gevent.select import _EV_READ
from gevent.select import _EV_WRITE

__implements__ = [
    'DefaultSelector',
]
__extra__ = [
    'GeventSelector',
]
__all__ = __implements__ + __extra__

__imports__ = copy_globals(
    __selectors__,
    globals(),
    names_to_ignore=__all__,
    # Copy __all__; __all__ is defined by selectors2 but not Python 3.
    dunder_names_to_keep=('__all__', ))

_POLL_ALL = _EV_READ | _EV_WRITE

EVENT_READ = __selectors__.EVENT_READ
EVENT_WRITE = __selectors__.EVENT_WRITE
_ALL_EVENTS = EVENT_READ | EVENT_WRITE
SelectorKey = __selectors__.SelectorKey

# In 3.4 and selectors2, BaseSelector is a concrete
# class that can be called. In 3.5 and later, it's an
# ABC, with the real implementation being
# passed to _BaseSelectorImpl.
_BaseSelectorImpl = getattr(__selectors__, '_BaseSelectorImpl',
示例#4
0
from gevent.socket import timeout as _socket_timeout
from gevent._util import copy_globals

from weakref import ref as _wref

__implements__ = [
    'SSLContext',
    'SSLSocket',
    'wrap_socket',
    'get_server_certificate',
]

# Import all symbols from Python's ssl.py, except those that we are implementing
# and "private" symbols.
__imports__ = copy_globals(__ssl__, globals(),
                           # SSLSocket *must* subclass gevent.socket.socket; see issue 597
                           names_to_ignore=__implements__ + ['socket'],
                           dunder_names_to_keep=())

__all__ = __implements__ + __imports__
if 'namedtuple' in __all__:
    __all__.remove('namedtuple')

orig_SSLContext = __ssl__.SSLContext # pylint:disable=no-member


class SSLContext(orig_SSLContext):
    def wrap_socket(self, sock, server_side=False,
                    do_handshake_on_connect=True,
                    suppress_ragged_eofs=True,
                    server_hostname=None,
                    session=None):
示例#5
0
"""
Secure Sockets Layer (SSL/TLS) module.
"""
from gevent._compat import PY2
from gevent._util import copy_globals


# things we expect to override, here for static analysis
def wrap_socket(sock, **kwargs):  # pylint:disable=unused-argument
    raise NotImplementedError()


if PY2:
    if hasattr(__import__('ssl'), 'SSLContext'):
        # It's not sufficient to check for >= 2.7.9; some distributions
        # have backported most of PEP 466. Try to accommodate them. See Issue #702.
        # We're just about to import ssl anyway so it's fine to import it here, just
        # don't pollute the namespace
        from gevent import _sslgte279 as _source
    else:
        from gevent import _ssl2 as _source  # pragma: no cover
else:
    # Py3
    from gevent import _ssl3 as _source  # pragma: no cover

copy_globals(_source, globals())
示例#6
0
# Downstream classes (like pywsgi) know how to handle/ignore EPIPE.
# This set is used by socket.send() to decide whether the write should
# be retried. The default is to retry only on EWOULDBLOCK. Here we add
# EPROTOTYPE on macOS to handle this platform-specific race condition.
GSENDAGAIN = (EWOULDBLOCK, )
if is_macos:
    from errno import EPROTOTYPE
    GSENDAGAIN += (EPROTOTYPE, )

import _socket
_realsocket = _socket.socket
import socket as __socket__

_name = _value = None
__imports__ = copy_globals(__socket__,
                           globals(),
                           only_names=__imports__,
                           ignore_missing_names=True)

for _name in __socket__.__all__:
    _value = getattr(__socket__, _name)
    if isinstance(_value, (integer_types, string_types)):
        globals()[_name] = _value
        __imports__.append(_name)

del _name, _value

_timeout_error = timeout  # pylint: disable=undefined-variable

from gevent import _hub_primitives
_hub_primitives.set_default_timeout_error(_timeout_error)
示例#7
0
    Internal function, called when gevent needs to perform imports
    lazily, but does not know the state of the system. It may be impossible
    to take the import lock because there are no other running greenlets, for
    example. This causes a monkey-patched __import__ to avoid taking any locks.
    until the corresponding call to lock_imports. This should only be done for limited
    amounts of time and when the set of imports is statically known to be "safe".
    """
    global __lock_imports
    # This could easily become a list that we push/pop from or an integer
    # we increment if we need to do this recursively, but we shouldn't get
    # that complex.
    __lock_imports = False


def _lock_imports():
    global __lock_imports
    __lock_imports = True

if sys.version_info[:2] >= (3, 3):
    __implements__ = []
    __import__ = _import
else:
    __implements__ = ['__import__']
__all__ = __implements__


from gevent._util import copy_globals

__imports__ = copy_globals(__gbuiltins__, globals(),
                           names_to_ignore=__implements__)
示例#8
0
文件: select.py 项目: gevent/gevent
try:
    from select import poll as original_poll
    from select import POLLIN, POLLOUT, POLLNVAL
    __implements__ = ['select', 'poll']
except ImportError:
    original_poll = None
    __implements__ = ['select']

__all__ = ['error'] + __implements__

import select as __select__

error = __select__.error

__imports__ = copy_globals(__select__, globals(),
                           names_to_ignore=__all__,
                           dunder_names_to_keep=())

_EV_READ = 1
_EV_WRITE = 2

def get_fileno(obj):
    try:
        fileno_f = obj.fileno
    except AttributeError:
        if not isinstance(obj, integer_types):
            raise TypeError('argument must be an int, or have a fileno() method: %r' % (obj,))
        return obj
    else:
        return fileno_f()
示例#9
0
    lazily, but does not know the state of the system. It may be impossible
    to take the import lock because there are no other running greenlets, for
    example. This causes a monkey-patched __import__ to avoid taking any locks.
    until the corresponding call to lock_imports. This should only be done for limited
    amounts of time and when the set of imports is statically known to be "safe".
    """
    global __lock_imports
    # This could easily become a list that we push/pop from or an integer
    # we increment if we need to do this recursively, but we shouldn't get
    # that complex.
    __lock_imports = False


def _lock_imports():
    global __lock_imports
    __lock_imports = True


if sys.version_info[:2] >= (3, 3):
    __implements__ = []
    __import__ = _import
else:
    __implements__ = ['__import__']
__all__ = __implements__

from gevent._util import copy_globals

__imports__ = copy_globals(__gbuiltins__,
                           globals(),
                           names_to_ignore=__implements__)
示例#10
0
# Copyright (c) 2009-2015 Denis Bilenko and gevent contributors. See LICENSE for details.
from __future__ import absolute_import

import os

from gevent._util import copy_globals

try:
    if os.environ.get('GEVENT_CORE_CFFI_ONLY'):
        raise ImportError("Not attempting corecext")

    from gevent.libev import corecext as _core
except ImportError:
    if os.environ.get('GEVENT_CORE_CEXT_ONLY'):
        raise

    # CFFI/PyPy
    lib = os.environ.get('GEVENT_CORE_CFFI_ONLY')
    if lib == 'libuv':
        from gevent.libuv import loop as _core
    else:
        try:
            from gevent.libev import corecffi as _core
        except ImportError:
            from gevent.libuv import loop as _core

copy_globals(_core, globals())

__all__ = _core.__all__  # pylint:disable=no-member
# define some things we're expecting to overwrite; each module
# needs to define these
__implements__ = __dns__ = __all__ = __extensions__ = __imports__ = ()


class error(Exception):
    errno = None


def getfqdn(*args):
    # pylint:disable=unused-argument
    raise NotImplementedError()

copy_globals(_source, globals(),
             dunder_names_to_keep=('__implements__', '__dns__', '__all__',
                                   '__extensions__', '__imports__', '__socket__'),
             cleanup_globs=False)

# The _socket2 and _socket3 don't import things defined in
# __extensions__, to help avoid confusing reference cycles in the
# documentation and to prevent importing from the wrong place, but we
# *do* need to expose them here. (NOTE: This may lead to some sphinx
# warnings like:
#    WARNING: missing attribute mentioned in :members: or __all__:
#             module gevent._socket2, attribute cancel_wait
# These can be ignored.)
from gevent import _socketcommon
copy_globals(_socketcommon, globals(),
             only_names=_socketcommon.__extensions__)

try:
示例#12
0
文件: ssl.py 项目: 18965050/gevent
"""
Secure Sockets Layer (SSL/TLS) module.
"""
from gevent._compat import PY2
from gevent._util import copy_globals

# things we expect to override, here for static analysis
def wrap_socket(sock, **kwargs): # pylint:disable=unused-argument
    raise NotImplementedError()

if PY2:
    if hasattr(__import__('ssl'), 'SSLContext'):
        # It's not sufficient to check for >= 2.7.9; some distributions
        # have backported most of PEP 466. Try to accommodate them. See Issue #702.
        # We're just about to import ssl anyway so it's fine to import it here, just
        # don't pollute the namespace
        from gevent import _sslgte279 as _source
    else:
        from gevent import _ssl2 as _source # pragma: no cover
else:
    # Py3
    from gevent import _ssl3 as _source # pragma: no cover


copy_globals(_source, globals())
示例#13
0
文件: core.py 项目: 18965050/gevent
# Copyright (c) 2009-2015 Denis Bilenko and gevent contributors. See LICENSE for details.
from __future__ import absolute_import

import os

from gevent._util import copy_globals

try:
    if os.environ.get('GEVENT_CORE_CFFI_ONLY'):
        raise ImportError("Not attempting corecext")

    from gevent.libev import corecext as _core
except ImportError:
    if os.environ.get('GEVENT_CORE_CEXT_ONLY'):
        raise

    # CFFI/PyPy
    from gevent.libev import corecffi as _core

copy_globals(_core, globals())

__all__ = _core.__all__
示例#14
0
文件: socket.py 项目: 18965050/gevent
# define some things we're expecting to overwrite; each module
# needs to define these
__implements__ = __dns__ = __all__ = __extensions__ = __imports__ = ()


class error(Exception):
    errno = None


def getfqdn(*args):
    # pylint:disable=unused-argument
    raise NotImplementedError()

copy_globals(_source, globals(),
             dunder_names_to_keep=('__implements__', '__dns__', '__all__',
                                   '__extensions__', '__imports__', '__socket__'),
             cleanup_globs=False)

# The _socket2 and _socket3 don't import things defined in
# __extensions__, to help avoid confusing reference cycles in the
# documentation and to prevent importing from the wrong place, but we
# *do* need to expose them here. (NOTE: This may lead to some sphinx
# warnings like:
#    WARNING: missing attribute mentioned in :members: or __all__:
#             module gevent._socket2, attribute cancel_wait
# These can be ignored.)
from gevent import _socketcommon
copy_globals(_socketcommon, globals(),
             only_names=_socketcommon.__extensions__)

try:
示例#15
0
# pylint: disable=undefined-variable
# pylint: disable=too-many-statements,too-many-branches
# pylint: disable=too-many-public-methods,unused-argument
from __future__ import absolute_import
import io
import os
import sys

from gevent import _socketcommon
from gevent._util import copy_globals
from gevent._compat import PYPY
import _socket
from os import dup

copy_globals(_socketcommon,
             globals(),
             names_to_ignore=_socketcommon.__extensions__,
             dunder_names_to_keep=())

try:
    from errno import EHOSTUNREACH
    from errno import ECONNREFUSED
except ImportError:
    EHOSTUNREACH = -1
    ECONNREFUSED = -1

__socket__ = _socketcommon.__socket__
__implements__ = _socketcommon._implements
__extensions__ = _socketcommon.__extensions__
__imports__ = _socketcommon.__imports__
__dns__ = _socketcommon.__dns__
示例#16
0
allocate_lock = LockType


def exit():
    raise GreenletExit


if hasattr(__thread__, 'stack_size'):
    _original_stack_size = __thread__.stack_size

    def stack_size(size=None):
        if size is None:
            return _original_stack_size()
        if size > _original_stack_size():
            return _original_stack_size(size)
        else:
            pass
            # not going to decrease stack_size, because otherwise other greenlets in this thread will suffer
else:
    __implements__.remove('stack_size')

__imports__ = copy_globals(__thread__, globals(),
                           only_names=__imports__,
                           ignore_missing_names=True)

__all__ = __implements__ + __imports__
__all__.remove('_local')

# XXX interrupt_main
# XXX _count()
示例#17
0
文件: os.py 项目: 00arthur00/PWM
                but *does not* prepare the parent to wait for the child or receive SIGCHLD.

                This implementation of ``fork`` is a wrapper for :func:`fork_gevent`
                when the environment variable ``GEVENT_NOWAITPID`` *is* defined.
                This is not recommended for most applications.
                """
                return fork_gevent()

            if 'forkpty' in __implements__:
                def forkpty():
                    """
                    Like :func:`fork`, but using :func:`os.forkpty`

                    This implementation of ``forkpty`` is a wrapper for :func:`forkpty_gevent`
                    when the environment variable ``GEVENT_NOWAITPID`` *is* defined.
                    This is not recommended for most applications.

                    .. versionadded:: 1.1b5
                    """
                    return forkpty_gevent()
            __extensions__.append("waitpid")

else:
    __implements__.remove('fork')

__imports__ = copy_globals(os, globals(),
                           names_to_ignore=__implements__ + __extensions__,
                           dunder_names_to_keep=())

__all__ = list(set(__implements__ + __extensions__))
示例#18
0
# pylint: disable=too-many-public-methods,unused-argument
from __future__ import absolute_import
import io
import os
import sys

from gevent import _socketcommon
from gevent._util import copy_globals
from gevent._compat import PYPY
from gevent.timeout import Timeout
import _socket
from os import dup


copy_globals(_socketcommon, globals(),
             names_to_ignore=_socketcommon.__extensions__,
             dunder_names_to_keep=())

try:
    from errno import EHOSTUNREACH
    from errno import ECONNREFUSED
except ImportError:
    EHOSTUNREACH = -1
    ECONNREFUSED = -1


__socket__ = _socketcommon.__socket__
__implements__ = _socketcommon._implements
__extensions__ = _socketcommon.__extensions__
__imports__ = _socketcommon.__imports__
__dns__ = _socketcommon.__dns__
示例#19
0
try:
    from select import poll as original_poll
    from select import POLLIN, POLLOUT, POLLNVAL
    __implements__ = ['select', 'poll']
except ImportError:
    original_poll = None
    __implements__ = ['select']

__all__ = ['error'] + __implements__

import select as __select__

error = __select__.error

__imports__ = copy_globals(__select__,
                           globals(),
                           names_to_ignore=__all__,
                           dunder_names_to_keep=())

_EV_READ = 1
_EV_WRITE = 2


def get_fileno(obj):
    try:
        fileno_f = obj.fileno
    except AttributeError:
        if not isinstance(obj, integer_types):
            raise TypeError(
                'argument must be an int, or have a fileno() method: %r' %
                (obj, ))
        return obj
示例#20
0
文件: time.py 项目: gevent/gevent
# Copyright (c) 2018 gevent. See LICENSE for details.
"""
The standard library :mod:`time` module, but :func:`sleep` is
gevent-aware.

.. versionadded:: 1.3a2
"""

from __future__ import absolute_import

__implements__ = [
    'sleep',
]

__all__ = __implements__

import time as __time__

from gevent._util import copy_globals

__imports__ = copy_globals(__time__, globals(),
                           names_to_ignore=__implements__)



from gevent.hub import sleep
sleep = sleep # pylint