Commit 1b0f1c23 authored by Jason Madden's avatar Jason Madden

Update tblib to 1.3.0

parent 35ff8ede
......@@ -8,6 +8,7 @@
==================
- Update libev to version 4.22.
- Update tblib to 1.3.0.
1.1.0 (Mar 5, 2016)
===================
......
......@@ -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,62 +96,71 @@ 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+)(, in (?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
self.co_firstlineno = code.co_firstlineno
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,35 +174,32 @@ 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:
tb = sys.exc_info()[2].tb_next
tb_set_next(tb, self.tb_next and self.tb_next.as_traceback())
try:
return tb
finally:
del tb
return 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 +209,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
......
......@@ -107,7 +107,7 @@
# undef EV_USE_POLL
# define EV_USE_POLL 0
# endif
# if HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H
# ifndef EV_USE_EPOLL
# define EV_USE_EPOLL EV_FEATURE_BACKENDS
......@@ -116,7 +116,7 @@
# undef EV_USE_EPOLL
# define EV_USE_EPOLL 0
# endif
# if HAVE_KQUEUE && HAVE_SYS_EVENT_H
# ifndef EV_USE_KQUEUE
# define EV_USE_KQUEUE EV_FEATURE_BACKENDS
......@@ -125,7 +125,7 @@
# undef EV_USE_KQUEUE
# define EV_USE_KQUEUE 0
# endif
# if HAVE_PORT_H && HAVE_PORT_CREATE
# ifndef EV_USE_PORT
# define EV_USE_PORT EV_FEATURE_BACKENDS
......@@ -161,7 +161,7 @@
# undef EV_USE_EVENTFD
# define EV_USE_EVENTFD 0
# endif
#endif
#include <stdlib.h>
......@@ -1941,8 +1941,8 @@ array_nextsize (int elem, int cur, int cnt)
return ncur;
}
static void * noinline ecb_cold
/* gevent: remove noinline, breaks all the appveyor builds */
static void * ecb_cold
array_realloc (int elem, void *base, int *cur, int cnt)
{
*cur = array_nextsize (elem, *cur, cnt);
......@@ -2307,7 +2307,7 @@ downheap (ANHE *heap, int N, int k)
heap [k] = heap [c];
ev_active (ANHE_w (heap [k])) = k;
k = c;
}
......@@ -2727,7 +2727,7 @@ ev_supported_backends (void) EV_THROW
if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL;
if (EV_USE_POLL ) flags |= EVBACKEND_POLL;
if (EV_USE_SELECT) flags |= EVBACKEND_SELECT;
return flags;
}
......@@ -5094,4 +5094,3 @@ ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_THROW
#if EV_MULTIPLICITY
#include "ev_wrap.h"
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment