Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Code formatting and cleanups

  • Loading branch information...
commit dec954c289fc4771c8157ec79cf400880a71c2f5 1 parent e43e809
Alvaro authored
View
5 evy/api.py
@@ -35,7 +35,7 @@
from evy import debug
__all__ = [
- 'call_after', 'exc_after', 'getcurrent', 'get_default_hub', 'get_hub',
+ 'exc_after', 'getcurrent', 'get_default_hub', 'get_hub',
'GreenletExit', 'kill', 'sleep', 'spawn', 'spew', 'switch',
'ssl_listener', 'tcp_listener', 'trampoline',
'unspew', 'use_hub', 'with_timeout', 'timeout']
@@ -59,9 +59,6 @@ def switch (coro, result = None, exc = None):
spawn = greenthread.spawn
spawn_n = greenthread.spawn_n
kill = greenthread.kill
-call_after = greenthread.call_after
-call_after_local = greenthread.call_after_local
-call_after_global = greenthread.call_after_global
class _SilentException(BaseException):
View
9 evy/corolocal.py
@@ -37,9 +37,12 @@ def get_ident ():
return id(greenthread.getcurrent())
-# the entire purpose of this class is to store off the constructor
-# arguments in a local variable without calling __init__ directly
class _localbase(object):
+ """
+ This class is used to store off the constructor arguments in a local variable without
+ calling __init__ directly
+ """
+
__slots__ = '_local__args', '_local__greens'
def __new__ (cls, *args, **kw):
@@ -53,6 +56,7 @@ def __new__ (cls, *args, **kw):
def _patch (thrl):
greens = object.__getattribute__(thrl, '_local__greens')
+
# until we can store the localdict on greenlets themselves,
# we store it in _local__greens on the local object
cur = greenthread.getcurrent()
@@ -66,6 +70,7 @@ def _patch (thrl):
object.__setattr__(thrl, '__dict__', greens[cur])
+
class local(_localbase):
def __getattribute__ (self, attr):
_patch(self)
View
23 evy/greenthread.py
@@ -116,7 +116,8 @@ def spawn_after (seconds, func, *args, **kwargs):
def spawn_after_local (seconds, func, *args, **kwargs):
- """Spawns *func* after *seconds* have elapsed. The function will NOT be
+ """
+ Spawns *func* after *seconds* have elapsed. The function will NOT be
called if the current greenthread has exited.
*seconds* may be specified as an integer, or a float if fractional seconds
@@ -138,26 +139,6 @@ def spawn_after_local (seconds, func, *args, **kwargs):
return g
-def call_after_global (seconds, func, *args, **kwargs):
- warnings.warn("call_after_global is renamed to spawn_after, which"
- "has the same signature and semantics (plus a bit extra). Please do a"
- " quick search-and-replace on your codebase, thanks!",
- DeprecationWarning, stacklevel = 2)
- return _spawn_n(seconds, func, args, kwargs)[0]
-
-
-def call_after_local (seconds, function, *args, **kwargs):
- warnings.warn("call_after_local is renamed to spawn_after_local, which"
- "has the same signature and semantics (plus a bit extra).",
- DeprecationWarning, stacklevel = 2)
- hub = hubs.get_hub()
- g = greenlet.greenlet(function, parent = hub.greenlet)
- t = hub.schedule_call_local(seconds, g.switch, *args, **kwargs)
- return t
-
-
-call_after = call_after_local
-
def exc_after (seconds, *throw_args):
warnings.warn("Instead of exc_after, which is deprecated, use "
View
56 evy/support/greendns.py
@@ -1,8 +1,4 @@
#!/usr/bin/env python
-'''
- greendns - non-blocking DNS support for Eventlet
-'''
-
# Portions of this code taken from the gogreen project:
# http://github.com/slideinc/gogreen
#
@@ -35,6 +31,13 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+"""
+Non-blocking DNS support for Evy
+"""
+
+
+
import sys
import struct
@@ -146,7 +149,8 @@ def resolve (name):
# methods
#
def getaliases (host):
- """Checks for aliases of the given hostname (cname records)
+ """
+ Checks for aliases of the given hostname (cname records)
returns a list of alias targets
will return an empty list if no aliases
"""
@@ -170,7 +174,8 @@ def getaliases (host):
def getaddrinfo (host, port, family = 0, socktype = 0, proto = 0, flags = 0):
- """Replacement for Python's socket.getaddrinfo.
+ """
+ Replacement for Python's socket.getaddrinfo.
Currently only supports IPv4. At present, flags are not
implemented.
@@ -189,7 +194,8 @@ def getaddrinfo (host, port, family = 0, socktype = 0, proto = 0, flags = 0):
def gethostbyname (hostname):
- """Replacement for Python's socket.gethostbyname.
+ """
+ Replacement for Python's socket.gethostbyname.
Currently only supports IPv4.
"""
@@ -201,7 +207,8 @@ def gethostbyname (hostname):
def gethostbyname_ex (hostname):
- """Replacement for Python's socket.gethostbyname_ex.
+ """
+ Replacement for Python's socket.gethostbyname_ex.
Currently only supports IPv4.
"""
@@ -217,7 +224,8 @@ def gethostbyname_ex (hostname):
def getnameinfo (sockaddr, flags):
- """Replacement for Python's socket.getnameinfo.
+ """
+ Replacement for Python's socket.getnameinfo.
Currently only supports IPv4.
"""
@@ -272,8 +280,8 @@ def getnameinfo (sockaddr, flags):
def is_ipv4_addr (host):
- """is_ipv4_addr returns true if host is a valid IPv4 address in
- dotted quad notation.
+ """
+ Return true if host is a valid IPv4 address in dotted quad notation.
"""
try:
d1, d2, d3, d4 = map(int, host.split('.'))
@@ -286,7 +294,8 @@ def is_ipv4_addr (host):
def _net_read (sock, count, expiration):
- """coro friendly replacement for dns.query._net_write
+ """
+ Coroutines-friendly replacement for dns.query._net_write
Read the specified number of bytes from sock. Keep trying until we
either get the desired amount, or we hit EOF.
A Timeout exception will be raised if the operation is not completed
@@ -308,7 +317,8 @@ def _net_read (sock, count, expiration):
def _net_write (sock, data, expiration):
- """coro friendly replacement for dns.query._net_write
+ """
+ Coroutines-friendly replacement for dns.query._net_write
Write the specified data to the socket.
A Timeout exception will be raised if the operation is not completed
by the expiration time.
@@ -324,10 +334,10 @@ def _net_write (sock, data, expiration):
raise dns.exception.Timeout
-def udp (
- q, where, timeout = DNS_QUERY_TIMEOUT, port = 53, af = None, source = None,
- source_port = 0, ignore_unexpected = False):
- """coro friendly replacement for dns.query.udp
+def udp (q, where, timeout = DNS_QUERY_TIMEOUT, port = 53, af = None, source = None,
+ source_port = 0, ignore_unexpected = False):
+ """
+ Coroutines-friendly replacement for dns.query.udp
Return the response obtained after sending a query via UDP.
@param q: the query
@@ -351,7 +361,8 @@ def udp (
@type source_port: int
@param ignore_unexpected: If True, ignore responses from unexpected
sources. The default is False.
- @type ignore_unexpected: bool"""
+ @type ignore_unexpected: bool
+ """
wire = q.to_wire()
if af is None:
@@ -404,7 +415,8 @@ def udp (
def tcp (q, where, timeout = DNS_QUERY_TIMEOUT, port = 53,
af = None, source = None, source_port = 0):
- """coro friendly replacement for dns.query.tcp
+ """
+ Coroutines-friendly replacement for dns.query.tcp
Return the response obtained after sending a query via TCP.
@param q: the query
@@ -425,7 +437,8 @@ def tcp (q, where, timeout = DNS_QUERY_TIMEOUT, port = 53,
@type source: string
@param source_port: The port from which to send the message.
The default is 0.
- @type source_port: int"""
+ @type source_port: int
+ """
wire = q.to_wire()
if af is None:
@@ -441,6 +454,7 @@ def tcp (q, where, timeout = DNS_QUERY_TIMEOUT, port = 53,
destination = (where, port, 0, 0)
if source is not None:
source = (source, source_port, 0, 0)
+
s = socket.socket(af, socket.SOCK_STREAM)
s.settimeout(timeout)
try:
@@ -455,6 +469,7 @@ def tcp (q, where, timeout = DNS_QUERY_TIMEOUT, port = 53,
raise dns.exception.Timeout
l = len(wire)
+
# copying the wire into tcpmsg is inefficient, but lets us
# avoid writev() or doing a short write that would get pushed
# onto the net
@@ -465,6 +480,7 @@ def tcp (q, where, timeout = DNS_QUERY_TIMEOUT, port = 53,
wire = _net_read(s, l, expiration)
finally:
s.close()
+
r = dns.message.from_wire(wire, keyring = q.keyring, request_mac = q.mac)
if not q.is_response(r):
raise dns.query.BadResponse()
View
2  setup.py
@@ -20,7 +20,7 @@
url = 'http://github.com/inercia/evy',
packages = find_packages(exclude = ['tests', 'benchmarks']),
- install_requires = [],
+ install_requires = ['dnspython'],
zip_safe = False,
long_description = open(
Please sign in to comment.
Something went wrong with that request. Please try again.