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
596043df
Commit
596043df
authored
Dec 01, 2013
by
Denis Bilenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
replace "ex = sys.exc_info()[1]" with "as ex" #38
parent
8707190c
Changes
33
Hide whitespace changes
Inline
Side-by-side
Showing
33 changed files
with
80 additions
and
157 deletions
+80
-157
examples/dns_mass_resolve.py
examples/dns_mass_resolve.py
+1
-3
examples/geventsendfile.py
examples/geventsendfile.py
+1
-3
examples/webproxy.py
examples/webproxy.py
+3
-4
gevent/baseserver.py
gevent/baseserver.py
+4
-6
gevent/event.py
gevent/event.py
+2
-4
gevent/fileobject.py
gevent/fileobject.py
+4
-4
gevent/greenlet.py
gevent/greenlet.py
+2
-2
gevent/pool.py
gevent/pool.py
+1
-3
gevent/pywsgi.py
gevent/pywsgi.py
+2
-4
gevent/resolver_ares.py
gevent/resolver_ares.py
+1
-3
gevent/select.py
gevent/select.py
+1
-3
gevent/server.py
gevent/server.py
+2
-4
gevent/socket.py
gevent/socket.py
+13
-24
gevent/ssl.py
gevent/ssl.py
+6
-12
gevent/threadpool.py
gevent/threadpool.py
+2
-2
gevent/timeout.py
gevent/timeout.py
+2
-3
gevent/util.py
gevent/util.py
+2
-4
greentest/greentest.py
greentest/greentest.py
+3
-6
greentest/test__api_timeout.py
greentest/test__api_timeout.py
+4
-8
greentest/test__event.py
greentest/test__event.py
+1
-3
greentest/test__greenlet.py
greentest/test__greenlet.py
+1
-2
greentest/test__greenness.py
greentest/test__greenness.py
+1
-3
greentest/test__pywsgi.py
greentest/test__pywsgi.py
+4
-8
greentest/test__server.py
greentest/test__server.py
+3
-7
greentest/test__signal.py
greentest/test__signal.py
+2
-5
greentest/test__socket.py
greentest/test__socket.py
+1
-2
greentest/test__socket_dns.py
greentest/test__socket_dns.py
+2
-3
greentest/test__socket_errors.py
greentest/test__socket_errors.py
+1
-3
greentest/test__socket_timeout.py
greentest/test__socket_timeout.py
+1
-3
greentest/test__subprocess.py
greentest/test__subprocess.py
+1
-2
greentest/test__systemerror.py
greentest/test__systemerror.py
+2
-4
greentest/test__timeout.py
greentest/test__timeout.py
+3
-7
greentest/xtest__server_close.py
greentest/xtest__server_close.py
+1
-3
No files found.
examples/dns_mass_resolve.py
View file @
596043df
...
...
@@ -10,7 +10,6 @@ variable. To enable threading resolver:
GEVENT_RESOLVER=thread python dns_mass_resolve.py
"""
from
__future__
import
with_statement
import
sys
import
gevent
from
gevent
import
socket
from
gevent.pool
import
Pool
...
...
@@ -27,8 +26,7 @@ def job(url):
try
:
ip
=
socket
.
gethostbyname
(
url
)
print
(
'%s = %s'
%
(
url
,
ip
))
except
socket
.
gaierror
:
ex
=
sys
.
exc_info
()[
1
]
except
socket
.
gaierror
as
ex
:
print
(
'%s failed with %s'
%
(
url
,
ex
))
finally
:
finished
+=
1
...
...
examples/geventsendfile.py
View file @
596043df
...
...
@@ -2,7 +2,6 @@
[1] http://pypi.python.org/pypi/py-sendfile/
"""
from
sys
import
exc_info
from
errno
import
EAGAIN
from
sendfile
import
sendfile
as
original_sendfile
from
gevent.socket
import
wait_write
...
...
@@ -15,8 +14,7 @@ def gevent_sendfile(out_fd, in_fd, offset, count):
_offset
,
sent
=
original_sendfile
(
out_fd
,
in_fd
,
offset
+
total_sent
,
count
-
total_sent
)
#print '%s: sent %s [%d%%]' % (out_fd, sent, 100*total_sent/count)
total_sent
+=
sent
except
OSError
:
ex
=
exc_info
()[
1
]
except
OSError
as
ex
:
if
ex
[
0
]
==
EAGAIN
:
wait_write
(
out_fd
)
else
:
...
...
examples/webproxy.py
View file @
596043df
...
...
@@ -51,14 +51,13 @@ def proxy(path, start_response, proxy_url):
try
:
try
:
response
=
urllib2
.
urlopen
(
path
)
except
urllib2
.
HTTPError
:
response
=
sys
.
exc_info
()[
1
]
except
urllib2
.
HTTPError
as
ex
:
response
=
ex
print
(
'%s: %s %s'
%
(
path
,
response
.
code
,
response
.
msg
))
headers
=
[(
k
,
v
)
for
(
k
,
v
)
in
response
.
headers
.
items
()
if
k
not
in
drop_headers
]
scheme
,
netloc
,
path
,
params
,
query
,
fragment
=
urlparse
(
path
)
host
=
(
scheme
or
'http'
)
+
'://'
+
netloc
except
Exception
:
ex
=
sys
.
exc_info
()[
1
]
except
Exception
as
ex
:
sys
.
stderr
.
write
(
'error while reading %s:
\
n
'
%
path
)
traceback
.
print_exc
()
tb
=
traceback
.
format_exc
()
...
...
gevent/baseserver.py
View file @
596043df
...
...
@@ -179,8 +179,7 @@ class BaseServer(object):
if
hasattr
(
self
,
'socket'
):
try
:
fileno
=
self
.
socket
.
fileno
()
except
Exception
:
ex
=
sys
.
exc_info
()[
1
]
except
Exception
as
ex
:
fileno
=
str
(
ex
)
result
=
'fileno=%s '
%
fileno
else
:
...
...
@@ -190,8 +189,7 @@ class BaseServer(object):
result
+=
'address=%s:%s'
%
self
.
address
else
:
result
+=
'address=%s'
%
(
self
.
address
,
)
except
Exception
:
ex
=
sys
.
exc_info
()[
1
]
except
Exception
as
ex
:
result
+=
str
(
ex
)
or
'<error>'
try
:
handle
=
getfuncname
(
self
.
__dict__
[
'handle'
])
...
...
@@ -319,5 +317,5 @@ def _parse_address(address):
def
parse_address
(
address
):
try
:
return
_parse_address
(
address
)
except
ValueError
:
raise
ValueError
(
'Failed to parse address %r: %s'
%
(
address
,
sys
.
exc_info
()[
1
]
))
except
ValueError
as
ex
:
raise
ValueError
(
'Failed to parse address %r: %s'
%
(
address
,
ex
))
gevent/event.py
View file @
596043df
...
...
@@ -76,8 +76,7 @@ class Event(object):
try
:
result
=
self
.
hub
.
switch
()
assert
result
is
self
,
'Invalid switch into Event.wait(): %r'
%
(
result
,
)
except
Timeout
:
ex
=
sys
.
exc_info
()[
1
]
except
Timeout
as
ex
:
if
ex
is
not
timer
:
raise
finally
:
...
...
@@ -268,8 +267,7 @@ class AsyncResult(object):
assert
result
is
self
,
'Invalid switch into AsyncResult.wait(): %r'
%
(
result
,
)
finally
:
timer
.
cancel
()
except
Timeout
:
exc
=
sys
.
exc_info
()[
1
]
except
Timeout
as
exc
:
self
.
unlink
(
switch
)
if
exc
is
not
timer
:
raise
...
...
gevent/fileobject.py
View file @
596043df
...
...
@@ -101,8 +101,8 @@ else:
while
True
:
try
:
bytes_written
+=
_write
(
fileno
,
_get_memory
(
data
,
bytes_written
))
except
(
IOError
,
OSError
):
code
=
sys
.
exc_info
()[
1
]
.
args
[
0
]
except
(
IOError
,
OSError
)
as
ex
:
code
=
ex
.
args
[
0
]
if
code
not
in
ignored_errors
:
raise
sys
.
exc_clear
()
...
...
@@ -114,8 +114,8 @@ else:
while
True
:
try
:
data
=
_read
(
self
.
fileno
(),
size
)
except
(
IOError
,
OSError
):
code
=
sys
.
exc_info
()[
1
]
.
args
[
0
]
except
(
IOError
,
OSError
)
as
ex
:
code
=
ex
.
args
[
0
]
if
code
not
in
ignored_errors
:
raise
sys
.
exc_clear
()
...
...
gevent/greenlet.py
View file @
596043df
...
...
@@ -291,9 +291,9 @@ class Greenlet(greenlet):
assert
result
is
self
,
'Invalid switch into Greenlet.join(): %r'
%
(
result
,
)
finally
:
t
.
cancel
()
except
Timeout
:
except
Timeout
as
ex
:
self
.
unlink
(
switch
)
if
sys
.
exc_info
()[
1
]
is
not
t
:
if
ex
is
not
t
:
raise
except
:
self
.
unlink
(
switch
)
...
...
gevent/pool.py
View file @
596043df
...
...
@@ -9,7 +9,6 @@ concurrency: its :meth:`spawn <Pool.spawn>` method blocks if the number of
greenlets in the pool has already reached the limit, until there is a free slot.
"""
import
sys
from
bisect
import
insort_right
from
gevent.hub
import
GreenletExit
,
getcurrent
,
kill
as
_kill
,
PY3
...
...
@@ -116,8 +115,7 @@ class Group(object):
if
not
block
:
break
joinall
(
self
.
greenlets
)
except
Timeout
:
ex
=
sys
.
exc_info
()[
1
]
except
Timeout
as
ex
:
if
ex
is
not
timer
:
raise
finally
:
...
...
gevent/pywsgi.py
View file @
596043df
...
...
@@ -308,8 +308,7 @@ class WSGIHandler(object):
# for compatibility with older versions of pywsgi, we pass self.requestline as an argument there
if
not
self
.
read_request
(
self
.
requestline
):
return
(
'400'
,
_BAD_REQUEST_RESPONSE
)
except
Exception
:
ex
=
sys
.
exc_info
()[
1
]
except
Exception
as
ex
:
if
not
isinstance
(
ex
,
ValueError
):
traceback
.
print_exc
()
self
.
log_error
(
'Invalid request: %s'
,
str
(
ex
)
or
ex
.
__class__
.
__name__
)
...
...
@@ -319,8 +318,7 @@ class WSGIHandler(object):
self
.
application
=
self
.
server
.
application
try
:
self
.
handle_one_response
()
except
socket
.
error
:
ex
=
sys
.
exc_info
()[
1
]
except
socket
.
error
as
ex
:
# Broken pipe, connection reset by peer
if
ex
.
args
[
0
]
in
(
errno
.
EPIPE
,
errno
.
ECONNRESET
):
sys
.
exc_clear
()
...
...
gevent/resolver_ares.py
View file @
596043df
# Copyright (c) 2011 Denis Bilenko. See LICENSE for details.
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
from
gevent.socket
import
AF_UNSPEC
,
AF_INET
,
AF_INET6
,
SOCK_STREAM
,
SOCK_DGRAM
,
SOCK_RAW
,
AI_NUMERICHOST
,
EAI_SERVICE
,
AI_PASSIVE
...
...
@@ -99,8 +98,7 @@ class Resolver(object):
port
=
getservbyname
(
port
,
'udp'
)
else
:
raise
gaierror
(
EAI_SERVICE
,
'Servname not supported for ai_socktype'
)
except
error
:
ex
=
sys
.
exc_info
()[
1
]
except
error
as
ex
:
if
'not found'
in
str
(
ex
):
raise
gaierror
(
EAI_SERVICE
,
'Servname not supported for ai_socktype'
)
else
:
...
...
gevent/select.py
View file @
596043df
# Copyright (c) 2009-2011 Denis Bilenko. See LICENSE for details.
from
__future__
import
absolute_import
import
sys
from
gevent.timeout
import
Timeout
from
gevent.event
import
Event
from
gevent.hub
import
get_hub
...
...
@@ -63,8 +62,7 @@ def select(rlist, wlist, xlist, timeout=None):
watcher
.
priority
=
MAXPRI
watcher
.
start
(
result
.
add_write
,
writefd
)
watchers
.
append
(
watcher
)
except
IOError
:
ex
=
sys
.
exc_info
()[
1
]
except
IOError
as
ex
:
raise
error
(
*
ex
.
args
)
result
.
event
.
wait
(
timeout
=
timeout
)
return
result
.
read
,
result
.
write
,
[]
...
...
gevent/server.py
View file @
596043df
...
...
@@ -151,8 +151,7 @@ def _tcp_listener(address, backlog=50, reuse_addr=None, family=_socket.AF_INET):
sock
.
setsockopt
(
_socket
.
SOL_SOCKET
,
_socket
.
SO_REUSEADDR
,
reuse_addr
)
try
:
sock
.
bind
(
address
)
except
_socket
.
error
:
ex
=
sys
.
exc_info
()[
1
]
except
_socket
.
error
as
ex
:
strerror
=
getattr
(
ex
,
'strerror'
,
None
)
if
strerror
is
not
None
:
ex
.
strerror
=
strerror
+
': '
+
repr
(
address
)
...
...
@@ -169,8 +168,7 @@ def _udp_socket(address, backlog=50, reuse_addr=None, family=_socket.AF_INET):
sock
.
setsockopt
(
_socket
.
SOL_SOCKET
,
_socket
.
SO_REUSEADDR
,
reuse_addr
)
try
:
sock
.
bind
(
address
)
except
_socket
.
error
:
ex
=
sys
.
exc_info
()[
1
]
except
_socket
.
error
as
ex
:
strerror
=
getattr
(
ex
,
'strerror'
,
None
)
if
strerror
is
not
None
:
ex
.
strerror
=
strerror
+
': '
+
repr
(
address
)
...
...
gevent/socket.py
View file @
596043df
...
...
@@ -247,8 +247,8 @@ class socket(object):
def
_formatinfo
(
self
):
try
:
fileno
=
self
.
fileno
()
except
Exception
:
fileno
=
str
(
sys
.
exc_info
()[
1
]
)
except
Exception
as
ex
:
fileno
=
str
(
ex
)
try
:
sockname
=
self
.
getsockname
()
sockname
=
'%s:%s'
%
sockname
...
...
@@ -302,8 +302,7 @@ class socket(object):
try
:
client_socket
,
address
=
sock
.
accept
()
break
except
error
:
ex
=
sys
.
exc_info
()[
1
]
except
error
as
ex
:
if
ex
[
0
]
!=
EWOULDBLOCK
or
self
.
timeout
==
0.0
:
raise
sys
.
exc_clear
()
...
...
@@ -352,8 +351,7 @@ class socket(object):
return
self
.
connect
(
address
)
or
0
except
timeout
:
return
EAGAIN
except
error
:
ex
=
sys
.
exc_info
()[
1
]
except
error
as
ex
:
if
type
(
ex
)
is
error
:
return
ex
.
args
[
0
]
else
:
...
...
@@ -379,8 +377,7 @@ class socket(object):
while
True
:
try
:
return
sock
.
recv
(
*
args
)
except
error
:
ex
=
sys
.
exc_info
()[
1
]
except
error
as
ex
:
if
ex
.
args
[
0
]
!=
EWOULDBLOCK
or
self
.
timeout
==
0.0
:
raise
# QQQ without clearing exc_info test__refcount.test_clean_exit fails
...
...
@@ -392,8 +389,7 @@ class socket(object):
while
True
:
try
:
return
sock
.
recvfrom
(
*
args
)
except
error
:
ex
=
sys
.
exc_info
()[
1
]
except
error
as
ex
:
if
ex
.
args
[
0
]
!=
EWOULDBLOCK
or
self
.
timeout
==
0.0
:
raise
sys
.
exc_clear
()
...
...
@@ -404,8 +400,7 @@ class socket(object):
while
True
:
try
:
return
sock
.
recvfrom_into
(
*
args
)
except
error
:
ex
=
sys
.
exc_info
()[
1
]
except
error
as
ex
:
if
ex
.
args
[
0
]
!=
EWOULDBLOCK
or
self
.
timeout
==
0.0
:
raise
sys
.
exc_clear
()
...
...
@@ -416,8 +411,7 @@ class socket(object):
while
True
:
try
:
return
sock
.
recv_into
(
*
args
)
except
error
:
ex
=
sys
.
exc_info
()[
1
]
except
error
as
ex
:
if
ex
.
args
[
0
]
!=
EWOULDBLOCK
or
self
.
timeout
==
0.0
:
raise
sys
.
exc_clear
()
...
...
@@ -429,16 +423,14 @@ class socket(object):
timeout
=
self
.
timeout
try
:
return
sock
.
send
(
data
,
flags
)
except
error
:
ex
=
sys
.
exc_info
()[
1
]
except
error
as
ex
:
if
ex
.
args
[
0
]
!=
EWOULDBLOCK
or
timeout
==
0.0
:
raise
sys
.
exc_clear
()
self
.
_wait
(
self
.
_write_event
)
try
:
return
sock
.
send
(
data
,
flags
)
except
error
:
ex2
=
sys
.
exc_info
()[
1
]
except
error
as
ex2
:
if
ex2
.
args
[
0
]
==
EWOULDBLOCK
:
return
0
raise
...
...
@@ -468,16 +460,14 @@ class socket(object):
sock
=
self
.
_sock
try
:
return
sock
.
sendto
(
*
args
)
except
error
:
ex
=
sys
.
exc_info
()[
1
]
except
error
as
ex
:
if
ex
.
args
[
0
]
!=
EWOULDBLOCK
or
timeout
==
0.0
:
raise
sys
.
exc_clear
()
self
.
_wait
(
self
.
_write_event
)
try
:
return
sock
.
sendto
(
*
args
)
except
error
:
ex2
=
sys
.
exc_info
()[
1
]
except
error
as
ex2
:
if
ex2
.
args
[
0
]
==
EWOULDBLOCK
:
return
0
raise
...
...
@@ -574,8 +564,7 @@ def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT, source_address=N
sock
.
bind
(
source_address
)
sock
.
connect
(
sa
)
return
sock
except
error
:
err
=
sys
.
exc_info
()[
1
]
except
error
as
err
:
# without exc_clear(), if connect() fails once, the socket is referenced by the frame in exc_info
# and the next bind() fails (see test__socket.TestCreateConnection)
# that does not happen with regular sockets though, because _socket.socket.connect() is a built-in.
...
...
gevent/ssl.py
View file @
596043df
...
...
@@ -104,8 +104,7 @@ class SSLSocket(socket):
while
True
:
try
:
return
self
.
_sslobj
.
read
(
len
)
except
SSLError
:
ex
=
sys
.
exc_info
()[
1
]
except
SSLError
as
ex
:
if
ex
.
args
[
0
]
==
SSL_ERROR_EOF
and
self
.
suppress_ragged_eofs
:
return
''
elif
ex
.
args
[
0
]
==
SSL_ERROR_WANT_READ
:
...
...
@@ -128,8 +127,7 @@ class SSLSocket(socket):
while
True
:
try
:
return
self
.
_sslobj
.
write
(
data
)
except
SSLError
:
ex
=
sys
.
exc_info
()[
1
]
except
SSLError
as
ex
:
if
ex
.
args
[
0
]
==
SSL_ERROR_WANT_READ
:
if
self
.
timeout
==
0.0
:
raise
...
...
@@ -167,8 +165,7 @@ class SSLSocket(socket):
while
True
:
try
:
v
=
self
.
_sslobj
.
write
(
data
)
except
SSLError
:
x
=
sys
.
exc_info
()[
1
]
except
SSLError
as
x
:
if
x
.
args
[
0
]
==
SSL_ERROR_WANT_READ
:
if
self
.
timeout
==
0.0
:
return
0
...
...
@@ -221,8 +218,7 @@ class SSLSocket(socket):
v
=
len
(
tmp_buffer
)
buffer
[:
v
]
=
tmp_buffer
return
v
except
SSLError
:
x
=
sys
.
exc_info
()[
1
]
except
SSLError
as
x
:
if
x
.
args
[
0
]
==
SSL_ERROR_WANT_READ
:
if
self
.
timeout
==
0.0
:
raise
...
...
@@ -258,8 +254,7 @@ class SSLSocket(socket):
while
True
:
try
:
return
self
.
_sslobj
.
shutdown
()
except
SSLError
:
ex
=
sys
.
exc_info
()[
1
]
except
SSLError
as
ex
:
if
ex
.
args
[
0
]
==
SSL_ERROR_EOF
and
self
.
suppress_ragged_eofs
:
return
''
elif
ex
.
args
[
0
]
==
SSL_ERROR_WANT_READ
:
...
...
@@ -299,8 +294,7 @@ class SSLSocket(socket):
while
True
:
try
:
return
self
.
_sslobj
.
do_handshake
()
except
SSLError
:
ex
=
sys
.
exc_info
()[
1
]
except
SSLError
as
ex
:
if
ex
.
args
[
0
]
==
SSL_ERROR_WANT_READ
:
if
self
.
timeout
==
0.0
:
raise
...
...
gevent/threadpool.py
View file @
596043df
...
...
@@ -325,5 +325,5 @@ class ThreadResult(object):
def
wrap_errors
(
errors
,
function
,
args
,
kwargs
):
try
:
return
True
,
function
(
*
args
,
**
kwargs
)
except
errors
:
return
False
,
sys
.
exc_info
()[
1
]
except
errors
as
ex
:
return
False
,
ex
gevent/timeout.py
View file @
596043df
...
...
@@ -13,7 +13,6 @@ to arbitrary code.
which no switches occur, :class:`Timeout` is powerless.
"""
import
sys
from
gevent.hub
import
getcurrent
,
_NONE
,
get_hub
,
string_types
__all__
=
[
'Timeout'
,
...
...
@@ -175,8 +174,8 @@ def with_timeout(seconds, function, *args, **kwds):
try
:
try
:
return
function
(
*
args
,
**
kwds
)
except
Timeout
:
if
sys
.
exc_info
()[
1
]
is
timeout
and
timeout_value
is
not
_NONE
:
except
Timeout
as
ex
:
if
ex
is
timeout
and
timeout_value
is
not
_NONE
:
return
timeout_value
raise
finally
:
...
...
gevent/util.py
View file @
596043df
# Copyright (c) 2009 Denis Bilenko. See LICENSE for details.
__all__
=
[
'wrap_errors'
]
import
sys
class
wrap_errors
(
object
):
"""Helper to make function return an exception, rather than raise it.
...
...
@@ -37,8 +35,8 @@ class wrap_errors(object):
func
=
self
.
func
try
:
return
func
(
*
args
,
**
kwargs
)
except
self
.
errors
:
return
sys
.
exc_info
()[
1
]
except
self
.
errors
as
ex
:
return
ex
def
__str__
(
self
):
return
str
(
self
.
func
)
...
...
greentest/greentest.py
View file @
596043df
...
...
@@ -296,8 +296,7 @@ def test_outer_timeout_is_not_lost(self):
try
:
try
:
result
=
self
.
wait
(
timeout
=
1
)
except
gevent
.
Timeout
:
ex
=
sys
.
exc_info
()[
1
]
except
gevent
.
Timeout
as
ex
:
assert
ex
is
timeout
,
(
ex
,
timeout
)
else
:
raise
AssertionError
(
'must raise Timeout (returned %r)'
%
(
result
,
))
...
...
@@ -346,8 +345,7 @@ class GenericGetTestCase(TestCase):
timeout
=
gevent
.
Timeout
(
0.01
)
try
:
self
.
wait
(
timeout
=
timeout
)
except
gevent
.
Timeout
:
ex
=
sys
.
exc_info
()[
1
]
except
gevent
.
Timeout
as
ex
:
assert
ex
is
timeout
,
(
ex
,
timeout
)
delay
=
time
.
time
()
-
start
assert
0.01
-
0.001
<=
delay
<
0.01
+
0.01
+
0.1
,
delay
...
...
@@ -359,8 +357,7 @@ class GenericGetTestCase(TestCase):
timeout
=
gevent
.
Timeout
(
0.01
,
exception
=
error
)
try
:
self
.
wait
(
timeout
=
timeout
)
except
RuntimeError
:
ex
=
sys
.
exc_info
()[
1
]
except
RuntimeError
as
ex
:
assert
ex
is
error
,
(
ex
,
error
)
delay
=
time
.
time
()
-
start
assert
0.01
-
0.001
<=
delay
<
0.01
+
0.01
+
0.1
,
delay
...
...
greentest/test__api_timeout.py
View file @
596043df
...
...
@@ -49,8 +49,7 @@ class Test(greentest.TestCase):
try
:
with
Timeout
(
DELAY
)
as
t
:
sleep
(
DELAY
*
2
)
except
Timeout
:
ex
=
sys
.
exc_info
()[
1
]
except
Timeout
as
ex
:
assert
ex
is
t
,
(
ex
,
t
)
else
:
raise
AssertionError
(
'must raise Timeout'
)
...
...
@@ -59,8 +58,7 @@ class Test(greentest.TestCase):
try
:
with
Timeout
(
DELAY
,
IOError
(
"Operation takes way too long"
)):
sleep
(
DELAY
*
2
)
except
IOError
:
ex
=
sys
.
exc_info
()[
1
]
except
IOError
as
ex
:
assert
str
(
ex
)
==
"Operation takes way too long"
,
repr
(
ex
)
# Providing classes instead of values should be possible too:
...
...
@@ -119,8 +117,7 @@ class Test(greentest.TestCase):
with
Timeout
(
DELAY
*
2
)
as
t2
:
try
:
sleep
(
DELAY
*
3
)
except
Timeout
:
ex
=
sys
.
exc_info
()[
1
]
except
Timeout
as
ex
:
assert
ex
is
t1
,
(
ex
,
t1
)
assert
not
t1
.
pending
,
t1
assert
t2
.
pending
,
t2
...
...
@@ -130,8 +127,7 @@ class Test(greentest.TestCase):
with
Timeout
(
DELAY
)
as
t2
:
try
:
sleep
(
DELAY
*
3
)
except
Timeout
:
ex
=
sys
.
exc_info
()[
1
]
except
Timeout
as
ex
:
assert
ex
is
t2
,
(
ex
,
t2
)
assert
t1
.
pending
,
t1
assert
not
t2
.
pending
,
t2
...
...
greentest/test__event.py
View file @
596043df
import
greentest
import
gevent
import
sys
from
gevent.event
import
Event
,
AsyncResult
DELAY
=
0.01
...
...
@@ -46,8 +45,7 @@ class TestAsyncResult(greentest.TestCase):
try
:
result
=
e
.
get
()
log
.
append
((
'received'
,
result
))
except
Exception
:
ex
=
sys
.
exc_info
()[
1
]
except
Exception
as
ex
:
log
.
append
((
'catched'
,
ex
))
gevent
.
spawn
(
waiter
)
obj
=
Exception
()
...
...
greentest/test__greenlet.py
View file @
596043df
...
...
@@ -284,8 +284,7 @@ class TestStuff(greentest.TestCase):
b
=
gevent
.
spawn
(
lambda
:
getcurrent
().
throw
(
ExpectedError
(
'second'
)))
try
:
gevent
.
joinall
([
a
,
b
],
raise_error
=
True
)
except
ExpectedError
:
ex
=
sys
.
exc_info
()[
1
]
except
ExpectedError
as
ex
:
assert
'second'
in
str
(
ex
),
repr
(
str
(
ex
))
gevent
.
joinall
([
a
,
b
])
...
...
greentest/test__greenness.py
View file @
596043df
...
...
@@ -26,7 +26,6 @@ If either operation blocked the whole script would block and timeout.
import
greentest
from
gevent
import
monkey
monkey
.
patch_all
()
import
sys
try
:
import
urllib2
except
ImportError
:
...
...
@@ -56,8 +55,7 @@ class TestGreenness(greentest.TestCase):
try
:
urllib2
.
urlopen
(
'http://127.0.0.1:%s'
%
port
)
assert
False
,
'should not get there'
except
urllib2
.
HTTPError
:
ex
=
sys
.
exc_info
()[
1
]
except
urllib2
.
HTTPError
as
ex
:
assert
ex
.
code
==
501
,
repr
(
ex
)
server
.
get
(
0.01
)
self
.
assertEqual
(
self
.
httpd
.
request_count
,
1
)
...
...
greentest/test__pywsgi.py
View file @
596043df
...
...
@@ -277,8 +277,7 @@ class CommonTests(TestCase):
fd
.
close
()
finally
:
timeout
.
cancel
()
except
AssertionError
:
ex
=
sys
.
exc_info
()[
1
]
except
AssertionError
as
ex
:
if
ex
is
not
exception
:
raise
...
...
@@ -294,8 +293,7 @@ class CommonTests(TestCase):
try
:
result
=
fd
.
readline
()
assert
not
result
,
'The remote side is expected to close the connection, but it send %r'
%
(
result
,
)
except
socket
.
error
:
ex
=
sys
.
exc_info
()[
1
]
except
socket
.
error
as
ex
:
if
ex
.
args
[
0
]
not
in
CONN_ABORTED_ERRORS
:
raise
...
...
@@ -952,8 +950,7 @@ class ChunkedInputTests(TestCase):
fd
.
write
(
req
)
try
:
read_http
(
fd
,
body
=
"pong"
)
except
AssertionError
:
ex
=
sys
.
exc_info
()[
1
]
except
AssertionError
as
ex
:
if
str
(
ex
).
startswith
(
'Unexpected code: 400'
):
if
not
server_implements_chunked
:
print
'ChunkedNotImplementedWarning'
...
...
@@ -1005,8 +1002,7 @@ class Expect100ContinueTests(TestCase):
fd
.
write
(
'PUT / HTTP/1.1
\
r
\
n
Host: localhost
\
r
\
n
Content-length: 1025
\
r
\
n
Expect: 100-continue
\
r
\
n
\
r
\
n
'
)
try
:
read_http
(
fd
,
code
=
417
,
body
=
"failure"
)
except
AssertionError
:
ex
=
sys
.
exc_info
()[
1
]
except
AssertionError
as
ex
:
if
str
(
ex
).
startswith
(
'Unexpected code: 400'
):
if
not
server_implements_100continue
:
print
'100ContinueNotImplementedWarning'
...
...
greentest/test__server.py
View file @
596043df
...
...
@@ -3,7 +3,6 @@ from gevent import socket
import
gevent
from
gevent.server
import
StreamServer
import
errno
import
sys
import
os
...
...
@@ -52,8 +51,7 @@ class Settings:
# attempt to send anything reset the connection
try
:
self
.
send_request
()
except
socket
.
error
:
ex
=
sys
.
exc_info
()[
1
]
except
socket
.
error
as
ex
:
if
ex
.
args
[
0
]
!=
errno
.
ECONNRESET
:
raise
...
...
@@ -94,8 +92,7 @@ class TestCase(greentest.TestCase):
try
:
conn
=
self
.
makefile
()
raise
AssertionError
(
'Connection was not refused: %r'
%
(
conn
.
_sock
,
))
except
socket
.
error
:
ex
=
sys
.
exc_info
()[
1
]
except
socket
.
error
as
ex
:
if
ex
.
args
[
0
]
not
in
(
errno
.
ECONNREFUSED
,
errno
.
EADDRNOTAVAIL
):
raise
...
...
@@ -259,8 +256,7 @@ class TestDefaultSpawn(TestCase):
result
=
conn
.
read
()
if
result
:
assert
result
.
startswith
(
'HTTP/1.0 500 Internal Server Error'
),
repr
(
result
)
except
socket
.
error
:
ex
=
sys
.
exc_info
()[
1
]
except
socket
.
error
as
ex
:
if
ex
.
args
[
0
]
==
10053
:
pass
# "established connection was aborted by the software in your host machine"
elif
ex
.
args
[
0
]
==
errno
.
ECONNRESET
:
...
...
greentest/test__signal.py
View file @
596043df
import
signal
import
greentest
import
gevent
import
sys
class
Expected
(
Exception
):
...
...
@@ -30,16 +29,14 @@ if hasattr(signal, 'SIGALRM'):
try
:
gevent
.
sleep
(
2
)
raise
AssertionError
(
'must raise Expected'
)
except
Expected
:
ex
=
sys
.
exc_info
()[
1
]
except
Expected
as
ex
:
assert
str
(
ex
)
==
'TestSignal'
,
ex
# also let's check that alarm is persistent
signal
.
alarm
(
1
)
try
:
gevent
.
sleep
(
2
)
raise
AssertionError
(
'must raise Expected'
)
except
Expected
:
ex
=
sys
.
exc_info
()[
1
]
except
Expected
as
ex
:
assert
str
(
ex
)
==
'TestSignal'
,
ex
finally
:
sig
.
cancel
()
...
...
greentest/test__socket.py
View file @
596043df
...
...
@@ -175,8 +175,7 @@ class TestCreateConnection(greentest.TestCase):
def
test
(
self
):
try
:
socket
.
create_connection
((
'localhost'
,
get_port
()),
timeout
=
30
,
source_address
=
(
''
,
get_port
()))
except
socket
.
error
:
ex
=
sys
.
exc_info
()[
1
]
except
socket
.
error
as
ex
:
if
'refused'
not
in
str
(
ex
).
lower
():
raise
else
:
...
...
greentest/test__socket_dns.py
View file @
596043df
#!/usr/bin/python
# -*- coding: utf-8 -*-
from
__future__
import
with_statement
import
sys
import
re
import
greentest
import
socket
...
...
@@ -29,8 +28,8 @@ def _run(function, *args):
result
=
function
(
*
args
)
assert
not
isinstance
(
result
,
BaseException
),
repr
(
result
)
return
result
except
Exception
:
return
sys
.
exc_info
()[
1
]
except
Exception
as
ex
:
return
ex
def
format_call
(
function
,
args
):
...
...
greentest/test__socket_errors.py
View file @
596043df
...
...
@@ -19,7 +19,6 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import
sys
import
greentest
from
gevent.socket
import
socket
,
error
...
...
@@ -37,8 +36,7 @@ class TestSocketErrors(greentest.TestCase):
s
=
socket
()
try
:
s
.
connect
((
'127.0.0.1'
,
81
))
except
error
:
ex
=
sys
.
exc_info
()[
1
]
except
error
as
ex
:
assert
ex
.
args
[
0
]
==
ECONNREFUSED
,
repr
(
ex
)
assert
'refused'
in
str
(
ex
).
lower
(),
str
(
ex
)
...
...
greentest/test__socket_timeout.py
View file @
596043df
import
sys
import
gevent
from
gevent
import
socket
import
greentest
...
...
@@ -29,8 +28,7 @@ class Test(greentest.TestCase):
try
:
result
=
sock
.
recv
(
1024
)
raise
AssertionError
(
'Expected timeout to be raised, instead recv() returned %r'
%
(
result
,
))
except
socket
.
error
:
ex
=
sys
.
exc_info
()[
1
]
except
socket
.
error
as
ex
:
self
.
assertEqual
(
ex
.
args
,
(
'timed out'
,))
self
.
assertEqual
(
str
(
ex
),
'timed out'
)
self
.
assertEqual
(
ex
[
0
],
'timed out'
)
...
...
greentest/test__subprocess.py
View file @
596043df
...
...
@@ -131,8 +131,7 @@ class Test(greentest.TestCase):
for
i
in
range
(
7
):
try
:
p1
=
subprocess
.
Popen
(
'this_name_must_not_exist'
)
except
OSError
:
ex
=
sys
.
exc_info
()[
1
]
except
OSError
as
ex
:
if
ex
.
errno
!=
errno
.
ENOENT
:
raise
else
:
...
...
greentest/test__systemerror.py
View file @
596043df
...
...
@@ -20,8 +20,7 @@ class Test(greentest.TestCase):
try
:
gevent
.
sleep
(
0.001
)
except
SystemExit
:
ex
=
sys
.
exc_info
()[
1
]
except
SystemExit
as
ex
:
assert
str
(
ex
)
==
MSG
,
repr
(
str
(
ex
))
else
:
raise
AssertionError
(
'must raise SystemExit'
)
...
...
@@ -41,8 +40,7 @@ class Test(greentest.TestCase):
try
:
gevent
.
sleep
(
0.001
)
except
SystemError
:
ex
=
sys
.
exc_info
()[
1
]
except
SystemError
as
ex
:
assert
str
(
ex
)
==
MSG
,
repr
(
str
(
ex
))
else
:
raise
AssertionError
(
'must raise SystemError'
)
...
...
greentest/test__timeout.py
View file @
596043df
import
greentest
import
gevent
import
sys
from
gevent.hub
import
get_hub
DELAY
=
0.01
...
...
@@ -12,16 +11,14 @@ class TestDirectRaise(greentest.TestCase):
def
test_direct_raise_class
(
self
):
try
:
raise
gevent
.
Timeout
except
gevent
.
Timeout
:
t
=
sys
.
exc_info
()[
1
]
except
gevent
.
Timeout
as
t
:
assert
not
t
.
pending
,
repr
(
t
)
def
test_direct_raise_instance
(
self
):
timeout
=
gevent
.
Timeout
()
try
:
raise
timeout
except
gevent
.
Timeout
:
t
=
sys
.
exc_info
()[
1
]
except
gevent
.
Timeout
as
t
:
assert
timeout
is
t
,
(
timeout
,
t
)
assert
not
t
.
pending
,
repr
(
t
)
...
...
@@ -32,8 +29,7 @@ class Test(greentest.TestCase):
try
:
get_hub
().
switch
()
raise
AssertionError
(
'Must raise Timeout'
)
except
gevent
.
Timeout
:
ex
=
sys
.
exc_info
()[
1
]
except
gevent
.
Timeout
as
ex
:
if
ex
is
not
timeout
:
raise
...
...
greentest/xtest__server_close.py
View file @
596043df
...
...
@@ -2,7 +2,6 @@ import unittest
from
gevent
import
socket
import
gevent
import
errno
import
sys
import
os
from
test__server
import
SimpleStreamServer
...
...
@@ -20,8 +19,7 @@ class Test(unittest.TestCase):
try
:
conn
=
self
.
makefile
()
raise
AssertionError
(
'Connection was not refused: %r'
%
(
conn
.
_sock
,
))
except
socket
.
error
:
ex
=
sys
.
exc_info
()[
1
]
except
socket
.
error
as
ex
:
if
ex
.
args
[
0
]
!=
errno
.
ECONNREFUSED
:
raise
...
...
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