Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gevent
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gevent
Commits
1bb128b8
Commit
1bb128b8
authored
Sep 15, 2010
by
Denis Bilenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pep8
parent
d70a3fd1
Changes
21
Hide whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
45 additions
and
58 deletions
+45
-58
gevent/__init__.py
gevent/__init__.py
+1
-1
gevent/backdoor.py
gevent/backdoor.py
+1
-2
gevent/baseserver.py
gevent/baseserver.py
+0
-1
gevent/coros.py
gevent/coros.py
+1
-2
gevent/dns.py
gevent/dns.py
+1
-1
gevent/event.py
gevent/event.py
+4
-5
gevent/greenlet.py
gevent/greenlet.py
+1
-2
gevent/http.py
gevent/http.py
+0
-1
gevent/hub.py
gevent/hub.py
+6
-5
gevent/local.py
gevent/local.py
+1
-0
gevent/pool.py
gevent/pool.py
+5
-6
gevent/pywsgi.py
gevent/pywsgi.py
+4
-7
gevent/queue.py
gevent/queue.py
+2
-3
gevent/rawgreenlet.py
gevent/rawgreenlet.py
+2
-3
gevent/select.py
gevent/select.py
+0
-1
gevent/server.py
gevent/server.py
+2
-3
gevent/sslold.py
gevent/sslold.py
+2
-2
gevent/timeout.py
gevent/timeout.py
+10
-10
gevent/util.py
gevent/util.py
+1
-1
gevent/win32util.py
gevent/win32util.py
+0
-1
gevent/wsgi.py
gevent/wsgi.py
+1
-1
No files found.
gevent/__init__.py
View file @
1bb128b8
...
...
@@ -33,7 +33,7 @@ __all__ = ['Greenlet',
import
sys
if
sys
.
platform
==
'win32'
:
__import__
(
'socket'
)
# trigger WSAStartup call
__import__
(
'socket'
)
# trigger WSAStartup call
del
sys
...
...
gevent/backdoor.py
View file @
1bb128b8
...
...
@@ -86,7 +86,7 @@ class SocketConsole(Greenlet):
try
:
console
=
InteractiveConsole
(
self
.
locals
)
console
.
interact
()
except
SystemExit
:
# raised by quit()
except
SystemExit
:
# raised by quit()
pass
finally
:
self
.
switch_out
()
...
...
@@ -115,4 +115,3 @@ if __name__ == '__main__':
print
'USAGE: %s PORT'
%
sys
.
argv
[
0
]
else
:
BackdoorServer
((
'127.0.0.1'
,
int
(
sys
.
argv
[
1
]))).
serve_forever
()
gevent/baseserver.py
View file @
1bb128b8
...
...
@@ -196,4 +196,3 @@ def _tcp_listener(address, backlog=50, reuse_addr=None):
sock
.
listen
(
backlog
)
sock
.
setblocking
(
0
)
return
sock
gevent/coros.py
View file @
1bb128b8
...
...
@@ -15,7 +15,7 @@ class Semaphore(object):
"""A semaphore manages a counter representing the number of release() calls minus the number of acquire() calls,
plus an initial value. The acquire() method blocks if necessary until it can return without making the counter
negative.
If not given, value defaults to 1."""
def
__init__
(
self
,
value
=
1
):
...
...
@@ -232,4 +232,3 @@ class RLock(object):
def
_is_owned
(
self
):
return
self
.
_owner
is
getcurrent
()
gevent/dns.py
View file @
1bb128b8
...
...
@@ -36,7 +36,7 @@ class DNSError(gaierror):
"""
def
__init__
(
self
,
*
args
):
if
len
(
args
)
==
1
:
if
len
(
args
)
==
1
:
code
=
args
[
0
]
gaierror
.
__init__
(
self
,
code
,
core
.
dns_err_to_string
(
code
))
else
:
...
...
gevent/event.py
View file @
1bb128b8
...
...
@@ -30,8 +30,8 @@ class Event(object):
"""Return true if and only if the internal flag is true."""
return
self
.
_flag
isSet
=
is_set
# makes it a better drop-in replacement for threading.Event
ready
=
is_set
# makes it compatible with AsyncResult and Greenlet (for example in wait())
isSet
=
is_set
# makes it a better drop-in replacement for threading.Event
ready
=
is_set
# makes it compatible with AsyncResult and Greenlet (for example in wait())
def
set
(
self
):
"""Set the internal flag to true. All greenlets waiting for it to become true are awakened.
...
...
@@ -92,7 +92,7 @@ class Event(object):
raise
TypeError
(
'Expected callable: %r'
%
(
callback
,
))
self
.
_links
.
append
(
callback
)
if
self
.
_flag
:
core
.
active_event
(
self
.
_notify_links
,
list
(
self
.
_links
))
# XXX just pass [callback]
core
.
active_event
(
self
.
_notify_links
,
list
(
self
.
_links
))
# XXX just pass [callback]
def
unlink
(
self
,
callback
):
"""Remove the callback set by :meth:`rawlink`"""
...
...
@@ -104,7 +104,7 @@ class Event(object):
def
_notify_links
(
self
,
links
):
assert
getcurrent
()
is
get_hub
()
for
link
in
links
:
if
link
in
self
.
_links
:
# check that link was not notified yet and was not removed by the client
if
link
in
self
.
_links
:
# check that link was not notified yet and was not removed by the client
try
:
link
(
self
)
except
:
...
...
@@ -320,4 +320,3 @@ def waitall(events):
finally
:
for
event
in
events
:
event
.
unlink
(
put
)
gevent/greenlet.py
View file @
1bb128b8
...
...
@@ -228,7 +228,7 @@ class Greenlet(greenlet):
# the result was not set and the links weren't notified. let's do it here.
# checking that self.dead is true is essential, because the exception raised by
# throw() could have been cancelled by the greenlet's function.
if
len
(
args
)
==
1
:
if
len
(
args
)
==
1
:
arg
=
args
[
0
]
#if isinstance(arg, type):
if
type
(
arg
)
is
type
(
Exception
):
...
...
@@ -614,4 +614,3 @@ def getfuncname(func):
_NONE
=
Exception
(
"Neither exception nor value"
)
gevent/http.py
View file @
1bb128b8
...
...
@@ -47,4 +47,3 @@ class HTTPServer(BaseServer):
def
stop_accepting
(
self
):
self
.
http
=
None
gevent/hub.py
View file @
1bb128b8
...
...
@@ -100,8 +100,9 @@ def _wrap_signal_handler(handler, args, kwargs):
except
:
core
.
active_event
(
MAIN
.
throw
,
*
sys
.
exc_info
())
def
signal
(
signalnum
,
handler
,
*
args
,
**
kwargs
):
return
core
.
signal
(
signalnum
,
lambda
:
spawn_raw
(
_wrap_signal_handler
,
handler
,
args
,
kwargs
))
return
core
.
signal
(
signalnum
,
lambda
:
spawn_raw
(
_wrap_signal_handler
,
handler
,
args
,
kwargs
))
if
_original_fork
is
not
None
:
...
...
@@ -169,7 +170,7 @@ class Hub(greenlet):
try
:
self
.
keyboard_interrupt_signal
=
signal
(
2
,
core
.
active_event
,
MAIN
.
throw
,
KeyboardInterrupt
)
except
IOError
:
pass
# no signal() on windows
pass
# no signal() on windows
try
:
loop_count
=
0
while
True
:
...
...
@@ -204,7 +205,7 @@ class Hub(greenlet):
try
:
self
.
switch
()
except
DispatchExit
,
ex
:
if
ex
.
code
==
1
:
# no more events registered?
if
ex
.
code
==
1
:
# no more events registered?
return
raise
...
...
@@ -320,7 +321,7 @@ class Waiter(object):
finally
:
self
.
greenlet
=
None
wait
=
get
# XXX backward compatibility; will be removed in the next release
wait
=
get
# XXX backward compatibility; will be removed in the next release
# can also have a debugging version, that wraps the value in a tuple (self, value) in switch()
# and unwraps it in wait() thus checking that switch() was indeed called
...
...
@@ -329,8 +330,8 @@ class Waiter(object):
class
_NONE
(
object
):
"A special thingy you must never pass to any of gevent API"
__slots__
=
[]
def
__repr__
(
self
):
return
'<_NONE>'
_NONE
=
_NONE
()
gevent/local.py
View file @
1bb128b8
...
...
@@ -132,6 +132,7 @@ from gevent.coros import RLock
__all__
=
[
"local"
]
class
_localbase
(
object
):
__slots__
=
'_local__args'
,
'_local__lock'
,
'_local__dicts'
...
...
gevent/pool.py
View file @
1bb128b8
...
...
@@ -26,7 +26,7 @@ class Group(object):
greenlet_class
=
Greenlet
def
__init__
(
self
,
*
args
):
assert
len
(
args
)
<=
1
,
args
assert
len
(
args
)
<=
1
,
args
self
.
greenlets
=
set
(
*
args
)
if
args
:
for
greenlet
in
args
[
0
]:
...
...
@@ -40,7 +40,7 @@ class Group(object):
try
:
classname
=
self
.
__class__
.
__name__
except
AttributeError
:
classname
=
'Group'
# XXX check if 2.4 really uses this line
classname
=
'Group'
# XXX check if 2.4 really uses this line
return
'<%s at %s %s>'
%
(
classname
,
hex
(
id
(
self
)),
self
.
greenlets
)
def
__len__
(
self
):
...
...
@@ -183,7 +183,7 @@ class Group(object):
def
imap
(
self
,
func
,
iterable
):
"""An equivalent of itertools.imap()
**TODO**: Fix this.
"""
return
iter
(
self
.
map
(
func
,
iterable
))
...
...
@@ -191,7 +191,7 @@ class Group(object):
def
imap_unordered
(
self
,
func
,
iterable
):
"""The same as imap() except that the ordering of the results from the
returned iterator should be considered arbitrary.
**TODO**: Fix this.
"""
return
iter
(
self
.
map
(
func
,
iterable
))
...
...
@@ -203,7 +203,7 @@ class Group(object):
pass
GreenletSet
=
Group
# the old name; will be deprecated in the future
GreenletSet
=
Group
# the old name; will be deprecated in the future
class
Pool
(
Group
):
...
...
@@ -315,4 +315,3 @@ class pass_value(object):
def
__getattr__
(
self
,
item
):
assert
item
!=
'callback'
return
getattr
(
self
.
callback
,
item
)
gevent/pywsgi.py
View file @
1bb128b8
...
...
@@ -19,14 +19,11 @@ __all__ = ['WSGIHandler', 'WSGIServer']
MAX_REQUEST_LINE
=
8192
# Weekday and month names for HTTP date/time formatting; always English!
_WEEKDAYNAME
=
[
"Mon"
,
"Tue"
,
"Wed"
,
"Thu"
,
"Fri"
,
"Sat"
,
"Sun"
]
_MONTHNAME
=
[
None
,
# Dummy so we can use 1-based month numbers
_MONTHNAME
=
[
None
,
# Dummy so we can use 1-based month numbers
"Jan"
,
"Feb"
,
"Mar"
,
"Apr"
,
"May"
,
"Jun"
,
"Jul"
,
"Aug"
,
"Sep"
,
"Oct"
,
"Nov"
,
"Dec"
]
_INTERNAL_ERROR_STATUS
=
'500 Internal Server Error'
_INTERNAL_ERROR_BODY
=
'Internal Server Error'
_INTERNAL_ERROR_HEADERS
=
[(
'Content-Type'
,
'text/plain'
),
...
...
@@ -34,9 +31,9 @@ _INTERNAL_ERROR_HEADERS = [('Content-Type', 'text/plain'),
(
'Content-Length'
,
str
(
len
(
_INTERNAL_ERROR_BODY
)))]
_REQUEST_TOO_LONG_RESPONSE
=
"HTTP/1.0 414 Request URI Too Long
\
r
\
n
Connection: close
\
r
\
n
Content-length: 0
\
r
\
n
\
r
\
n
"
_BAD_REQUEST_RESPONSE
=
"HTTP/1.0 400 Bad Request
\
r
\
n
Connection: close
\
r
\
n
Content-length: 0
\
r
\
n
\
r
\
n
"
_CONTINUE_RESPONSE
=
"HTTP/1.1 100 Continue
\
r
\
n
\
r
\
n
"
def
format_date_time
(
timestamp
):
year
,
month
,
day
,
hh
,
mm
,
ss
,
wd
,
_y
,
_z
=
time
.
gmtime
(
timestamp
)
return
"%s, %02d %3s %4d %02d:%02d:%02d GMT"
%
(
_WEEKDAYNAME
[
wd
],
day
,
_MONTHNAME
[
month
],
year
,
hh
,
mm
,
ss
)
...
...
@@ -184,7 +181,7 @@ class WSGIHandler(object):
version
=
self
.
request_version
if
not
version
.
startswith
(
"HTTP/"
):
return
False
version
=
tuple
(
int
(
x
)
for
x
in
version
[
5
:].
split
(
"."
))
# "HTTP/"
version
=
tuple
(
int
(
x
)
for
x
in
version
[
5
:].
split
(
"."
))
# "HTTP/"
if
version
[
1
]
<
0
or
version
<
(
0
,
9
)
or
version
>=
(
2
,
0
):
return
False
return
True
...
...
@@ -299,7 +296,7 @@ class WSGIHandler(object):
if
self
.
rfile
.
closed
:
return
return
True
# read more requests
return
True
# read more requests
def
write
(
self
,
data
):
towrite
=
[]
...
...
gevent/queue.py
View file @
1bb128b8
...
...
@@ -208,7 +208,7 @@ class Queue(object):
getter
=
self
.
getters
.
pop
()
if
getter
:
item
=
putter
.
item
putter
.
item
=
_NONE
# this makes greenlet calling put() not to call _put() again
putter
.
item
=
_NONE
# this makes greenlet calling put() not to call _put() again
self
.
_put
(
item
)
item
=
self
.
_get
()
getter
.
switch
(
item
)
...
...
@@ -221,7 +221,7 @@ class Queue(object):
else
:
break
finally
:
self
.
_event_unlock
=
None
# QQQ maybe it's possible to obtain this info from libevent?
self
.
_event_unlock
=
None
# QQQ maybe it's possible to obtain this info from libevent?
# i.e. whether this event is pending _OR_ currently executing
# testcase: 2 greenlets: while True: q.put(q.get()) - nothing else has a change to execute
# to avoid this, schedule unlock with timer(0, ...) once in a while
...
...
@@ -315,4 +315,3 @@ class JoinableQueue(Queue):
unfinished tasks drops to zero, :meth:`join` unblocks.
'''
self
.
_cond
.
wait
()
gevent/rawgreenlet.py
View file @
1bb128b8
...
...
@@ -74,7 +74,7 @@ def join(greenlet, polling_period=0.2):
"""Wait for a greenlet to finish by polling its status"""
delay
=
0.002
while
not
greenlet
.
dead
:
delay
=
min
(
polling_period
,
delay
*
2
)
delay
=
min
(
polling_period
,
delay
*
2
)
sleep
(
delay
)
...
...
@@ -85,8 +85,7 @@ def joinall(greenlets, polling_period=0.2):
current
+=
1
delay
=
0.002
while
current
<
len
(
greenlets
):
delay
=
min
(
polling_period
,
delay
*
2
)
delay
=
min
(
polling_period
,
delay
*
2
)
sleep
(
delay
)
while
current
<
len
(
greenlets
)
and
greenlets
[
current
].
dead
:
current
+=
1
gevent/select.py
View file @
1bb128b8
...
...
@@ -65,4 +65,3 @@ def select(rlist, wlist, xlist, timeout=None):
for
evt
in
allevents
:
evt
.
cancel
()
timeout
.
cancel
()
gevent/server.py
View file @
1bb128b8
...
...
@@ -114,7 +114,7 @@ class StreamServer(BaseServer):
try
:
client_socket
,
address
=
self
.
socket
.
accept
()
except
socket
.
error
,
err
:
if
err
[
0
]
==
errno
.
EAGAIN
:
if
err
[
0
]
==
errno
.
EAGAIN
:
sys
.
exc_clear
()
return
raise
...
...
@@ -144,7 +144,7 @@ class StreamServer(BaseServer):
if
self
.
delay
>=
0
:
self
.
stop_accepting
()
self
.
_start_accepting_timer
=
core
.
timer
(
self
.
delay
,
self
.
start_accepting
)
self
.
delay
=
min
(
self
.
max_delay
,
self
.
delay
*
2
)
self
.
delay
=
min
(
self
.
max_delay
,
self
.
delay
*
2
)
sys
.
exc_clear
()
def
is_fatal_error
(
self
,
ex
):
...
...
@@ -162,4 +162,3 @@ def _import_sslold_wrap_socket():
return
wrap_socket
except
ImportError
:
pass
gevent/sslold.py
View file @
1bb128b8
...
...
@@ -12,6 +12,7 @@ __all__ = ['ssl', 'sslerror']
try
:
sslerror
=
__socket__
.
sslerror
except
AttributeError
:
class
sslerror
(
error
):
pass
...
...
@@ -176,7 +177,7 @@ def wrap_socket(sock, keyfile=None, certfile=None,
do_handshake_on_connect
=
None
,
suppress_ragged_eofs
=
None
):
"""Create a new :class:`SSLObject` instance.
For compatibility with :mod:`gevent.ssl` the function accepts all the arguments that :func:`gevent.ssl.wrap_socket`
accepts. However, it only understands what *sock*, *keyfile* and *certfile* mean, so it will raise
:exc:`ImportError` if you pass anything else.
...
...
@@ -185,4 +186,3 @@ def wrap_socket(sock, keyfile=None, certfile=None,
if
locals
()[
arg
]
is
not
None
:
raise
TypeError
(
'To use argument %r install ssl package: http://pypi.python.org/pypi/ssl'
%
arg
)
return
ssl
(
sock
,
keyfile
=
keyfile
,
certfile
=
certfile
)
gevent/timeout.py
View file @
1bb128b8
...
...
@@ -22,7 +22,8 @@ __all__ = ['Timeout',
try
:
BaseException
except
NameError
:
# Python < 2.5
except
NameError
:
# Python < 2.5
class
BaseException
:
# not subclassing from object() intentionally, because in
# that case "raise Timeout" fails with TypeError.
...
...
@@ -35,7 +36,7 @@ class Timeout(BaseException):
timeout = Timeout(seconds, exception)
timeout.start()
try:
... # exception will be raised here, after *seconds* passed since start() call
...
# exception will be raised here, after *seconds* passed since start() call
finally:
timeout.cancel()
...
...
@@ -50,7 +51,7 @@ class Timeout(BaseException):
For Python 2.5 and newer ``with`` statement can be used::
with Timeout(seconds, exception) as timeout:
pass # ... code block ...
pass
# ... code block ...
This is equivalent to try/finally block above with one additional feature:
if *exception* is ``False``, the timeout is still raised, but context manager
...
...
@@ -62,9 +63,9 @@ class Timeout(BaseException):
with Timeout(5, False):
data = mysock.makefile().readline()
if data is None:
... # 5 seconds passed without reading a line
...
# 5 seconds passed without reading a line
else:
... # a line was read within 5 seconds
...
# a line was read within 5 seconds
Note that, if ``readline()`` above catches and doesn't re-raise :class:`BaseException`
(for example, with ``except:``), then your timeout is screwed.
...
...
@@ -90,11 +91,11 @@ class Timeout(BaseException):
def
start
(
self
):
"""Schedule the timeout."""
assert
not
self
.
pending
,
'%r is already started; to restart it, cancel it first'
%
self
if
self
.
seconds
is
None
:
# "fake" timeout (never expires)
if
self
.
seconds
is
None
:
# "fake" timeout (never expires)
self
.
timer
=
None
elif
self
.
exception
is
None
or
self
.
exception
is
False
:
# timeout that raises self
elif
self
.
exception
is
None
or
self
.
exception
is
False
:
# timeout that raises self
self
.
timer
=
core
.
timer
(
self
.
seconds
,
getcurrent
().
throw
,
self
)
else
:
# regular timeout with user-provided exception
else
:
# regular timeout with user-provided exception
self
.
timer
=
core
.
timer
(
self
.
seconds
,
getcurrent
().
throw
,
self
.
exception
)
@
classmethod
...
...
@@ -133,7 +134,7 @@ class Timeout(BaseException):
def
__repr__
(
self
):
try
:
classname
=
self
.
__class__
.
__name__
except
AttributeError
:
# Python < 2.5
except
AttributeError
:
# Python < 2.5
classname
=
'Timeout'
if
self
.
pending
:
pending
=
' pending'
...
...
@@ -196,4 +197,3 @@ def with_timeout(seconds, function, *args, **kwds):
raise
finally
:
timeout
.
cancel
()
gevent/util.py
View file @
1bb128b8
# Copyright (c) 2009 Denis Bilenko. See LICENSE for details.
__all__
=
[
'wrap_errors'
,
'lazy_property'
]
class
wrap_errors
(
object
):
"""Helper to make function return an exception, rather than raise it.
...
...
@@ -62,4 +63,3 @@ class lazy_property(object):
value
=
self
.
_calculate
(
obj
)
setattr
(
obj
,
self
.
_calculate
.
func_name
,
value
)
return
value
gevent/win32util.py
View file @
1bb128b8
...
...
@@ -66,7 +66,6 @@ class _ErrorFormatter(object):
return
cls
(
WinError
,
FormatMessage
,
errorTab
)
fromEnvironment
=
classmethod
(
fromEnvironment
)
def
formatError
(
self
,
errorcode
):
"""
Returns the string associated with a Windows error message, such as the
...
...
gevent/wsgi.py
View file @
1bb128b8
...
...
@@ -120,7 +120,7 @@ class WSGIHandler(object):
except
Exception
:
pass
# do not call self.end so that core.http replies with 500
self
=
None
self
=
None
return
finally
:
sys
.
exc_clear
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment