Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions eventlet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
import sys
import warnings

if sys.version_info < (3, 5):
warnings.warn(
"Support for your Python version is deprecated and will be removed in the future",
DeprecationWarning,
)

from eventlet import convenience
from eventlet import event
Expand Down
8 changes: 3 additions & 5 deletions eventlet/backdoor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import print_function

from code import InteractiveConsole
import errno
import socket
Expand All @@ -21,7 +19,7 @@
sys.ps2 = '... '


class FileProxy(object):
class FileProxy:
def __init__(self, f):
self.f = f

Expand All @@ -35,7 +33,7 @@ def write(self, data, *a, **kw):
try:
self.f.write(data, *a, **kw)
self.f.flush()
except socket.error as e:
except OSError as e:
if get_errno(e) != errno.EPIPE:
raise

Expand Down Expand Up @@ -108,7 +106,7 @@ def backdoor_server(sock, locals=None):
try:
socketpair = sock.accept()
backdoor(socketpair, locals)
except socket.error as e:
except OSError as e:
# Broken pipe means it was shutdown
if get_errno(e) != errno.EPIPE:
raise
Expand Down
2 changes: 1 addition & 1 deletion eventlet/convenience.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def listen(addr, family=socket.AF_INET, backlog=50, reuse_addr=True, reuse_port=
try:
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
# OSError is enough on Python 3+
except (OSError, socket.error) as ex:
except OSError as ex:
if support.get_errno(ex) in (22, 92):
# A famous platform defines unsupported socket option.
# https://github.com/eventlet/eventlet/issues/380
Expand Down
2 changes: 1 addition & 1 deletion eventlet/corolocal.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def get_ident():

# the entire purpose of this class is to store off the constructor
# arguments in a local variable without calling __init__ directly
class _localbase(object):
class _localbase:
__slots__ = '_local__args', '_local__greens'

def __new__(cls, *args, **kw):
Expand Down
4 changes: 1 addition & 3 deletions eventlet/coros.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from __future__ import print_function

from eventlet import event as _event


class metaphore(object):
class metaphore:
"""This is sort of an inverse semaphore: a counter that starts at 0 and
waits only if nonzero. It's used to implement a "wait for all" scenario.

Expand Down
29 changes: 14 additions & 15 deletions eventlet/dagpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from eventlet.event import Event
from eventlet import greenthread
import six
import collections


Expand Down Expand Up @@ -39,9 +38,9 @@ class PropagateError(Exception):
"""
def __init__(self, key, exc):
# initialize base class with a reasonable string message
msg = "PropagateError({0}): {1}: {2}" \
msg = "PropagateError({}): {}: {}" \
.format(key, exc.__class__.__name__, exc)
super(PropagateError, self).__init__(msg)
super().__init__(msg)
self.msg = msg
# Unless we set args, this is unpickleable:
# https://bugs.python.org/issue1692335
Expand All @@ -53,7 +52,7 @@ def __str__(self):
return self.msg


class DAGPool(object):
class DAGPool:
"""
A DAGPool is a pool that constrains greenthreads, not by max concurrency,
but by data dependencies.
Expand Down Expand Up @@ -123,7 +122,7 @@ def __init__(self, preload={}):
try:
# If a dict is passed, copy it. Don't risk a subsequent
# modification to passed dict affecting our internal state.
iteritems = six.iteritems(preload)
iteritems = preload.items()
except AttributeError:
# Not a dict, just an iterable of (key, value) pairs
iteritems = preload
Expand Down Expand Up @@ -258,7 +257,7 @@ def _get_keyset_for_wait_each(self, keys):
return set(keys)
else:
# keys arg omitted -- use all the keys we know about
return set(six.iterkeys(self.coros)) | set(six.iterkeys(self.values))
return set(self.coros.keys()) | set(self.values.keys())

def _wait_each(self, pending):
"""
Expand Down Expand Up @@ -394,7 +393,7 @@ def spawn_many(self, depends, function, *args, **kwds):
"""
# Iterate over 'depends' items, relying on self.spawn() not to
# context-switch so no one can modify 'depends' along the way.
for key, deps in six.iteritems(depends):
for key, deps in depends.items():
self.spawn(key, deps, function, *args, **kwds)

def kill(self, key):
Expand Down Expand Up @@ -502,7 +501,7 @@ def keys(self):
"""
# Explicitly return a copy rather than an iterator: don't assume our
# caller will finish iterating before new values are posted.
return tuple(six.iterkeys(self.values))
return tuple(self.values.keys())

def items(self):
"""
Expand All @@ -511,7 +510,7 @@ def items(self):
# Don't assume our caller will finish iterating before new values are
# posted.
return tuple((key, self._value_or_raise(value))
for key, value in six.iteritems(self.values))
for key, value in self.values.items())

def running(self):
"""
Expand All @@ -529,7 +528,7 @@ def running_keys(self):
"""
# return snapshot; don't assume caller will finish iterating before we
# next modify self.coros
return tuple(six.iterkeys(self.coros))
return tuple(self.coros.keys())

def waiting(self):
"""
Expand Down Expand Up @@ -567,7 +566,7 @@ def waiting_for(self, key=_MISSING):
# some or all of those keys, because those greenthreads have not yet
# regained control since values were posted. So make a point of
# excluding values that are now available.
available = set(six.iterkeys(self.values))
available = set(self.values.keys())

if key is not _MISSING:
# waiting_for(key) is semantically different than waiting_for().
Expand Down Expand Up @@ -596,7 +595,7 @@ def waiting_for(self, key=_MISSING):
# are now available. Filter out any pair in which 'pending' is empty,
# that is, that greenthread will be unblocked next time it resumes.
# Make a dict from those pairs.
return dict((key, pending)
for key, pending in ((key, (coro.pending - available))
for key, coro in six.iteritems(self.coros))
if pending)
return {key: pending
for key, pending in ((key, (coro.pending - available))
for key, coro in self.coros.items())
if pending}
18 changes: 7 additions & 11 deletions eventlet/db_pool.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import print_function

from collections import deque
from contextlib import contextmanager
import sys
Expand Down Expand Up @@ -59,9 +57,7 @@ def __init__(self, db_module,
self.connect_timeout = connect_timeout
self._expiration_timer = None
self.cleanup = cleanup
super(BaseConnectionPool, self).__init__(min_size=min_size,
max_size=max_size,
order_as_stack=True)
super().__init__(min_size=min_size, max_size=max_size, order_as_stack=True)

def _schedule_expiration(self):
"""Sets up a timer that will call _expire_old_connections when the
Expand Down Expand Up @@ -173,7 +169,7 @@ def _safe_close(self, conn, quiet=False):
print("Connection.close raised: %s" % (sys.exc_info()[1]))

def get(self):
conn = super(BaseConnectionPool, self).get()
conn = super().get()

# None is a flag value that means that put got called with
# something it couldn't use
Expand Down Expand Up @@ -229,12 +225,12 @@ def put(self, conn, cleanup=_MISSING):
raise

if conn is not None:
super(BaseConnectionPool, self).put((now, created_at, conn))
super().put((now, created_at, conn))
else:
# wake up any waiters with a flag value that indicates
# they need to manufacture a connection
if self.waiting() > 0:
super(BaseConnectionPool, self).put(None)
super().put(None)
else:
# no waiters -- just change the size
self.current_size -= 1
Expand Down Expand Up @@ -308,7 +304,7 @@ def connect(cls, db_module, connect_timeout, *args, **kw):
ConnectionPool = TpooledConnectionPool


class GenericConnectionWrapper(object):
class GenericConnectionWrapper:
def __init__(self, baseconn):
self._base = baseconn

Expand Down Expand Up @@ -386,7 +382,7 @@ class PooledConnectionWrapper(GenericConnectionWrapper):
"""

def __init__(self, baseconn, pool):
super(PooledConnectionWrapper, self).__init__(baseconn)
super().__init__(baseconn)
self._pool = pool

def __nonzero__(self):
Expand Down Expand Up @@ -416,7 +412,7 @@ def __del__(self):
# self.close()


class DatabaseConnector(object):
class DatabaseConnector:
"""
This is an object which will maintain a collection of database
connection pools on a per-host basis.
Expand Down
7 changes: 3 additions & 4 deletions eventlet/debug.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""The debug module contains utilities and functions for better
debugging Eventlet-powered applications."""
from __future__ import print_function

import os
import sys
Expand All @@ -13,10 +12,10 @@
'hub_prevent_multiple_readers', 'hub_timer_stacks',
'hub_blocking_detection']

_token_splitter = re.compile('\W+')
_token_splitter = re.compile(r'\W+')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

raw string looks correct



class Spew(object):
class Spew:

def __init__(self, trace_names=None, show_values=True):
self.trace_names = trace_names
Expand All @@ -37,7 +36,7 @@ def __call__(self, frame, event, arg):
try:
src = inspect.getsourcelines(frame)
line = src[lineno]
except IOError:
except OSError:
line = 'Unknown code named [%s]. VM instruction #%d' % (
frame.f_code.co_name, frame.f_lasti)
if self.trace_names is None or name in self.trace_names:
Expand Down
4 changes: 1 addition & 3 deletions eventlet/event.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import print_function

from eventlet import hubs
from eventlet.support import greenlets as greenlet

Expand All @@ -14,7 +12,7 @@ def __repr__(self):
NOT_USED = NOT_USED()


class Event(object):
class Event:
"""An abstraction where an arbitrary number of coroutines
can wait for one event from another.

Expand Down
3 changes: 1 addition & 2 deletions eventlet/green/BaseHTTPServer.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from eventlet import patcher
from eventlet.green import socket
from eventlet.green import SocketServer
import six

patcher.inject(
'BaseHTTPServer' if six.PY2 else 'http.server',
'http.server',
globals(),
('socket', socket),
('SocketServer', SocketServer),
Expand Down
2 changes: 1 addition & 1 deletion eventlet/green/MySQLdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def Connection(*args, **kw):


# replicate the MySQLdb.connections module but with a tpooled Connection factory
class MySQLdbConnectionsModule(object):
class MySQLdbConnectionsModule:
pass


Expand Down
6 changes: 3 additions & 3 deletions eventlet/green/Queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ class Queue(queue.Queue):
def __init__(self, maxsize=0):
if maxsize == 0:
maxsize = None
super(Queue, self).__init__(maxsize)
super().__init__(maxsize)


class PriorityQueue(queue.PriorityQueue):
def __init__(self, maxsize=0):
if maxsize == 0:
maxsize = None
super(PriorityQueue, self).__init__(maxsize)
super().__init__(maxsize)


class LifoQueue(queue.LifoQueue):
def __init__(self, maxsize=0):
if maxsize == 0:
maxsize = None
super(LifoQueue, self).__init__(maxsize)
super().__init__(maxsize)


Empty = queue.Empty
Expand Down
3 changes: 1 addition & 2 deletions eventlet/green/SocketServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
from eventlet.green import socket
from eventlet.green import select
from eventlet.green import threading
import six

patcher.inject(
'SocketServer' if six.PY2 else 'socketserver',
'socketserver',
globals(),
('socket', socket),
('select', select),
Expand Down
13 changes: 0 additions & 13 deletions eventlet/green/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,14 @@
from eventlet.hubs import hub
from eventlet.patcher import slurp_properties
import sys
import six

__all__ = dir(builtins_orig)
__patched__ = ['open']
if six.PY2:
__patched__ += ['file']

slurp_properties(builtins_orig, globals(),
ignore=__patched__, srckeys=dir(builtins_orig))

hubs.get_hub()

if six.PY2:
__original_file = file

class file(__original_file):
def __init__(self, *args, **kwargs):
super(file, self).__init__(*args, **kwargs)
hubs.notify_opened(self.fileno())


__original_open = open
__opening = False

Expand Down
2 changes: 0 additions & 2 deletions eventlet/green/http/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@
# 8. By copying, installing or otherwise using Python, Licensee
# agrees to be bound by the terms and conditions of this License
# Agreement.
import six
assert six.PY3, 'This is a Python 3 module'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert must not be used in code loaded at runtime, if user call python with the optimization flag, all asserts would be removed, and, so, this kind of code would be removed at runtime.

That's one less to transform.


from enum import IntEnum

Expand Down
Loading