Python inspect.istraceback() Examples
The following are 30
code examples of inspect.istraceback().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
inspect
, or try the search function
.
Example #1
Source File: test_inspect.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
def test_excluding_predicates(self): #self.istest(inspect.isbuiltin, 'sys.exit') # Not valid for Jython self.istest(inspect.isbuiltin, '[].append') self.istest(inspect.iscode, 'mod.spam.func_code') self.istest(inspect.isframe, 'tb.tb_frame') self.istest(inspect.isfunction, 'mod.spam') self.istest(inspect.ismethod, 'mod.StupidGit.abuse') self.istest(inspect.ismethod, 'git.argue') self.istest(inspect.ismodule, 'mod') self.istest(inspect.istraceback, 'tb') self.istest(inspect.isdatadescriptor, '__builtin__.file.closed') self.istest(inspect.isdatadescriptor, '__builtin__.file.softspace') self.istest(inspect.isgenerator, '(x for x in xrange(2))') self.istest(inspect.isgeneratorfunction, 'generator_function_example') if hasattr(types, 'GetSetDescriptorType'): self.istest(inspect.isgetsetdescriptor, 'type(tb.tb_frame).f_locals') else: self.assertFalse(inspect.isgetsetdescriptor(type(tb.tb_frame).f_locals)) if hasattr(types, 'MemberDescriptorType'): # Not valid for Jython # self.istest(inspect.ismemberdescriptor, 'datetime.timedelta.days') pass else: self.assertFalse(inspect.ismemberdescriptor(datetime.timedelta.days))
Example #2
Source File: test_inspect.py From oss-ftp with MIT License | 6 votes |
def test_excluding_predicates(self): self.istest(inspect.isbuiltin, 'sys.exit') self.istest(inspect.isbuiltin, '[].append') self.istest(inspect.iscode, 'mod.spam.func_code') self.istest(inspect.isframe, 'tb.tb_frame') self.istest(inspect.isfunction, 'mod.spam') self.istest(inspect.ismethod, 'mod.StupidGit.abuse') self.istest(inspect.ismethod, 'git.argue') self.istest(inspect.ismodule, 'mod') self.istest(inspect.istraceback, 'tb') self.istest(inspect.isdatadescriptor, '__builtin__.file.closed') self.istest(inspect.isdatadescriptor, '__builtin__.file.softspace') self.istest(inspect.isgenerator, '(x for x in xrange(2))') self.istest(inspect.isgeneratorfunction, 'generator_function_example') if hasattr(types, 'GetSetDescriptorType'): self.istest(inspect.isgetsetdescriptor, 'type(tb.tb_frame).f_locals') else: self.assertFalse(inspect.isgetsetdescriptor(type(tb.tb_frame).f_locals)) if hasattr(types, 'MemberDescriptorType'): self.istest(inspect.ismemberdescriptor, 'datetime.timedelta.days') else: self.assertFalse(inspect.ismemberdescriptor(datetime.timedelta.days))
Example #3
Source File: test_inspect.py From gcblue with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_excluding_predicates(self): self.istest(inspect.isbuiltin, 'sys.exit') self.istest(inspect.isbuiltin, '[].append') self.istest(inspect.iscode, 'mod.spam.func_code') self.istest(inspect.isframe, 'tb.tb_frame') self.istest(inspect.isfunction, 'mod.spam') self.istest(inspect.ismethod, 'mod.StupidGit.abuse') self.istest(inspect.ismethod, 'git.argue') self.istest(inspect.ismodule, 'mod') self.istest(inspect.istraceback, 'tb') self.istest(inspect.isdatadescriptor, '__builtin__.file.closed') self.istest(inspect.isdatadescriptor, '__builtin__.file.softspace') self.istest(inspect.isgenerator, '(x for x in xrange(2))') self.istest(inspect.isgeneratorfunction, 'generator_function_example') if hasattr(types, 'GetSetDescriptorType'): self.istest(inspect.isgetsetdescriptor, 'type(tb.tb_frame).f_locals') else: self.assertFalse(inspect.isgetsetdescriptor(type(tb.tb_frame).f_locals)) if hasattr(types, 'MemberDescriptorType'): self.istest(inspect.ismemberdescriptor, 'datetime.timedelta.days') else: self.assertFalse(inspect.ismemberdescriptor(datetime.timedelta.days))
Example #4
Source File: test_inspect.py From BinderFilter with MIT License | 6 votes |
def test_excluding_predicates(self): self.istest(inspect.isbuiltin, 'sys.exit') self.istest(inspect.isbuiltin, '[].append') self.istest(inspect.iscode, 'mod.spam.func_code') self.istest(inspect.isframe, 'tb.tb_frame') self.istest(inspect.isfunction, 'mod.spam') self.istest(inspect.ismethod, 'mod.StupidGit.abuse') self.istest(inspect.ismethod, 'git.argue') self.istest(inspect.ismodule, 'mod') self.istest(inspect.istraceback, 'tb') self.istest(inspect.isdatadescriptor, '__builtin__.file.closed') self.istest(inspect.isdatadescriptor, '__builtin__.file.softspace') self.istest(inspect.isgenerator, '(x for x in xrange(2))') self.istest(inspect.isgeneratorfunction, 'generator_function_example') if hasattr(types, 'GetSetDescriptorType'): self.istest(inspect.isgetsetdescriptor, 'type(tb.tb_frame).f_locals') else: self.assertFalse(inspect.isgetsetdescriptor(type(tb.tb_frame).f_locals)) if hasattr(types, 'MemberDescriptorType'): self.istest(inspect.ismemberdescriptor, 'datetime.timedelta.days') else: self.assertFalse(inspect.ismemberdescriptor(datetime.timedelta.days))
Example #5
Source File: detect.py From dagbldr with BSD 3-Clause "New" or "Revised" License | 6 votes |
def code(func): '''get the code object for the given function or method NOTE: use dill.source.getsource(CODEOBJ) to get the source code ''' if PY3: im_func = '__func__' func_code = '__code__' else: im_func = 'im_func' func_code = 'func_code' if ismethod(func): func = getattr(func, im_func) if isfunction(func): func = getattr(func, func_code) if istraceback(func): func = func.tb_frame if isframe(func): func = func.f_code if iscode(func): return func return #XXX: ugly: parse dis.dis for name after "<code object" in line and in globals?
Example #6
Source File: source.py From dagbldr with BSD 3-Clause "New" or "Revised" License | 6 votes |
def _isinstance(object): '''True if object is a class instance type (and is not a builtin)''' if _hascode(object) or isclass(object) or ismodule(object): return False if istraceback(object) or isframe(object) or iscode(object): return False # special handling (numpy arrays, ...) if not getmodule(object) and getmodule(type(object)).__name__ in ['numpy']: return True # # check if is instance of a builtin # if not getmodule(object) and getmodule(type(object)).__name__ in ['__builtin__','builtins']: # return False _types = ('<class ',"<type 'instance'>") if not repr(type(object)).startswith(_types): #FIXME: weak hack return False if not getmodule(object) or object.__module__ in ['builtins','__builtin__'] or getname(object, force=True) in ['array']: return False return True # by process of elimination... it's what we want
Example #7
Source File: detect.py From dagbldr with BSD 3-Clause "New" or "Revised" License | 6 votes |
def code(func): '''get the code object for the given function or method NOTE: use dill.source.getsource(CODEOBJ) to get the source code ''' if PY3: im_func = '__func__' func_code = '__code__' else: im_func = 'im_func' func_code = 'func_code' if ismethod(func): func = getattr(func, im_func) if isfunction(func): func = getattr(func, func_code) if istraceback(func): func = func.tb_frame if isframe(func): func = func.f_code if iscode(func): return func return #XXX: ugly: parse dis.dis for name after "<code object" in line and in globals?
Example #8
Source File: source.py From dagbldr with BSD 3-Clause "New" or "Revised" License | 6 votes |
def _isinstance(object): '''True if object is a class instance type (and is not a builtin)''' if _hascode(object) or isclass(object) or ismodule(object): return False if istraceback(object) or isframe(object) or iscode(object): return False # special handling (numpy arrays, ...) if not getmodule(object) and getmodule(type(object)).__name__ in ['numpy']: return True # # check if is instance of a builtin # if not getmodule(object) and getmodule(type(object)).__name__ in ['__builtin__','builtins']: # return False _types = ('<class ',"<type 'instance'>") if not repr(type(object)).startswith(_types): #FIXME: weak hack return False if not getmodule(object) or object.__module__ in ['builtins','__builtin__'] or getname(object, force=True) in ['array']: return False return True # by process of elimination... it's what we want
Example #9
Source File: test_inspect.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_excluding_predicates(self): self.istest(inspect.isbuiltin, 'sys.exit') self.istest(inspect.isbuiltin, '[].append') self.istest(inspect.iscode, 'mod.spam.func_code') self.istest(inspect.isframe, 'tb.tb_frame') self.istest(inspect.isfunction, 'mod.spam') self.istest(inspect.ismethod, 'mod.StupidGit.abuse') self.istest(inspect.ismethod, 'git.argue') self.istest(inspect.ismodule, 'mod') self.istest(inspect.istraceback, 'tb') self.istest(inspect.isdatadescriptor, '__builtin__.file.closed') self.istest(inspect.isdatadescriptor, '__builtin__.file.softspace') self.istest(inspect.isgenerator, '(x for x in xrange(2))') self.istest(inspect.isgeneratorfunction, 'generator_function_example') if hasattr(types, 'GetSetDescriptorType'): self.istest(inspect.isgetsetdescriptor, 'type(tb.tb_frame).f_locals') else: self.assertFalse(inspect.isgetsetdescriptor(type(tb.tb_frame).f_locals)) if hasattr(types, 'MemberDescriptorType'): self.istest(inspect.ismemberdescriptor, 'datetime.timedelta.days') else: self.assertFalse(inspect.ismemberdescriptor(datetime.timedelta.days))
Example #10
Source File: test_inspect.py From CTFCrackTools with GNU General Public License v3.0 | 6 votes |
def test_excluding_predicates(self): #self.istest(inspect.isbuiltin, 'sys.exit') # Not valid for Jython self.istest(inspect.isbuiltin, '[].append') self.istest(inspect.iscode, 'mod.spam.func_code') self.istest(inspect.isframe, 'tb.tb_frame') self.istest(inspect.isfunction, 'mod.spam') self.istest(inspect.ismethod, 'mod.StupidGit.abuse') self.istest(inspect.ismethod, 'git.argue') self.istest(inspect.ismodule, 'mod') self.istest(inspect.istraceback, 'tb') self.istest(inspect.isdatadescriptor, '__builtin__.file.closed') self.istest(inspect.isdatadescriptor, '__builtin__.file.softspace') self.istest(inspect.isgenerator, '(x for x in xrange(2))') self.istest(inspect.isgeneratorfunction, 'generator_function_example') if hasattr(types, 'GetSetDescriptorType'): self.istest(inspect.isgetsetdescriptor, 'type(tb.tb_frame).f_locals') else: self.assertFalse(inspect.isgetsetdescriptor(type(tb.tb_frame).f_locals)) if hasattr(types, 'MemberDescriptorType'): # Not valid for Jython # self.istest(inspect.ismemberdescriptor, 'datetime.timedelta.days') pass else: self.assertFalse(inspect.ismemberdescriptor(datetime.timedelta.days))
Example #11
Source File: pydoc.py From unity-python with MIT License | 5 votes |
def isdata(object): """Check if an object is of a type that probably means it's data.""" return not (inspect.ismodule(object) or inspect.isclass(object) or inspect.isroutine(object) or inspect.isframe(object) or inspect.istraceback(object) or inspect.iscode(object))
Example #12
Source File: test_inspect.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_abuse_done(self): self.istest(inspect.istraceback, 'git.ex[2]') self.istest(inspect.isframe, 'mod.fr')
Example #13
Source File: test_inspect.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_excluding_predicates(self): global tb self.istest(inspect.isbuiltin, 'sys.exit') self.istest(inspect.isbuiltin, '[].append') self.istest(inspect.iscode, 'mod.spam.__code__') try: 1/0 except: tb = sys.exc_info()[2] self.istest(inspect.isframe, 'tb.tb_frame') self.istest(inspect.istraceback, 'tb') if hasattr(types, 'GetSetDescriptorType'): self.istest(inspect.isgetsetdescriptor, 'type(tb.tb_frame).f_locals') else: self.assertFalse(inspect.isgetsetdescriptor(type(tb.tb_frame).f_locals)) finally: # Clear traceback and all the frames and local variables hanging to it. tb = None self.istest(inspect.isfunction, 'mod.spam') self.istest(inspect.isfunction, 'mod.StupidGit.abuse') self.istest(inspect.ismethod, 'git.argue') self.istest(inspect.ismodule, 'mod') self.istest(inspect.isdatadescriptor, 'collections.defaultdict.default_factory') self.istest(inspect.isgenerator, '(x for x in range(2))') self.istest(inspect.isgeneratorfunction, 'generator_function_example') if hasattr(types, 'MemberDescriptorType'): self.istest(inspect.ismemberdescriptor, 'datetime.timedelta.days') else: self.assertFalse(inspect.ismemberdescriptor(datetime.timedelta.days))
Example #14
Source File: pydoc.py From ironpython3 with Apache License 2.0 | 5 votes |
def isdata(object): """Check if an object is of a type that probably means it's data.""" return not (inspect.ismodule(object) or inspect.isclass(object) or inspect.isroutine(object) or inspect.isframe(object) or inspect.istraceback(object) or inspect.iscode(object))
Example #15
Source File: test_inspect.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_abuse_done(self): self.istest(inspect.istraceback, 'git.ex[2]') self.istest(inspect.isframe, 'mod.fr')
Example #16
Source File: exceptions.py From reframe with BSD 3-Clause "New" or "Revised" License | 5 votes |
def user_frame(tb): if not inspect.istraceback(tb): raise ValueError('could not retrieve frame: argument not a traceback') for finfo in reversed(inspect.getinnerframes(tb)): relpath = os.path.relpath(finfo.filename, sys.path[0]) if relpath.split(os.sep)[0] != 'reframe': return finfo return None
Example #17
Source File: pydoc.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def isdata(object): """Check if an object is of a type that probably means it's data.""" return not (inspect.ismodule(object) or inspect.isclass(object) or inspect.isroutine(object) or inspect.isframe(object) or inspect.istraceback(object) or inspect.iscode(object))
Example #18
Source File: pydoc.py From jawfish with MIT License | 5 votes |
def isdata(object): """Check if an object is of a type that probably means it's data.""" return not (inspect.ismodule(object) or inspect.isclass(object) or inspect.isroutine(object) or inspect.isframe(object) or inspect.istraceback(object) or inspect.iscode(object))
Example #19
Source File: test_inspect.py From oss-ftp with MIT License | 5 votes |
def test_abuse_done(self): self.istest(inspect.istraceback, 'git.ex[2]') self.istest(inspect.isframe, 'mod.fr')
Example #20
Source File: pydoc.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def isdata(object): """Check if an object is of a type that probably means it's data.""" return not (inspect.ismodule(object) or inspect.isclass(object) or inspect.isroutine(object) or inspect.isframe(object) or inspect.istraceback(object) or inspect.iscode(object))
Example #21
Source File: test_inspect.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_excluding_predicates(self): global tb self.istest(inspect.isbuiltin, 'sys.exit') self.istest(inspect.isbuiltin, '[].append') self.istest(inspect.iscode, 'mod.spam.__code__') try: 1/0 except: tb = sys.exc_info()[2] self.istest(inspect.isframe, 'tb.tb_frame') self.istest(inspect.istraceback, 'tb') if hasattr(types, 'GetSetDescriptorType'): self.istest(inspect.isgetsetdescriptor, 'type(tb.tb_frame).f_locals') else: self.assertFalse(inspect.isgetsetdescriptor(type(tb.tb_frame).f_locals)) finally: # Clear traceback and all the frames and local variables hanging to it. tb = None self.istest(inspect.isfunction, 'mod.spam') self.istest(inspect.isfunction, 'mod.StupidGit.abuse') self.istest(inspect.ismethod, 'git.argue') self.istest(inspect.ismodule, 'mod') self.istest(inspect.isdatadescriptor, 'collections.defaultdict.default_factory') self.istest(inspect.isgenerator, '(x for x in range(2))') self.istest(inspect.isgeneratorfunction, 'generator_function_example') with warnings.catch_warnings(): warnings.simplefilter("ignore") self.istest(inspect.iscoroutine, 'coroutine_function_example(1)') self.istest(inspect.iscoroutinefunction, 'coroutine_function_example') if hasattr(types, 'MemberDescriptorType'): self.istest(inspect.ismemberdescriptor, 'datetime.timedelta.days') else: self.assertFalse(inspect.ismemberdescriptor(datetime.timedelta.days))
Example #22
Source File: test_inspect.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_abuse_done(self): self.istest(inspect.istraceback, 'git.ex[2]') self.istest(inspect.isframe, 'mod.fr')
Example #23
Source File: pydoc.py From medicare-demo with Apache License 2.0 | 5 votes |
def isdata(object): """Check if an object is of a type that probably means it's data.""" return not (inspect.ismodule(object) or inspect.isclass(object) or inspect.isroutine(object) or inspect.isframe(object) or inspect.istraceback(object) or inspect.iscode(object))
Example #24
Source File: pydoc.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def isdata(object): """Check if an object is of a type that probably means it's data.""" return not (inspect.ismodule(object) or inspect.isclass(object) or inspect.isroutine(object) or inspect.isframe(object) or inspect.istraceback(object) or inspect.iscode(object))
Example #25
Source File: test_inspect.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_excluding_predicates(self): #XXX: Jython's PySystemState needs more work before this #will be doable. if not test_support.is_jython: self.istest(inspect.isbuiltin, 'sys.exit') self.istest(inspect.isbuiltin, '[].append') self.istest(inspect.isclass, 'mod.StupidGit') self.istest(inspect.iscode, 'mod.spam.func_code') self.istest(inspect.isframe, 'tb.tb_frame') self.istest(inspect.isfunction, 'mod.spam') self.istest(inspect.ismethod, 'mod.StupidGit.abuse') self.istest(inspect.ismethod, 'git.argue') self.istest(inspect.ismodule, 'mod') self.istest(inspect.istraceback, 'tb') self.istest(inspect.isdatadescriptor, '__builtin__.file.closed') self.istest(inspect.isdatadescriptor, '__builtin__.file.softspace') if hasattr(types, 'GetSetDescriptorType'): self.istest(inspect.isgetsetdescriptor, 'type(tb.tb_frame).f_locals') #XXX: This detail of PyFrames is not yet supported in Jython elif not test_support.is_jython: self.failIf(inspect.isgetsetdescriptor(type(tb.tb_frame).f_locals)) if hasattr(types, 'MemberDescriptorType'): self.istest(inspect.ismemberdescriptor, 'datetime.timedelta.days') else: self.failIf(inspect.ismemberdescriptor(datetime.timedelta.days))
Example #26
Source File: test_inspect.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_abuse_done(self): self.istest(inspect.istraceback, 'git.ex[2]') self.istest(inspect.isframe, 'mod.fr')
Example #27
Source File: mypydoc.py From azure-linux-extensions with Apache License 2.0 | 5 votes |
def isdata(object): """Check if an object is of a type that probably means it's data.""" return not (inspect.ismodule(object) or inspect.isclass(object) or inspect.isroutine(object) or inspect.isframe(object) or inspect.istraceback(object) or inspect.iscode(object))
Example #28
Source File: pydoc.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def isdata(object): """Check if an object is of a type that probably means it's data.""" return not (inspect.ismodule(object) or inspect.isclass(object) or inspect.isroutine(object) or inspect.isframe(object) or inspect.istraceback(object) or inspect.iscode(object))
Example #29
Source File: pydoc.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def isdata(object): """Check if an object is of a type that probably means it's data.""" return not (inspect.ismodule(object) or inspect.isclass(object) or inspect.isroutine(object) or inspect.isframe(object) or inspect.istraceback(object) or inspect.iscode(object))
Example #30
Source File: pydoc.py From RevitBatchProcessor with GNU General Public License v3.0 | 5 votes |
def isdata(object): """Check if an object is of a type that probably means it's data.""" return not (inspect.ismodule(object) or inspect.isclass(object) or inspect.isroutine(object) or inspect.isframe(object) or inspect.istraceback(object) or inspect.iscode(object))