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
26f29b6c
Commit
26f29b6c
authored
Mar 09, 2016
by
Jason Madden
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #765 from gevent/tblib-update
Update tblib to 1.3.0
parents
d17b5e0b
9a5fd30c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
124 additions
and
29 deletions
+124
-29
changelog.rst
changelog.rst
+1
-0
gevent/_tblib.py
gevent/_tblib.py
+123
-29
No files found.
changelog.rst
View file @
26f29b6c
...
...
@@ -8,6 +8,7 @@
==================
- Update libev to version 4.22.
- Update tblib to 1.3.0.
1.1.0 (Mar 5, 2016)
===================
...
...
gevent/_tblib.py
View file @
26f29b6c
# -*- coding: utf-8 -*-
# A vendored version of part of https://github.com/ionelmc/python-tblib
####
# Copyright (c) 2013-201
4
, Ionel Cristian Mărieș
# Copyright (c) 2013-201
6
, Ionel Cristian Mărieș
# All rights reserved.
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
...
...
@@ -51,6 +51,7 @@ def _init_ugly_crap():
# regular python
class
_PyObject
(
ctypes
.
Structure
):
pass
_PyObject
.
_fields_
=
[
(
'ob_refcnt'
,
_Py_ssize_t
),
(
'ob_type'
,
ctypes
.
POINTER
(
_PyObject
))
...
...
@@ -60,6 +61,7 @@ def _init_ugly_crap():
if
hasattr
(
sys
,
'getobjects'
):
class
_PyObject
(
ctypes
.
Structure
):
pass
_PyObject
.
_fields_
=
[
(
'_ob_next'
,
ctypes
.
POINTER
(
_PyObject
)),
(
'_ob_prev'
,
ctypes
.
POINTER
(
_PyObject
)),
...
...
@@ -69,6 +71,7 @@ def _init_ugly_crap():
class
_Traceback
(
_PyObject
):
pass
_Traceback
.
_fields_
=
[
(
'tb_next'
,
ctypes
.
POINTER
(
_Traceback
)),
(
'tb_frame'
,
ctypes
.
POINTER
(
_PyObject
)),
...
...
@@ -78,8 +81,7 @@ def _init_ugly_crap():
def
tb_set_next
(
tb
,
next
):
"""Set the tb_next attribute of a traceback object."""
if
not
(
isinstance
(
tb
,
TracebackType
)
and
(
next
is
None
or
isinstance
(
next
,
TracebackType
))):
if
not
(
isinstance
(
tb
,
TracebackType
)
and
(
next
is
None
or
isinstance
(
next
,
TracebackType
))):
raise
TypeError
(
'tb_set_next arguments must be traceback objects'
)
obj
=
_Traceback
.
from_address
(
id
(
tb
))
if
tb
.
tb_next
is
not
None
:
...
...
@@ -94,44 +96,51 @@ def _init_ugly_crap():
return
tb_set_next
tb_set_next
=
None
# try:
# if platform.python_implementation() == 'CPython':
# #tb_set_next = _init_ugly_crap()
# tb_set_next = None
# except Exception as exc:
# sys.stderr.write("Failed to initialize cpython support: {!r}".format(exc))
# del _init_ugly_crap
#try:
# if platform.python_implementation() == 'CPython':
# tb_set_next = _init_ugly_crap()
#except Exception as exc:
# sys.stderr.write("Failed to initialize cpython support: {!r}".format(exc))
#del _init_ugly_crap
# __init__.py
import
re
from
types
import
CodeType
from
types
import
TracebackType
try
:
from
__pypy__
import
tproxy
except
ImportError
:
tproxy
=
None
#if not tb_set_next and not tproxy:
# raise ImportError("Cannot use tblib. Runtime not supported.")
from
types
import
CodeType
from
types
import
TracebackType
__version__
=
'1.3.0'
__all__
=
'Traceback'
,
PY3
=
sys
.
version_info
[
0
]
==
3
FRAME_RE
=
re
.
compile
(
r'^\
s*File
"(?P<co_filename>.+)", line (?P<tb_lineno>\
d+)(, i
n (?P<co_name>.+))?$'
)
class
_AttrDict
(
dict
):
def
__getattr__
(
self
,
attr
):
return
self
[
attr
]
__slots__
=
()
__getattr__
=
dict
.
__getitem__
# noinspection PyPep8Naming
class
__traceback_maker
(
Exception
):
pass
class
TracebackParseError
(
Exception
):
pass
class
Code
(
object
):
def
__init__
(
self
,
code
):
self
.
co_filename
=
code
.
co_filename
self
.
co_name
=
code
.
co_name
# gevent: copy more attributes
self
.
co_nlocals
=
code
.
co_nlocals
self
.
co_stacksize
=
code
.
co_stacksize
self
.
co_flags
=
code
.
co_flags
...
...
@@ -140,16 +149,19 @@ class Code(object):
class
Frame
(
object
):
def
__init__
(
self
,
frame
):
# gevent: python 2.6 syntax fix
self
.
f_globals
=
{
'__file__'
:
frame
.
f_globals
.
get
(
'__file__'
),
'__name__'
:
frame
.
f_globals
.
get
(
'__name__'
)}
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
)
class
Traceback
(
object
):
def
__init__
(
self
,
tb
):
self
.
tb_frame
=
Frame
(
tb
.
tb_frame
)
self
.
tb_lineno
=
tb
.
tb_lineno
# noinspection SpellCheckingInspection
self
.
tb_lineno
=
int
(
tb
.
tb_lineno
)
if
tb
.
tb_next
is
None
:
self
.
tb_next
=
None
else
:
...
...
@@ -163,23 +175,22 @@ class Traceback(object):
code
=
compile
(
'
\
n
'
*
(
self
.
tb_lineno
-
1
)
+
'raise __traceback_maker'
,
self
.
tb_frame
.
f_code
.
co_filename
,
'exec'
)
if
PY3
:
code
=
CodeType
(
0
,
0
,
f_code
.
co_nlocals
,
f_code
.
co_stacksize
,
f_
code
.
co_flags
,
0
,
code
.
co_kwonlyargcount
,
code
.
co_nlocals
,
code
.
co_stacksize
,
code
.
co_flags
,
code
.
co_code
,
code
.
co_consts
,
code
.
co_names
,
code
.
co_varnames
,
f_code
.
co_filename
,
f_code
.
co_name
,
code
.
co_firstlineno
,
b""
,
(),
()
code
.
co_firstlineno
,
code
.
co_lnotab
,
(),
()
)
else
:
code
=
CodeType
(
0
,
f_code
.
co_nlocals
,
f_code
.
co_stacksize
,
f_
code
.
co_flags
,
code
.
co_nlocals
,
code
.
co_stacksize
,
code
.
co_flags
,
code
.
co_code
,
code
.
co_consts
,
code
.
co_names
,
code
.
co_varnames
,
f_code
.
co_filename
.
encode
(),
f_code
.
co_name
.
encode
(),
code
.
co_firstlineno
,
b""
,
(),
()
code
.
co_firstlineno
,
code
.
co_lnotab
,
(),
()
)
# noinspection PyBroadException
try
:
exec
(
code
,
self
.
tb_frame
.
f_globals
,
{})
except
:
...
...
@@ -188,10 +199,13 @@ class Traceback(object):
try
:
return
tb
finally
:
# gevent: don't leak the traceback objects, this
# makes our leaktests fail
del
tb
else
:
raise
RuntimeError
(
"Cannot re-create traceback !"
)
# noinspection SpellCheckingInspection
def
__tproxy_handler
(
self
,
operation
,
*
args
,
**
kwargs
):
if
operation
in
(
'__getattribute__'
,
'__getattr__'
):
if
args
[
0
]
==
'tb_next'
:
...
...
@@ -201,6 +215,86 @@ class Traceback(object):
else
:
return
getattr
(
self
,
operation
)(
*
args
,
**
kwargs
)
def
to_dict
(
self
):
"""Convert a Traceback into a dictionary representation"""
if
self
.
tb_next
is
None
:
tb_next
=
None
else
:
tb_next
=
self
.
tb_next
.
to_dict
()
code
=
{
'co_filename'
:
self
.
tb_frame
.
f_code
.
co_filename
,
'co_name'
:
self
.
tb_frame
.
f_code
.
co_name
,
}
frame
=
{
'f_globals'
:
self
.
tb_frame
.
f_globals
,
'f_code'
:
code
,
}
return
{
'tb_frame'
:
frame
,
'tb_lineno'
:
self
.
tb_lineno
,
'tb_next'
:
tb_next
,
}
@
classmethod
def
from_dict
(
cls
,
dct
):
if
dct
[
'tb_next'
]:
tb_next
=
cls
.
from_dict
(
dct
[
'tb_next'
])
else
:
tb_next
=
None
code
=
_AttrDict
(
co_filename
=
dct
[
'tb_frame'
][
'f_code'
][
'co_filename'
],
co_name
=
dct
[
'tb_frame'
][
'f_code'
][
'co_name'
],
)
frame
=
_AttrDict
(
f_globals
=
dct
[
'tb_frame'
][
'f_globals'
],
f_code
=
code
,
)
tb
=
_AttrDict
(
tb_frame
=
frame
,
tb_lineno
=
dct
[
'tb_lineno'
],
tb_next
=
tb_next
,
)
return
cls
(
tb
)
@
classmethod
def
from_string
(
cls
,
string
,
strict
=
True
):
frames
=
[]
header
=
strict
for
line
in
string
.
splitlines
():
line
=
line
.
rstrip
()
if
header
:
if
line
==
'Traceback (most recent call last):'
:
header
=
False
continue
frame_match
=
FRAME_RE
.
match
(
line
)
if
frame_match
:
frames
.
append
(
frame_match
.
groupdict
())
elif
line
.
startswith
(
' '
):
pass
elif
strict
:
break
# traceback ended
if
frames
:
previous
=
None
for
frame
in
reversed
(
frames
):
previous
=
_AttrDict
(
frame
,
tb_frame
=
_AttrDict
(
frame
,
f_globals
=
_AttrDict
(
__file__
=
frame
[
'co_filename'
],
__name__
=
'?'
,
),
f_code
=
_AttrDict
(
frame
),
),
tb_next
=
previous
,
)
return
cls
(
previous
)
else
:
raise
TracebackParseError
(
"Could not find any frames in %r."
%
string
)
# pickling_support.py
...
...
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