Commit 0e63721d authored by Jason Madden's avatar Jason Madden

move compat code to its own module.

parent 4daeb035
......@@ -47,7 +47,8 @@ if sys.platform == 'win32':
import socket # pylint:disable=unused-import,useless-suppression
del socket
from gevent.hub import get_hub, iwait, wait, PYPY
from gevent.hub import get_hub, iwait, wait
from gevent._compat import PYPY
from gevent.greenlet import Greenlet, joinall, killall
joinall = joinall # export for pylint
spawn = Greenlet.spawn
......
# -*- coding: utf-8 -*-
"""
internal gevent python 2/python 3 bridges. Not for external use.
"""
from __future__ import print_function, absolute_import, division
import sys
PY2 = sys.version_info[0] == 2
PY3 = sys.version_info[0] >= 3
PYPY = hasattr(sys, 'pypy_version_info')
## Types
if PY3:
string_types = str,
integer_types = int,
text_type = str
else:
import __builtin__ # pylint:disable=import-error
string_types = __builtin__.basestring,
text_type = __builtin__.unicode
integer_types = (int, __builtin__.long)
## Exceptions
if PY3:
def reraise(t, value, tb=None): # pylint:disable=unused-argument
if value.__traceback__ is not tb:
raise value.with_traceback(tb)
raise value
else:
from gevent._util_py2 import reraise # pylint:disable=import-error,no-name-in-module
reraise = reraise # export
## Functions
if PY3:
iteritems = dict.items
xrange = range
else:
iteritems = dict.iteritems # python 3: pylint:disable=no-member
xrange = __builtin__.xrange # python 2: pylint:disable=redefined-variable-type
......@@ -7,7 +7,7 @@ Python 2 socket module.
import time
from gevent import _socketcommon
from gevent.hub import PYPY
from gevent._compat import PYPY
for key in _socketcommon.__dict__:
if key.startswith('__') or key in _socketcommon.__py3_imports__ or key in _socketcommon.__extensions__:
......
......@@ -70,9 +70,10 @@ __imports__.extend(__py3_imports__)
import sys
from gevent.hub import get_hub, string_types, integer_types
from gevent.hub import get_hub
from gevent.hub import ConcurrentObjectUseError
from gevent.timeout import Timeout
from gevent._compat import string_types, integer_types
is_windows = sys.platform == 'win32'
# pylint:disable=no-name-in-module,unused-import
......
......@@ -21,7 +21,7 @@ from gevent._socket2 import socket
from gevent.socket import _fileobject, timeout_default
from gevent.socket import error as socket_error, EWOULDBLOCK
from gevent.socket import timeout as _socket_timeout
from gevent.hub import string_types, PYPY
from gevent._compat import string_types, PYPY
try:
long
......
......@@ -22,7 +22,7 @@ from gevent._socket2 import socket
from gevent.socket import timeout_default
from gevent.socket import error as socket_error
from gevent.socket import timeout as _socket_timeout
from gevent.hub import PYPY
from gevent._compat import PYPY
__implements__ = [
'SSLContext',
......
......@@ -15,7 +15,7 @@ import heapq
from time import time as _time, sleep as _sleep
from gevent import monkey
from gevent.hub import PY3
from gevent._compat import PY3
__all__ = ['Condition',
......
......@@ -5,7 +5,8 @@ import _socket
import errno
from gevent.greenlet import Greenlet
from gevent.event import Event
from gevent.hub import string_types, integer_types, get_hub, xrange
from gevent.hub import get_hub
from gevent._compat import string_types, integer_types, xrange
__all__ = ['BaseServer']
......
......@@ -2,7 +2,8 @@
"""Basic synchronization primitives: Event and AsyncResult"""
from __future__ import print_function
import sys
from gevent.hub import get_hub, getcurrent, _NONE, reraise
from gevent.hub import get_hub, getcurrent, _NONE
from gevent._compat import reraise
from gevent.hub import InvalidSwitchError
from gevent.timeout import Timeout
from gevent._tblib import dump_traceback, load_traceback
......
......@@ -38,8 +38,8 @@ import sys
import os
from gevent._fileobjectcommon import FileObjectClosed
from gevent.hub import get_hub
from gevent.hub import integer_types
from gevent.hub import reraise
from gevent._compat import integer_types
from gevent._compat import reraise
from gevent.lock import Semaphore, DummySemaphore
......
......@@ -2,19 +2,19 @@
from __future__ import absolute_import
import sys
from greenlet import greenlet
from gevent._compat import PY3
from gevent._compat import PYPY
from gevent._compat import reraise
from gevent._tblib import dump_traceback
from gevent._tblib import load_traceback
from gevent.hub import GreenletExit
from gevent.hub import InvalidSwitchError
from gevent.hub import PY3
from gevent.hub import PYPY
from gevent.hub import Waiter
from gevent.hub import get_hub
from gevent.hub import getcurrent
from gevent.hub import iwait
from gevent.hub import reraise
from gevent.hub import wait
from gevent.timeout import Timeout
from gevent._tblib import dump_traceback
from gevent._tblib import load_traceback
from collections import deque
......
......@@ -26,31 +26,8 @@ __all__ = [
'Waiter',
]
PY2 = sys.version_info[0] == 2
PY3 = sys.version_info[0] >= 3
PYPY = hasattr(sys, 'pypy_version_info')
if PY3:
string_types = str,
integer_types = int,
text_type = str
xrange = range
def reraise(t, value, tb=None): # pylint:disable=unused-argument
if value.__traceback__ is not tb:
raise value.with_traceback(tb)
raise value
else:
import __builtin__ # pylint:disable=import-error
string_types = __builtin__.basestring,
text_type = __builtin__.unicode
integer_types = (int, __builtin__.long)
xrange = __builtin__.xrange # python 2: pylint:disable=redefined-variable-type
from gevent._util_py2 import reraise # pylint:disable=import-error,unused-import,no-name-in-module
from gevent._compat import string_types
from gevent._compat import xrange
if sys.version_info[0] <= 2:
import thread # pylint:disable=import-error
......@@ -447,7 +424,7 @@ def _import(path):
def config(default, envvar):
result = os.environ.get(envvar) or default
result = os.environ.get(envvar) or default # absolute import gets confused pylint: disable=no-member
if isinstance(result, string_types):
return result.split(',')
return result
......
......@@ -138,7 +138,8 @@ affects what we see:
from copy import copy
from weakref import ref
from contextlib import contextmanager
from gevent.hub import getcurrent, PYPY
from gevent.hub import getcurrent
from gevent._compat import PYPY
from gevent.lock import RLock
__all__ = ["local"]
......
......@@ -2,7 +2,8 @@
"""Locking primitives"""
from __future__ import absolute_import
from gevent.hub import getcurrent, PYPY
from gevent.hub import getcurrent
from gevent._compat import PYPY
from gevent._semaphore import Semaphore, BoundedSemaphore # pylint:disable=no-name-in-module,import-error
......
......@@ -45,7 +45,8 @@ from __future__ import absolute_import
import os
import sys
from gevent.hub import get_hub, reinit, PY3
from gevent.hub import get_hub, reinit
from gevent._compat import PY3
import errno
EAGAIN = getattr(errno, 'EAGAIN', 11)
......
......@@ -28,7 +28,8 @@ except ImportError:
from gevent import socket
import gevent
from gevent.server import StreamServer
from gevent.hub import GreenletExit, PY3, reraise
from gevent.hub import GreenletExit
from gevent._compat import PY3, reraise
from functools import partial
if PY3:
......
......@@ -35,7 +35,7 @@ Full = __queue__.Full
Empty = __queue__.Empty
from gevent.timeout import Timeout
from gevent.hub import get_hub, Waiter, getcurrent, PY3
from gevent.hub import get_hub, Waiter, getcurrent
from gevent.hub import InvalidSwitchError
......@@ -347,9 +347,8 @@ class Queue(object):
raise result
return result
if PY3:
__next__ = next
del next
class ItemWaiter(Waiter):
......
......@@ -6,7 +6,8 @@ from __future__ import absolute_import
import os
import sys
from _socket import getservbyname, getaddrinfo, gaierror, error
from gevent.hub import Waiter, get_hub, string_types, text_type, integer_types, reraise, PY3
from gevent.hub import Waiter, get_hub
from gevent._compat import string_types, text_type, integer_types, reraise, PY3
from gevent.socket import AF_UNSPEC, AF_INET, AF_INET6, SOCK_STREAM, SOCK_DGRAM, SOCK_RAW, AI_NUMERICHOST, EAI_SERVICE, AI_PASSIVE
from gevent.ares import channel, InvalidIP # pylint:disable=import-error,no-name-in-module
......
......@@ -3,7 +3,8 @@
Native thread-based hostname resolver.
"""
import _socket
from gevent.hub import get_hub, text_type
from gevent._compat import text_type
from gevent.hub import get_hub
__all__ = ['Resolver']
......
......@@ -5,7 +5,7 @@ Waiting for I/O completion.
from __future__ import absolute_import
from gevent.event import Event
from gevent.hub import get_hub
from gevent.hub import integer_types
from gevent._compat import integer_types
try:
......
......@@ -4,7 +4,7 @@ import sys
import _socket
from gevent.baseserver import BaseServer
from gevent.socket import EWOULDBLOCK, socket
from gevent.hub import PYPY, PY3
from gevent._compat import PYPY, PY3
__all__ = ['StreamServer', 'DatagramServer']
......
......@@ -14,7 +14,7 @@ as well as the constants from the :mod:`socket` module are imported into this mo
# pylint: disable=undefined-variable
import sys
from gevent.hub import PY3
from gevent._compat import PY3
if PY3:
......
"""
Secure Sockets Layer (SSL/TLS) module.
"""
from gevent.hub import PY2
from gevent._compat import PY2
if PY2:
......
......@@ -38,9 +38,10 @@ import signal
import sys
import traceback
from gevent.event import AsyncResult
from gevent.hub import get_hub, linkproxy, sleep, getcurrent, integer_types, string_types, xrange
from gevent.hub import PY3
from gevent.hub import reraise
from gevent.hub import get_hub, linkproxy, sleep, getcurrent
from gevent._compat import integer_types, string_types, xrange
from gevent._compat import PY3
from gevent._compat import reraise
from gevent.fileobject import FileObject
from gevent.greenlet import Greenlet, joinall
spawn = Greenlet.spawn
......
......@@ -30,7 +30,8 @@ else:
'interrupt_main',
'start_new']
error = __thread__.error
from gevent.hub import getcurrent, GreenletExit, PY3
from gevent._compat import PY3
from gevent.hub import getcurrent, GreenletExit
from gevent.greenlet import Greenlet
from gevent.lock import BoundedSemaphore
from gevent.local import local as _local
......
......@@ -16,7 +16,8 @@ import threading as __threading__
_DummyThread_ = __threading__._DummyThread
from gevent.local import local
from gevent.thread import start_new_thread as _start_new_thread, allocate_lock as _allocate_lock, get_ident as _get_ident
from gevent.hub import sleep as _sleep, getcurrent, PYPY
from gevent._compat import PYPY
from gevent.hub import sleep as _sleep, getcurrent
# Exports, prevent unused import warnings
local = local
......
......@@ -2,7 +2,8 @@
from __future__ import absolute_import
import sys
import os
from gevent.hub import get_hub, getcurrent, sleep, integer_types
from gevent._compat import integer_types
from gevent.hub import get_hub, getcurrent, sleep
from gevent.event import AsyncResult
from gevent.greenlet import Greenlet
from gevent.pool import GroupMappingMixin
......
......@@ -14,7 +14,8 @@ module add timeouts to arbitrary code.
which no switches occur, :class:`Timeout` is powerless.
"""
from gevent.hub import getcurrent, _NONE, get_hub, string_types
from gevent._compat import string_types
from gevent.hub import getcurrent, _NONE, get_hub
__all__ = ['Timeout',
'with_timeout']
......
......@@ -23,4 +23,5 @@ exclude_lines =
if PY3:
if sys.platform == 'win32':
if mswindows:
if is_windows:
if sys.version_info.*>=.*3
......@@ -43,7 +43,9 @@ COULD_BE_MISSING = {
'subprocess': ['_posixsubprocess'],
}
NO_ALL = ['gevent.threading', 'gevent._util',
NO_ALL = ['gevent.threading',
'gevent._util',
'gevent._compat',
'gevent._socketcommon',
'gevent._fileobjectcommon', 'gevent._fileobjectposix',
'gevent._tblib',
......
......@@ -47,7 +47,7 @@ except ImportError:
import greentest
import gevent
from gevent.hub import PY3, PYPY
from greentest import PY3, PYPY
from gevent import socket
from gevent import pywsgi
from gevent.pywsgi import Input
......
from __future__ import print_function
import greentest
from gevent.hub import PY3
from greentest import PY3
from gevent import socket
import gevent
from gevent.server import StreamServer
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment