Python code.co_filename() Examples
The following are 24
code examples of code.co_filename().
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
code
, or try the search function
.
Example #1
Source File: CLI.py From pycopia with Apache License 2.0 | 6 votes |
def get_generic_cmd(obj, ui, cliclass=GenericCLI, aliases=None, gbl=None): """get a GenericCLI (or other) command set wrapping any class instance object. The wrapped objects public methods have CLI command counterparts automatically created.""" import new from pycopia.methodholder import MethodHolder cmd = cliclass(ui, aliases) if gbl is None: gbl = globals() hashfilter = {} for name in _get_methodnames(obj): if hasattr(cmd, name): continue # don't override already defined methods # all this mess does is introspect the object methods and map it to a CLI # object method of the same name, with a docstring showing the attributes # and their default values, and the actual code mirroring the # _generic_call method in the GenericCLI class. else: obj_meth = getattr(obj, name) if id(obj_meth.__func__) in hashfilter: # filter out aliases continue else: hashfilter[id(obj_meth.__func__)] = True mh = MethodHolder(obj_meth) doc = "%s *\n%s" % (mh, obj_meth.__doc__ or "") code = cliclass._generic_call.func_code nc = new.code(code.co_argcount, code.co_nlocals, code.co_stacksize, code.co_flags, code.co_code, (doc,)+code.co_consts[1:], # replace docstring code.co_names, code.co_varnames, code.co_filename, code.co_name, code.co_firstlineno, code.co_lnotab) f = new.function(nc, gbl, name) m = new.instancemethod(f, cmd, cliclass) setattr(cmd, name, m) cmd._setup(obj, "Object:%s> " % (obj.__class__.__name__,)) return cmd
Example #2
Source File: pdb.py From android_universal with MIT License | 6 votes |
def _runmodule(self, module_name): self._wait_for_mainpyfile = True self._user_requested_quit = False import runpy mod_name, mod_spec, code = runpy._get_module_details(module_name) self.mainpyfile = self.canonic(code.co_filename) import __main__ __main__.__dict__.clear() __main__.__dict__.update({ "__name__": "__main__", "__file__": self.mainpyfile, "__package__": mod_spec.parent, "__loader__": mod_spec.loader, "__spec__": mod_spec, "__builtins__": __builtins__, }) self.run(code)
Example #3
Source File: pdb.py From Imogen with MIT License | 6 votes |
def _runmodule(self, module_name): self._wait_for_mainpyfile = True self._user_requested_quit = False import runpy mod_name, mod_spec, code = runpy._get_module_details(module_name) self.mainpyfile = self.canonic(code.co_filename) import __main__ __main__.__dict__.clear() __main__.__dict__.update({ "__name__": "__main__", "__file__": self.mainpyfile, "__package__": mod_spec.parent, "__loader__": mod_spec.loader, "__spec__": mod_spec, "__builtins__": __builtins__, }) self.run(code)
Example #4
Source File: pdb.py From ironpython3 with Apache License 2.0 | 5 votes |
def defaultFile(self): """Produce a reasonable default.""" filename = self.curframe.f_code.co_filename if filename == '<string>' and self.mainpyfile: filename = self.mainpyfile return filename
Example #5
Source File: pdb.py From android_universal with MIT License | 5 votes |
def defaultFile(self): """Produce a reasonable default.""" filename = self.curframe.f_code.co_filename if filename == '<string>' and self.mainpyfile: filename = self.mainpyfile return filename
Example #6
Source File: pdb.py From android_universal with MIT License | 5 votes |
def user_line(self, frame): """This function is called when we stop or break at this line.""" if self._wait_for_mainpyfile: if (self.mainpyfile != self.canonic(frame.f_code.co_filename) or frame.f_lineno <= 0): return self._wait_for_mainpyfile = False if self.bp_commands(frame): self.interaction(frame, None)
Example #7
Source File: pdb.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def do_longlist(self, arg): """longlist | ll List the whole source code for the current function or frame. """ filename = self.curframe.f_code.co_filename breaklist = self.get_file_breaks(filename) try: lines, lineno = getsourcelines(self.curframe) except OSError as err: self.error(err) return self._print_lines(lines, lineno, breaklist, self.curframe)
Example #8
Source File: pdb.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def defaultFile(self): """Produce a reasonable default.""" filename = self.curframe.f_code.co_filename if filename == '<string>' and self.mainpyfile: filename = self.mainpyfile return filename
Example #9
Source File: pdb.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def user_line(self, frame): """This function is called when we stop or break at this line.""" if self._wait_for_mainpyfile: if (self.mainpyfile != self.canonic(frame.f_code.co_filename) or frame.f_lineno <= 0): return self._wait_for_mainpyfile = False if self.bp_commands(frame): self.interaction(frame, None)
Example #10
Source File: pdb.py From ironpython3 with Apache License 2.0 | 5 votes |
def do_longlist(self, arg): """longlist | ll List the whole source code for the current function or frame. """ filename = self.curframe.f_code.co_filename breaklist = self.get_file_breaks(filename) try: lines, lineno = getsourcelines(self.curframe) except OSError as err: self.error(err) return self._print_lines(lines, lineno, breaklist, self.curframe)
Example #11
Source File: pdb.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def defaultFile(self): """Produce a reasonable default.""" filename = self.curframe.f_code.co_filename if filename == '<string>' and self.mainpyfile: filename = self.mainpyfile return filename
Example #12
Source File: pdb.py From ironpython3 with Apache License 2.0 | 5 votes |
def user_line(self, frame): """This function is called when we stop or break at this line.""" if self._wait_for_mainpyfile: if (self.mainpyfile != self.canonic(frame.f_code.co_filename) or frame.f_lineno <= 0): return self._wait_for_mainpyfile = False if self.bp_commands(frame): self.interaction(frame, None)
Example #13
Source File: pdb.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def user_line(self, frame): """This function is called when we stop or break at this line.""" if self._wait_for_mainpyfile: if (self.mainpyfile != self.canonic(frame.f_code.co_filename) or frame.f_lineno <= 0): return self._wait_for_mainpyfile = False if self.bp_commands(frame): self.interaction(frame, None)
Example #14
Source File: pdb.py From Imogen with MIT License | 5 votes |
def do_longlist(self, arg): """longlist | ll List the whole source code for the current function or frame. """ filename = self.curframe.f_code.co_filename breaklist = self.get_file_breaks(filename) try: lines, lineno = getsourcelines(self.curframe) except OSError as err: self.error(err) return self._print_lines(lines, lineno, breaklist, self.curframe)
Example #15
Source File: pdb.py From android_universal with MIT License | 5 votes |
def do_longlist(self, arg): """longlist | ll List the whole source code for the current function or frame. """ filename = self.curframe.f_code.co_filename breaklist = self.get_file_breaks(filename) try: lines, lineno = getsourcelines(self.curframe) except OSError as err: self.error(err) return self._print_lines(lines, lineno, breaklist, self.curframe)
Example #16
Source File: pdb.py From Imogen with MIT License | 5 votes |
def defaultFile(self): """Produce a reasonable default.""" filename = self.curframe.f_code.co_filename if filename == '<string>' and self.mainpyfile: filename = self.mainpyfile return filename
Example #17
Source File: pdb.py From Imogen with MIT License | 5 votes |
def user_line(self, frame): """This function is called when we stop or break at this line.""" if self._wait_for_mainpyfile: if (self.mainpyfile != self.canonic(frame.f_code.co_filename) or frame.f_lineno <= 0): return self._wait_for_mainpyfile = False if self.bp_commands(frame): self.interaction(frame, None)
Example #18
Source File: pdb.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def do_longlist(self, arg): """longlist | ll List the whole source code for the current function or frame. """ filename = self.curframe.f_code.co_filename breaklist = self.get_file_breaks(filename) try: lines, lineno = getsourcelines(self.curframe) except OSError as err: self.error(err) return self._print_lines(lines, lineno, breaklist, self.curframe)
Example #19
Source File: CLI.py From pycopia with Apache License 2.0 | 5 votes |
def get_generic_cmd(obj, ui, cliclass=GenericCLI, aliases=None, gbl=None): """get a GenericCLI (or other) command set wrapping any class instance object. The wrapped objects public methods have CLI command counterparts automatically created.""" import new from methodholder import MethodHolder cmd = cliclass(ui, aliases) if gbl is None: gbl = globals() hashfilter = {} for name in _get_methodnames(obj): if hasattr(cmd, name): continue # don't override already defined methods # all this mess does is introspect the object methods and map it to a CLI # object method of the same name, with a docstring showing the attributes # and their default values, and the actual code mirroring the # _generic_call method in the GenericCLI class. else: obj_meth = getattr(obj, name) if id(obj_meth.im_func) in hashfilter: # filter out aliases continue else: hashfilter[id(obj_meth.im_func)] = True mh = MethodHolder(obj_meth) doc = "%s *\n%s" % (mh, obj_meth.__doc__ or "") code = cliclass._generic_call.func_code nc = new.code(code.co_argcount, code.co_nlocals, code.co_stacksize, code.co_flags, code.co_code, (doc,)+code.co_consts[1:], # replace docstring code.co_names, code.co_varnames, code.co_filename, code.co_name, code.co_firstlineno, code.co_lnotab) f = new.function(nc, gbl, name) m = new.instancemethod(f, cmd, cliclass) setattr(cmd, name, m) cmd._setup(obj, "Object:%s> " % (obj.__class__.__name__,)) return cmd
Example #20
Source File: pdb.py From ironpython3 with Apache License 2.0 | 4 votes |
def do_list(self, arg): """l(ist) [first [,last] | .] List source code for the current file. Without arguments, list 11 lines around the current line or continue the previous listing. With . as argument, list 11 lines around the current line. With one argument, list 11 lines starting at that line. With two arguments, list the given range; if the second argument is less than the first, it is a count. The current line in the current frame is indicated by "->". If an exception is being debugged, the line where the exception was originally raised or propagated is indicated by ">>", if it differs from the current line. """ self.lastcmd = 'list' last = None if arg and arg != '.': try: if ',' in arg: first, last = arg.split(',') first = int(first.strip()) last = int(last.strip()) if last < first: # assume it's a count last = first + last else: first = int(arg.strip()) first = max(1, first - 5) except ValueError: self.error('Error in argument: %r' % arg) return elif self.lineno is None or arg == '.': first = max(1, self.curframe.f_lineno - 5) else: first = self.lineno + 1 if last is None: last = first + 10 filename = self.curframe.f_code.co_filename breaklist = self.get_file_breaks(filename) try: lines = linecache.getlines(filename, self.curframe.f_globals) self._print_lines(lines[first-1:last], first, breaklist, self.curframe) self.lineno = min(last, len(lines)) if len(lines) < last: self.message('[EOF]') except KeyboardInterrupt: pass
Example #21
Source File: pdb.py From android_universal with MIT License | 4 votes |
def do_list(self, arg): """l(ist) [first [,last] | .] List source code for the current file. Without arguments, list 11 lines around the current line or continue the previous listing. With . as argument, list 11 lines around the current line. With one argument, list 11 lines starting at that line. With two arguments, list the given range; if the second argument is less than the first, it is a count. The current line in the current frame is indicated by "->". If an exception is being debugged, the line where the exception was originally raised or propagated is indicated by ">>", if it differs from the current line. """ self.lastcmd = 'list' last = None if arg and arg != '.': try: if ',' in arg: first, last = arg.split(',') first = int(first.strip()) last = int(last.strip()) if last < first: # assume it's a count last = first + last else: first = int(arg.strip()) first = max(1, first - 5) except ValueError: self.error('Error in argument: %r' % arg) return elif self.lineno is None or arg == '.': first = max(1, self.curframe.f_lineno - 5) else: first = self.lineno + 1 if last is None: last = first + 10 filename = self.curframe.f_code.co_filename breaklist = self.get_file_breaks(filename) try: lines = linecache.getlines(filename, self.curframe.f_globals) self._print_lines(lines[first-1:last], first, breaklist, self.curframe) self.lineno = min(last, len(lines)) if len(lines) < last: self.message('[EOF]') except KeyboardInterrupt: pass
Example #22
Source File: pdb.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 4 votes |
def do_list(self, arg): """l(ist) [first [,last] | .] List source code for the current file. Without arguments, list 11 lines around the current line or continue the previous listing. With . as argument, list 11 lines around the current line. With one argument, list 11 lines starting at that line. With two arguments, list the given range; if the second argument is less than the first, it is a count. The current line in the current frame is indicated by "->". If an exception is being debugged, the line where the exception was originally raised or propagated is indicated by ">>", if it differs from the current line. """ self.lastcmd = 'list' last = None if arg and arg != '.': try: if ',' in arg: first, last = arg.split(',') first = int(first.strip()) last = int(last.strip()) if last < first: # assume it's a count last = first + last else: first = int(arg.strip()) first = max(1, first - 5) except ValueError: self.error('Error in argument: %r' % arg) return elif self.lineno is None or arg == '.': first = max(1, self.curframe.f_lineno - 5) else: first = self.lineno + 1 if last is None: last = first + 10 filename = self.curframe.f_code.co_filename breaklist = self.get_file_breaks(filename) try: lines = linecache.getlines(filename, self.curframe.f_globals) self._print_lines(lines[first-1:last], first, breaklist, self.curframe) self.lineno = min(last, len(lines)) if len(lines) < last: self.message('[EOF]') except KeyboardInterrupt: pass
Example #23
Source File: pdb.py From Imogen with MIT License | 4 votes |
def do_list(self, arg): """l(ist) [first [,last] | .] List source code for the current file. Without arguments, list 11 lines around the current line or continue the previous listing. With . as argument, list 11 lines around the current line. With one argument, list 11 lines starting at that line. With two arguments, list the given range; if the second argument is less than the first, it is a count. The current line in the current frame is indicated by "->". If an exception is being debugged, the line where the exception was originally raised or propagated is indicated by ">>", if it differs from the current line. """ self.lastcmd = 'list' last = None if arg and arg != '.': try: if ',' in arg: first, last = arg.split(',') first = int(first.strip()) last = int(last.strip()) if last < first: # assume it's a count last = first + last else: first = int(arg.strip()) first = max(1, first - 5) except ValueError: self.error('Error in argument: %r' % arg) return elif self.lineno is None or arg == '.': first = max(1, self.curframe.f_lineno - 5) else: first = self.lineno + 1 if last is None: last = first + 10 filename = self.curframe.f_code.co_filename breaklist = self.get_file_breaks(filename) try: lines = linecache.getlines(filename, self.curframe.f_globals) self._print_lines(lines[first-1:last], first, breaklist, self.curframe) self.lineno = min(last, len(lines)) if len(lines) < last: self.message('[EOF]') except KeyboardInterrupt: pass
Example #24
Source File: pdb.py From Fluid-Designer with GNU General Public License v3.0 | 4 votes |
def do_list(self, arg): """l(ist) [first [,last] | .] List source code for the current file. Without arguments, list 11 lines around the current line or continue the previous listing. With . as argument, list 11 lines around the current line. With one argument, list 11 lines starting at that line. With two arguments, list the given range; if the second argument is less than the first, it is a count. The current line in the current frame is indicated by "->". If an exception is being debugged, the line where the exception was originally raised or propagated is indicated by ">>", if it differs from the current line. """ self.lastcmd = 'list' last = None if arg and arg != '.': try: if ',' in arg: first, last = arg.split(',') first = int(first.strip()) last = int(last.strip()) if last < first: # assume it's a count last = first + last else: first = int(arg.strip()) first = max(1, first - 5) except ValueError: self.error('Error in argument: %r' % arg) return elif self.lineno is None or arg == '.': first = max(1, self.curframe.f_lineno - 5) else: first = self.lineno + 1 if last is None: last = first + 10 filename = self.curframe.f_code.co_filename breaklist = self.get_file_breaks(filename) try: lines = linecache.getlines(filename, self.curframe.f_globals) self._print_lines(lines[first-1:last], first, breaklist, self.curframe) self.lineno = min(last, len(lines)) if len(lines) < last: self.message('[EOF]') except KeyboardInterrupt: pass