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
2398a078
Commit
2398a078
authored
Mar 09, 2020
by
Ivanq
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update tblib version for pytest compatibility
parent
944677e5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
5 deletions
+44
-5
src/gevent/_tblib.py
src/gevent/_tblib.py
+44
-5
No files found.
src/gevent/_tblib.py
View file @
2398a078
...
...
@@ -110,6 +110,7 @@ tb_set_next = None
# __init__.py
import
re
from
types
import
CodeType
from
types
import
FrameType
from
types
import
TracebackType
try
:
...
...
@@ -126,7 +127,12 @@ FRAME_RE = re.compile(r'^\s*File "(?P<co_filename>.+)", line (?P<tb_lineno>\d+)(
class
_AttrDict
(
dict
):
__slots__
=
()
__getattr__
=
dict
.
__getitem__
def
__getattr__
(
self
,
name
):
try
:
return
self
[
name
]
except
KeyError
:
raise
AttributeError
(
name
)
# noinspection PyPep8Naming
...
...
@@ -142,21 +148,36 @@ class Code(object):
def
__init__
(
self
,
code
):
self
.
co_filename
=
code
.
co_filename
self
.
co_name
=
code
.
co_name
self
.
co_argcount
=
0
self
.
co_kwonlyargcount
=
0
self
.
co_varnames
=
()
# gevent: copy more attributes
self
.
co_nlocals
=
code
.
co_nlocals
self
.
co_stacksize
=
code
.
co_stacksize
self
.
co_flags
=
code
.
co_flags
self
.
co_firstlineno
=
code
.
co_firstlineno
def
__reduce__
(
self
):
return
Code
,
(
_AttrDict
(
self
.
__dict__
),)
# noinspection SpellCheckingInspection
def
__tproxy__
(
self
,
operation
,
*
args
,
**
kwargs
):
if
operation
in
(
'__getattribute__'
,
'__getattr__'
):
return
getattr
(
self
,
args
[
0
])
else
:
return
getattr
(
self
,
operation
)(
*
args
,
**
kwargs
)
class
Frame
(
object
):
def
__init__
(
self
,
frame
):
self
.
f_locals
=
{}
self
.
f_globals
=
dict
([
(
k
,
v
)
for
k
,
v
in
frame
.
f_globals
.
items
()
if
k
in
(
"__file__"
,
"__name__"
)
])
self
.
f_code
=
Code
(
frame
.
f_code
)
self
.
f_lineno
=
frame
.
f_lineno
def
clear
(
self
):
# For compatibility with PyPy 3.5;
...
...
@@ -165,6 +186,17 @@ class Frame(object):
# in turn is called by unittest.TestCase.assertRaises
pass
# noinspection SpellCheckingInspection
def
__tproxy__
(
self
,
operation
,
*
args
,
**
kwargs
):
if
operation
in
(
'__getattribute__'
,
'__getattr__'
):
if
args
[
0
]
==
'f_code'
:
return
tproxy
(
CodeType
,
self
.
f_code
.
__tproxy__
)
else
:
return
getattr
(
self
,
args
[
0
])
else
:
return
getattr
(
self
,
operation
)(
*
args
,
**
kwargs
)
class
Traceback
(
object
):
tb_next
=
None
...
...
@@ -188,7 +220,7 @@ class Traceback(object):
def
as_traceback
(
self
):
if
tproxy
:
return
tproxy
(
TracebackType
,
self
.
__tproxy_
handler
)
return
tproxy
(
TracebackType
,
self
.
__tproxy_
_
)
if
not
tb_set_next
:
raise
RuntimeError
(
"Cannot re-create traceback !"
)
...
...
@@ -222,7 +254,7 @@ class Traceback(object):
# noinspection PyBroadException
try
:
exec
(
code
,
current
.
tb_frame
.
f_globals
,
{})
exec
(
code
,
dict
(
current
.
tb_frame
.
f_globals
)
,
{})
except
:
next_tb
=
sys
.
exc_info
()[
2
].
tb_next
if
top_tb
is
None
:
...
...
@@ -238,19 +270,22 @@ class Traceback(object):
finally
:
del
top_tb
del
tb
to_traceback
=
as_traceback
# noinspection SpellCheckingInspection
def
__tproxy_
handler
(
self
,
operation
,
*
args
,
**
kwargs
):
def
__tproxy_
_
(
self
,
operation
,
*
args
,
**
kwargs
):
if
operation
in
(
'__getattribute__'
,
'__getattr__'
):
if
args
[
0
]
==
'tb_next'
:
return
self
.
tb_next
and
self
.
tb_next
.
as_traceback
()
elif
args
[
0
]
==
'tb_frame'
:
return
tproxy
(
FrameType
,
self
.
tb_frame
.
__tproxy__
)
else
:
return
getattr
(
self
,
args
[
0
])
else
:
return
getattr
(
self
,
operation
)(
*
args
,
**
kwargs
)
def
to
_dict
(
self
):
def
as
_dict
(
self
):
"""Convert a Traceback into a dictionary representation"""
if
self
.
tb_next
is
None
:
tb_next
=
None
...
...
@@ -264,12 +299,14 @@ class Traceback(object):
frame
=
{
'f_globals'
:
self
.
tb_frame
.
f_globals
,
'f_code'
:
code
,
'f_lineno'
:
self
.
tb_frame
.
f_lineno
,
}
return
{
'tb_frame'
:
frame
,
'tb_lineno'
:
self
.
tb_lineno
,
'tb_next'
:
tb_next
,
}
to_dict
=
as_dict
@
classmethod
def
from_dict
(
cls
,
dct
):
...
...
@@ -285,6 +322,7 @@ class Traceback(object):
frame
=
_AttrDict
(
f_globals
=
dct
[
'tb_frame'
][
'f_globals'
],
f_code
=
code
,
f_lineno
=
dct
[
'tb_frame'
][
'f_lineno'
],
)
tb
=
_AttrDict
(
tb_frame
=
frame
,
...
...
@@ -324,6 +362,7 @@ class Traceback(object):
__name__
=
'?'
,
),
f_code
=
_AttrDict
(
frame
),
f_lineno
=
int
(
frame
[
'tb_lineno'
]),
),
tb_next
=
previous
,
)
...
...
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