tblib-0.1.0/0000775000175000017500000000000012260420752012152 5ustar jmcjmc00000000000000tblib-0.1.0/LICENSE0000664000175000017500000000244012255771450013167 0ustar jmcjmc00000000000000Copyright (c) 2011, Ionel Cristian Maries All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.tblib-0.1.0/setup.py0000664000175000017500000000235612260420562013671 0ustar jmcjmc00000000000000# -*- encoding: utf8 -*- from setuptools import setup, find_packages import os setup( name = "tblib", version = "0.1.0", url = 'https://github.com/ionelmc/python-tblib', download_url = '', license = 'BSD', description = "Traceback fiddling library.", long_description = open(os.path.join(os.path.dirname(__file__), 'README.rst')).read(), author = 'Ionel Cristian Mărieș', author_email = 'contact@ionelmc.ro', packages = find_packages('src'), package_dir = {'':'src'}, include_package_data = True, zip_safe = False, classifiers = [ 'Development Status :: 4 - Beta', 'Intended Audience :: Developers', 'License :: OSI Approved :: BSD License', 'Operating System :: Unix', 'Operating System :: POSIX', 'Programming Language :: Python', 'Topic :: Software Development :: Debuggers', 'Topic :: Utilities', 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: Implementation :: CPython', 'Programming Language :: Python :: Implementation :: PyPy', ], install_requires=[ 'six', ] ) tblib-0.1.0/tox.ini0000664000175000017500000000114312260414423013462 0ustar jmcjmc00000000000000[tox] envlist = py, py2.7, py3.2, py3.3, pypy [testenv] setenv = PYTHONPATH = {toxinidir}/src:{toxinidir}/tests WITH_COVERAGE = x PYTHONUNBUFFERED = x commands = {envpython} {toxinidir}/tests/test_tblib.py [base] deps = coverage ;nose ;yanc ;nose-timelimit [testenv:py] basepython = python deps = {[base]deps} [testenv:py2.7] basepython = python2.7 deps = {[base]deps} [testenv:py3.2] basepython = python3.2 deps = {[base]deps} [testenv:py3.3] basepython = python3.3 deps = {[base]deps} [testenv:pypy] basepython = pypy deps = {[base]deps} tblib-0.1.0/tests/0000775000175000017500000000000012260420752013314 5ustar jmcjmc00000000000000tblib-0.1.0/tests/test_tblib.py0000664000175000017500000000103012260413324016010 0ustar jmcjmc00000000000000import sys import doctest #if sys.version_info[0] == 2 and sys.version_info[1] == 6: # import pth # pth.PathError.__name__ = 'pth.' + pth.PathError.__name__ # pth.PathMustBeFile.__name__ = 'pth.' + pth.PathMustBeFile.__name__ # pth.PathMustBeDirectory.__name__ = 'pth.' + pth.PathMustBeDirectory.__name__ # pth.PathDoesNotExist.__name__ = 'pth.' + pth.PathDoesNotExist.__name__ results = doctest.testfile('../README.rst', optionflags=doctest.ELLIPSIS) print(results) if results.failed: sys.exit(1) tblib-0.1.0/tests/examples.py0000664000175000017500000000021312260412656015504 0ustar jmcjmc00000000000000def func_a(_): func_b() def func_b(): func_c() def func_c(): func_d() def func_d(): raise Exception("Guessing time !") tblib-0.1.0/PKG-INFO0000664000175000017500000002372312260420752013256 0ustar jmcjmc00000000000000Metadata-Version: 1.1 Name: tblib Version: 0.1.0 Summary: Traceback fiddling library. Home-page: https://github.com/ionelmc/python-tblib Author: Ionel Cristian Mărieș Author-email: contact@ionelmc.ro License: BSD Description: ========================== python-tblib ========================== .. image:: https://secure.travis-ci.org/ionelmc/python-tblib.png?branch=master :alt: Build Status :target: http://travis-ci.org/ionelmc/python-tblib .. image:: https://coveralls.io/repos/ionelmc/python-tblib/badge.png?branch=master :alt: Coverage Status :target: https://coveralls.io/r/ionelmc/python-tblib .. image:: https://badge.fury.io/py/tblib.png :alt: PYPI Package :target: https://pypi.python.org/pypi/tblib Traceback fiddling library. Pickling tracebacks =================== **Note**: The traceback objects that come out are stripped of some attributes (like variables). But you'll be able to raise exceptions with those tracebacks or print them - that should cover 99% of the usecases. :: >>> from tblib import pickling_support >>> pickling_support.install() >>> import pickle, sys >>> def inner_0(): ... raise Exception('fail') ... >>> def inner_1(): ... inner_0() ... >>> def inner_2(): ... inner_1() ... >>> try: ... inner_2() ... except: ... s1 = pickle.dumps(sys.exc_info()) ... >>> len(s1) > 1 True >>> try: ... inner_2() ... except: ... s2 = pickle.dumps(sys.exc_info(), protocol=pickle.HIGHEST_PROTOCOL) ... >>> len(s2) > 1 True >>> try: ... import cPickle ... except ImportError: ... import pickle as cPickle >>> try: ... inner_2() ... except: ... s3 = cPickle.dumps(sys.exc_info(), protocol=pickle.HIGHEST_PROTOCOL) ... >>> len(s3) > 1 True Unpickling ---------- :: >>> pickle.loads(s1) (<...Exception'>, Exception('fail',), ) >>> pickle.loads(s2) (<...Exception'>, Exception('fail',), ) >>> pickle.loads(s3) (<...Exception'>, Exception('fail',), ) Raising ------- :: >>> from six import reraise >>> reraise(*pickle.loads(s1)) Traceback (most recent call last): ... File "", line 1, in reraise(*pickle.loads(s2)) File "", line 2, in inner_2() File "", line 2, in inner_2 inner_1() File "", line 2, in inner_1 inner_0() File "", line 2, in inner_0 raise Exception('fail') Exception: fail >>> reraise(*pickle.loads(s2)) Traceback (most recent call last): ... File "", line 1, in reraise(*pickle.loads(s2)) File "", line 2, in inner_2() File "", line 2, in inner_2 inner_1() File "", line 2, in inner_1 inner_0() File "", line 2, in inner_0 raise Exception('fail') Exception: fail >>> reraise(*pickle.loads(s3)) Traceback (most recent call last): ... File "", line 1, in reraise(*pickle.loads(s2)) File "", line 2, in inner_2() File "", line 2, in inner_2 inner_1() File "", line 2, in inner_1 inner_0() File "", line 2, in inner_0 raise Exception('fail') Exception: fail The tblib.Traceback object ========================== It is used by the ``pickling_support``. You can use it too if you want more flexibility:: >>> from tblib import Traceback >>> try: ... inner_2() ... except: ... et, ev, tb = sys.exc_info() ... tb = Traceback(tb) ... reraise(et, ev, tb.as_traceback()) ... Traceback (most recent call last): ... File "", line 6, in reraise(et, ev, tb.as_traceback()) File "", line 2, in inner_2() File "", line 2, in inner_2 inner_1() File "", line 2, in inner_1 inner_0() File "", line 2, in inner_0 raise Exception('fail') Exception: fail Decorators ========== return_error ------------ :: >>> from tblib.decorators import return_error >>> inner_2r = return_error(inner_2) >>> e = inner_2r() >>> e >>> e.reraise() Traceback (most recent call last): ... File "", line 1, in e.reraise() File ".../tblib/decorators.py", line 19, in reraise reraise(self.exc_type, self.exc_value, self.traceback) File ".../tblib/decorators.py", line 25, in return_exceptions_wrapper return func(*args, **kwargs) File "", line 2, in inner_2 inner_1() File "", line 2, in inner_1 inner_0() File "", line 2, in inner_0 raise Exception('fail') Exception: fail How's this useful ? Imagine you're using multiprocessing like this:: >>> import traceback >>> from multiprocessing import Pool >>> from examples import func_a >>> pool = Pool() >>> try: ... for i in pool.map(func_a, range(5)): ... print(i) ... except: ... print(traceback.format_exc()) ... Traceback (most recent call last): File "", line 2, in for i in pool.map(func_a, range(5)): File "/usr/lib/.../multiprocessing/pool.py", line ..., in map return self.map_async(func, iterable, chunksize).get() File "/usr/lib/.../multiprocessing/pool.py", line ..., in get raise self._value Exception: Guessing time ! >>> pool.terminate() Not very useful is it? Let's sort this out:: >>> from tblib.decorators import apply_with_return_error, Error >>> from itertools import repeat >>> pool = Pool() >>> try: ... for i in pool.map(apply_with_return_error, zip(repeat(func_a), range(5))): ... if isinstance(i, Error): ... i.reraise() ... else: ... print(i) ... except: ... print(traceback.format_exc()) ... Traceback (most recent call last): File "", line 4, in i.reraise() File ".../tblib/decorators.py", line ..., in reraise reraise(self.exc_type, self.exc_value, self.traceback) File ".../tblib/decorators.py", line ..., in return_exceptions_wrapper return func(*args, **kwargs) File ".../tblib/decorators.py", line ..., in apply_with_return_error return args[0](*args[1:]) File ".../examples.py", line 2, in func_a func_b() File ".../examples.py", line 5, in func_b func_c() File ".../examples.py", line 8, in func_c func_d() File ".../examples.py", line 11, in func_d raise Exception("Guessing time !") Exception: Guessing time ! >>> pool.terminate() Much better ! Platform: UNKNOWN Classifier: Development Status :: 4 - Beta Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Operating System :: Unix Classifier: Operating System :: POSIX Classifier: Programming Language :: Python Classifier: Topic :: Software Development :: Debuggers Classifier: Topic :: Utilities Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy tblib-0.1.0/README.rst0000664000175000017500000001630512260420652013645 0ustar jmcjmc00000000000000========================== python-tblib ========================== .. image:: https://secure.travis-ci.org/ionelmc/python-tblib.png?branch=master :alt: Build Status :target: http://travis-ci.org/ionelmc/python-tblib .. image:: https://coveralls.io/repos/ionelmc/python-tblib/badge.png?branch=master :alt: Coverage Status :target: https://coveralls.io/r/ionelmc/python-tblib .. image:: https://badge.fury.io/py/tblib.png :alt: PYPI Package :target: https://pypi.python.org/pypi/tblib Traceback fiddling library. Pickling tracebacks =================== **Note**: The traceback objects that come out are stripped of some attributes (like variables). But you'll be able to raise exceptions with those tracebacks or print them - that should cover 99% of the usecases. :: >>> from tblib import pickling_support >>> pickling_support.install() >>> import pickle, sys >>> def inner_0(): ... raise Exception('fail') ... >>> def inner_1(): ... inner_0() ... >>> def inner_2(): ... inner_1() ... >>> try: ... inner_2() ... except: ... s1 = pickle.dumps(sys.exc_info()) ... >>> len(s1) > 1 True >>> try: ... inner_2() ... except: ... s2 = pickle.dumps(sys.exc_info(), protocol=pickle.HIGHEST_PROTOCOL) ... >>> len(s2) > 1 True >>> try: ... import cPickle ... except ImportError: ... import pickle as cPickle >>> try: ... inner_2() ... except: ... s3 = cPickle.dumps(sys.exc_info(), protocol=pickle.HIGHEST_PROTOCOL) ... >>> len(s3) > 1 True Unpickling ---------- :: >>> pickle.loads(s1) (<...Exception'>, Exception('fail',), ) >>> pickle.loads(s2) (<...Exception'>, Exception('fail',), ) >>> pickle.loads(s3) (<...Exception'>, Exception('fail',), ) Raising ------- :: >>> from six import reraise >>> reraise(*pickle.loads(s1)) Traceback (most recent call last): ... File "", line 1, in reraise(*pickle.loads(s2)) File "", line 2, in inner_2() File "", line 2, in inner_2 inner_1() File "", line 2, in inner_1 inner_0() File "", line 2, in inner_0 raise Exception('fail') Exception: fail >>> reraise(*pickle.loads(s2)) Traceback (most recent call last): ... File "", line 1, in reraise(*pickle.loads(s2)) File "", line 2, in inner_2() File "", line 2, in inner_2 inner_1() File "", line 2, in inner_1 inner_0() File "", line 2, in inner_0 raise Exception('fail') Exception: fail >>> reraise(*pickle.loads(s3)) Traceback (most recent call last): ... File "", line 1, in reraise(*pickle.loads(s2)) File "", line 2, in inner_2() File "", line 2, in inner_2 inner_1() File "", line 2, in inner_1 inner_0() File "", line 2, in inner_0 raise Exception('fail') Exception: fail The tblib.Traceback object ========================== It is used by the ``pickling_support``. You can use it too if you want more flexibility:: >>> from tblib import Traceback >>> try: ... inner_2() ... except: ... et, ev, tb = sys.exc_info() ... tb = Traceback(tb) ... reraise(et, ev, tb.as_traceback()) ... Traceback (most recent call last): ... File "", line 6, in reraise(et, ev, tb.as_traceback()) File "", line 2, in inner_2() File "", line 2, in inner_2 inner_1() File "", line 2, in inner_1 inner_0() File "", line 2, in inner_0 raise Exception('fail') Exception: fail Decorators ========== return_error ------------ :: >>> from tblib.decorators import return_error >>> inner_2r = return_error(inner_2) >>> e = inner_2r() >>> e >>> e.reraise() Traceback (most recent call last): ... File "", line 1, in e.reraise() File ".../tblib/decorators.py", line 19, in reraise reraise(self.exc_type, self.exc_value, self.traceback) File ".../tblib/decorators.py", line 25, in return_exceptions_wrapper return func(*args, **kwargs) File "", line 2, in inner_2 inner_1() File "", line 2, in inner_1 inner_0() File "", line 2, in inner_0 raise Exception('fail') Exception: fail How's this useful ? Imagine you're using multiprocessing like this:: >>> import traceback >>> from multiprocessing import Pool >>> from examples import func_a >>> pool = Pool() >>> try: ... for i in pool.map(func_a, range(5)): ... print(i) ... except: ... print(traceback.format_exc()) ... Traceback (most recent call last): File "", line 2, in for i in pool.map(func_a, range(5)): File "/usr/lib/.../multiprocessing/pool.py", line ..., in map return self.map_async(func, iterable, chunksize).get() File "/usr/lib/.../multiprocessing/pool.py", line ..., in get raise self._value Exception: Guessing time ! >>> pool.terminate() Not very useful is it? Let's sort this out:: >>> from tblib.decorators import apply_with_return_error, Error >>> from itertools import repeat >>> pool = Pool() >>> try: ... for i in pool.map(apply_with_return_error, zip(repeat(func_a), range(5))): ... if isinstance(i, Error): ... i.reraise() ... else: ... print(i) ... except: ... print(traceback.format_exc()) ... Traceback (most recent call last): File "", line 4, in i.reraise() File ".../tblib/decorators.py", line ..., in reraise reraise(self.exc_type, self.exc_value, self.traceback) File ".../tblib/decorators.py", line ..., in return_exceptions_wrapper return func(*args, **kwargs) File ".../tblib/decorators.py", line ..., in apply_with_return_error return args[0](*args[1:]) File ".../examples.py", line 2, in func_a func_b() File ".../examples.py", line 5, in func_b func_c() File ".../examples.py", line 8, in func_c func_d() File ".../examples.py", line 11, in func_d raise Exception("Guessing time !") Exception: Guessing time ! >>> pool.terminate() Much better ! tblib-0.1.0/setup.cfg0000664000175000017500000000007312260420752013773 0ustar jmcjmc00000000000000[egg_info] tag_build = tag_date = 0 tag_svn_revision = 0 tblib-0.1.0/src/0000775000175000017500000000000012260420752012741 5ustar jmcjmc00000000000000tblib-0.1.0/src/tblib.egg-info/0000775000175000017500000000000012260420752015527 5ustar jmcjmc00000000000000tblib-0.1.0/src/tblib.egg-info/dependency_links.txt0000664000175000017500000000000112260420750021573 0ustar jmcjmc00000000000000 tblib-0.1.0/src/tblib.egg-info/top_level.txt0000664000175000017500000000000612260420750020253 0ustar jmcjmc00000000000000tblib tblib-0.1.0/src/tblib.egg-info/not-zip-safe0000664000175000017500000000000112260405451017754 0ustar jmcjmc00000000000000 tblib-0.1.0/src/tblib.egg-info/SOURCES.txt0000664000175000017500000000057212260420750017415 0ustar jmcjmc00000000000000LICENSE MANIFEST.in README.rst setup.py tox.ini src/tblib/__init__.py src/tblib/cpython.py src/tblib/decorators.py src/tblib/pickling_support.py src/tblib.egg-info/PKG-INFO src/tblib.egg-info/SOURCES.txt src/tblib.egg-info/dependency_links.txt src/tblib.egg-info/not-zip-safe src/tblib.egg-info/requires.txt src/tblib.egg-info/top_level.txt tests/examples.py tests/test_tblib.pytblib-0.1.0/src/tblib.egg-info/PKG-INFO0000664000175000017500000002372312260420750016631 0ustar jmcjmc00000000000000Metadata-Version: 1.1 Name: tblib Version: 0.1.0 Summary: Traceback fiddling library. Home-page: https://github.com/ionelmc/python-tblib Author: Ionel Cristian Mărieș Author-email: contact@ionelmc.ro License: BSD Description: ========================== python-tblib ========================== .. image:: https://secure.travis-ci.org/ionelmc/python-tblib.png?branch=master :alt: Build Status :target: http://travis-ci.org/ionelmc/python-tblib .. image:: https://coveralls.io/repos/ionelmc/python-tblib/badge.png?branch=master :alt: Coverage Status :target: https://coveralls.io/r/ionelmc/python-tblib .. image:: https://badge.fury.io/py/tblib.png :alt: PYPI Package :target: https://pypi.python.org/pypi/tblib Traceback fiddling library. Pickling tracebacks =================== **Note**: The traceback objects that come out are stripped of some attributes (like variables). But you'll be able to raise exceptions with those tracebacks or print them - that should cover 99% of the usecases. :: >>> from tblib import pickling_support >>> pickling_support.install() >>> import pickle, sys >>> def inner_0(): ... raise Exception('fail') ... >>> def inner_1(): ... inner_0() ... >>> def inner_2(): ... inner_1() ... >>> try: ... inner_2() ... except: ... s1 = pickle.dumps(sys.exc_info()) ... >>> len(s1) > 1 True >>> try: ... inner_2() ... except: ... s2 = pickle.dumps(sys.exc_info(), protocol=pickle.HIGHEST_PROTOCOL) ... >>> len(s2) > 1 True >>> try: ... import cPickle ... except ImportError: ... import pickle as cPickle >>> try: ... inner_2() ... except: ... s3 = cPickle.dumps(sys.exc_info(), protocol=pickle.HIGHEST_PROTOCOL) ... >>> len(s3) > 1 True Unpickling ---------- :: >>> pickle.loads(s1) (<...Exception'>, Exception('fail',), ) >>> pickle.loads(s2) (<...Exception'>, Exception('fail',), ) >>> pickle.loads(s3) (<...Exception'>, Exception('fail',), ) Raising ------- :: >>> from six import reraise >>> reraise(*pickle.loads(s1)) Traceback (most recent call last): ... File "", line 1, in reraise(*pickle.loads(s2)) File "", line 2, in inner_2() File "", line 2, in inner_2 inner_1() File "", line 2, in inner_1 inner_0() File "", line 2, in inner_0 raise Exception('fail') Exception: fail >>> reraise(*pickle.loads(s2)) Traceback (most recent call last): ... File "", line 1, in reraise(*pickle.loads(s2)) File "", line 2, in inner_2() File "", line 2, in inner_2 inner_1() File "", line 2, in inner_1 inner_0() File "", line 2, in inner_0 raise Exception('fail') Exception: fail >>> reraise(*pickle.loads(s3)) Traceback (most recent call last): ... File "", line 1, in reraise(*pickle.loads(s2)) File "", line 2, in inner_2() File "", line 2, in inner_2 inner_1() File "", line 2, in inner_1 inner_0() File "", line 2, in inner_0 raise Exception('fail') Exception: fail The tblib.Traceback object ========================== It is used by the ``pickling_support``. You can use it too if you want more flexibility:: >>> from tblib import Traceback >>> try: ... inner_2() ... except: ... et, ev, tb = sys.exc_info() ... tb = Traceback(tb) ... reraise(et, ev, tb.as_traceback()) ... Traceback (most recent call last): ... File "", line 6, in reraise(et, ev, tb.as_traceback()) File "", line 2, in inner_2() File "", line 2, in inner_2 inner_1() File "", line 2, in inner_1 inner_0() File "", line 2, in inner_0 raise Exception('fail') Exception: fail Decorators ========== return_error ------------ :: >>> from tblib.decorators import return_error >>> inner_2r = return_error(inner_2) >>> e = inner_2r() >>> e >>> e.reraise() Traceback (most recent call last): ... File "", line 1, in e.reraise() File ".../tblib/decorators.py", line 19, in reraise reraise(self.exc_type, self.exc_value, self.traceback) File ".../tblib/decorators.py", line 25, in return_exceptions_wrapper return func(*args, **kwargs) File "", line 2, in inner_2 inner_1() File "", line 2, in inner_1 inner_0() File "", line 2, in inner_0 raise Exception('fail') Exception: fail How's this useful ? Imagine you're using multiprocessing like this:: >>> import traceback >>> from multiprocessing import Pool >>> from examples import func_a >>> pool = Pool() >>> try: ... for i in pool.map(func_a, range(5)): ... print(i) ... except: ... print(traceback.format_exc()) ... Traceback (most recent call last): File "", line 2, in for i in pool.map(func_a, range(5)): File "/usr/lib/.../multiprocessing/pool.py", line ..., in map return self.map_async(func, iterable, chunksize).get() File "/usr/lib/.../multiprocessing/pool.py", line ..., in get raise self._value Exception: Guessing time ! >>> pool.terminate() Not very useful is it? Let's sort this out:: >>> from tblib.decorators import apply_with_return_error, Error >>> from itertools import repeat >>> pool = Pool() >>> try: ... for i in pool.map(apply_with_return_error, zip(repeat(func_a), range(5))): ... if isinstance(i, Error): ... i.reraise() ... else: ... print(i) ... except: ... print(traceback.format_exc()) ... Traceback (most recent call last): File "", line 4, in i.reraise() File ".../tblib/decorators.py", line ..., in reraise reraise(self.exc_type, self.exc_value, self.traceback) File ".../tblib/decorators.py", line ..., in return_exceptions_wrapper return func(*args, **kwargs) File ".../tblib/decorators.py", line ..., in apply_with_return_error return args[0](*args[1:]) File ".../examples.py", line 2, in func_a func_b() File ".../examples.py", line 5, in func_b func_c() File ".../examples.py", line 8, in func_c func_d() File ".../examples.py", line 11, in func_d raise Exception("Guessing time !") Exception: Guessing time ! >>> pool.terminate() Much better ! Platform: UNKNOWN Classifier: Development Status :: 4 - Beta Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Operating System :: Unix Classifier: Operating System :: POSIX Classifier: Programming Language :: Python Classifier: Topic :: Software Development :: Debuggers Classifier: Topic :: Utilities Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy tblib-0.1.0/src/tblib.egg-info/requires.txt0000664000175000017500000000000312260420750020116 0ustar jmcjmc00000000000000sixtblib-0.1.0/src/tblib/0000775000175000017500000000000012260420752014035 5ustar jmcjmc00000000000000tblib-0.1.0/src/tblib/decorators.py0000664000175000017500000000210712260420213016544 0ustar jmcjmc00000000000000import sys from functools import wraps from six import reraise from . import Traceback class Error(object): def __init__(self, exc_type, exc_value, traceback): self.exc_type = exc_type self.exc_value = exc_value self.__traceback = Traceback(traceback) @property def traceback(self): return self.__traceback.as_traceback() def reraise(self): reraise(self.exc_type, self.exc_value, self.traceback) def return_error(func, exc_type=Exception): @wraps(func) def return_exceptions_wrapper(*args, **kwargs): try: return func(*args, **kwargs) except exc_type as exc: return Error(*sys.exc_info()) return return_exceptions_wrapper returns_error = return_errors = returns_errors = return_error # cause I make too many typos @return_error def apply_with_return_error(args): """ args is a tuple where the first argument is a callable. eg:: apply_with_return_error((func, 1, 2, 3)) - this will call func(1, 2, 3) """ print args[0] return args[0](*args[1:]) tblib-0.1.0/src/tblib/cpython.py0000664000175000017500000000445012260405734016101 0ustar jmcjmc00000000000000""" Taken verbatim from Jinja2. https://github.com/mitsuhiko/jinja2/blob/master/jinja2/debug.py#L267 """ import sys def _init_ugly_crap(): """This function implements a few ugly things so that we can patch the traceback objects. The function returned allows resetting `tb_next` on any python traceback object. Do not attempt to use this on non cpython interpreters """ import ctypes from types import TracebackType # figure out side of _Py_ssize_t if hasattr(ctypes.pythonapi, 'Py_InitModule4_64'): _Py_ssize_t = ctypes.c_int64 else: _Py_ssize_t = ctypes.c_int # regular python class _PyObject(ctypes.Structure): pass _PyObject._fields_ = [ ('ob_refcnt', _Py_ssize_t), ('ob_type', ctypes.POINTER(_PyObject)) ] # python with trace if hasattr(sys, 'getobjects'): class _PyObject(ctypes.Structure): pass _PyObject._fields_ = [ ('_ob_next', ctypes.POINTER(_PyObject)), ('_ob_prev', ctypes.POINTER(_PyObject)), ('ob_refcnt', _Py_ssize_t), ('ob_type', ctypes.POINTER(_PyObject)) ] class _Traceback(_PyObject): pass _Traceback._fields_ = [ ('tb_next', ctypes.POINTER(_Traceback)), ('tb_frame', ctypes.POINTER(_PyObject)), ('tb_lasti', ctypes.c_int), ('tb_lineno', ctypes.c_int) ] 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))): raise TypeError('tb_set_next arguments must be traceback objects') obj = _Traceback.from_address(id(tb)) if tb.tb_next is not None: old = _Traceback.from_address(id(tb.tb_next)) old.ob_refcnt -= 1 if next is None: obj.tb_next = ctypes.POINTER(_Traceback)() else: next = _Traceback.from_address(id(next)) next.ob_refcnt += 1 obj.tb_next = ctypes.pointer(next) return tb_set_next tb_set_next = None try: tb_set_next = _init_ugly_crap() except: import traceback traceback.print_exc() del _init_ugly_crap tblib-0.1.0/src/tblib/__init__.py0000664000175000017500000000604612260420137016151 0ustar jmcjmc00000000000000try: from __pypy__ import tproxy except ImportError: tproxy = None try: from .cpython import tb_set_next except ImportError: tb_set_next = None if not tb_set_next and not tproxy: raise ImportError("Cannot use tblib. Runtime not supported.") import sys from types import CodeType from types import TracebackType PY3 = sys.version_info[0] == 3 class __traceback_maker(Exception): pass class Code(object): def __init__(self, code): self.co_filename = code.co_filename self.co_name = code.co_name self.co_nlocals = code.co_nlocals self.co_stacksize = code.co_stacksize self.co_flags = code.co_flags self.co_firstlineno = code.co_firstlineno self.co_lnotab = code.co_lnotab class Frame(object): def __init__(self, frame): self.f_globals = { 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 if tb.tb_next is None: self.tb_next = None else: self.tb_next = Traceback(tb.tb_next) def as_traceback(self): if tproxy: return tproxy(TracebackType, self.__tproxy_handler) elif tb_set_next: f_code = self.tb_frame.f_code 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, code.co_code, code.co_consts, code.co_names, code.co_varnames, f_code.co_filename, f_code.co_name, code.co_firstlineno, code.co_lnotab, (), () ) else: code = CodeType( 0, f_code.co_nlocals, f_code.co_stacksize, f_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, code.co_lnotab, (), () ) 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()) return tb else: raise RuntimeError("Cannot re-create traceback !") def __tproxy_handler(self, operation, *args, **kwargs): if operation in ('__getattribute__', '__getattr__'): if args[0] == 'tb_next': return self.tb_next and self.tb_next.as_traceback() else: return getattr(self, args[0]) else: return getattr(self, operation)(*args, **kwargs) tblib-0.1.0/src/tblib/pickling_support.py0000664000175000017500000000105712260415114020002 0ustar jmcjmc00000000000000import pickle try: import copy_reg except ImportError: import copyreg as copy_reg from types import TracebackType from . import Frame, Traceback def unpickle_traceback(tb_frame, tb_lineno, tb_next): ret = object.__new__(Traceback) ret.tb_frame = tb_frame ret.tb_lineno = tb_lineno ret.tb_next = tb_next return ret.as_traceback() def pickle_traceback(tb): return unpickle_traceback, (Frame(tb.tb_frame), tb.tb_lineno, tb.tb_next and Traceback(tb.tb_next)) def install(): copy_reg.pickle(TracebackType, pickle_traceback) tblib-0.1.0/MANIFEST.in0000664000175000017500000000016712255771450013724 0ustar jmcjmc00000000000000include README.rst include LICENSE include README include tox.ini recursive-include tests * global-exclude *.pyc *.pyo