Vega strike Python Modules doc
0.5.1
Documentation of the " Modules " folder of Vega strike
|
Data Structures | |
class | ListReader |
class | EndOfBlock |
class | BlockFinder |
Functions | |
def | ismodule |
def | isclass |
def | ismethod |
def | ismethoddescriptor |
def | isfunction |
def | istraceback |
def | isframe |
def | iscode |
def | isbuiltin |
def | isroutine |
def | getmembers |
def | classify_class_attrs |
def | getmro |
def | indentsize |
def | getdoc |
def | getfile |
def | getmoduleinfo |
def | getmodulename |
def | getsourcefile |
def | getabsfile |
def | getmodule |
def | findsource |
def | getcomments |
def | getblock |
def | getsourcelines |
def | getsource |
def | walktree |
def | getclasstree |
def | getargs |
def | getargspec |
def | getargvalues |
def | joinseq |
def | strseq |
def | formatargspec |
def | formatargvalues |
def | getframeinfo |
def | getlineno |
def | getouterframes |
def | getinnerframes |
def | currentframe |
def | stack |
def | trace |
Variables | |
string | __author__ = 'Ka-Ping Yee <ping@lfw.org>' |
string | __date__ = '1 Jan 2001' |
dictionary | modulesbyfile = {} |
Get useful information from live Python objects. This module encapsulates the interface provided by the internal special attributes (func_*, co_*, im_*, tb_*, etc.) in a friendlier fashion. It also provides some help for examining source code and class layout. Here are some of the useful functions provided by this module: ismodule(), isclass(), ismethod(), isfunction(), istraceback(), isframe(), iscode(), isbuiltin(), isroutine() - check object types getmembers() - get members of an object that satisfy a given condition getfile(), getsourcefile(), getsource() - find an object's source code getdoc(), getcomments() - get documentation on an object getmodule() - determine the module that an object came from getclasstree() - arrange classes so as to represent their hierarchy getargspec(), getargvalues() - get info about function arguments formatargspec(), formatargvalues() - format an argument spec getouterframes(), getinnerframes() - get info about frames currentframe() - get the current stack frame stack(), trace() - get info about frames on the stack or in a traceback
def inspect.classify_class_attrs | ( | cls) |
Return list of attribute-descriptor tuples. For each name in dir(cls), the return list contains a 4-tuple with these elements: 0. The name (a string). 1. The kind of attribute this is, one of these strings: 'class method' created via classmethod() 'static method' created via staticmethod() 'property' created via property() 'method' any other flavor of method 'data' not a method 2. The class which defined this attribute (a class). 3. The object as obtained directly from the defining class's __dict__, not via getattr. This is especially important for data attributes: C.data is just a data object, but C.__dict__['data'] may be a data descriptor with additional info, like a __doc__ string.
Definition at line 166 of file inspect.py.
References sre_parse.dir, getmro(), ismethod(), and ismethoddescriptor().
def inspect.currentframe | ( | ) |
def inspect.findsource | ( | object) |
Return the entire source file and starting line number for an object. The argument may be a module, class, method, function, traceback, frame, or code object. The source code is returned as a list of all the lines in the file and the line number indexes a line in that list. An IOError is raised if the source code cannot be retrieved.
Definition at line 377 of file inspect.py.
References getsourcefile(), isclass(), iscode(), isframe(), isfunction(), ismethod(), ismodule(), istraceback(), and aifc.open().
def inspect.formatargspec | ( | args, | |
varargs = None , |
|||
varkw = None , |
|||
defaults = None , |
|||
formatarg = str , |
|||
formatvarargs = lambda name: '*' + name , |
|||
formatvarkw = lambda name: '**' + name , |
|||
formatvalue = lambda value: '=' + repr(value) , |
|||
join = joinseq |
|||
) |
Format an argument spec from the 4 values returned by getargspec. The first four arguments are (args, varargs, varkw, defaults). The other four arguments are the corresponding optional formatting functions that are called to turn names and values into strings. The ninth argument is an optional function to format the sequence of arguments.
Definition at line 650 of file inspect.py.
References formatargvalues(), string.join(), and strseq().
def inspect.formatargvalues | ( | args, | |
varargs, | |||
varkw, | |||
locals, | |||
formatarg = str , |
|||
formatvarargs = lambda name: '*' + name , |
|||
formatvarkw = lambda name: '**' + name , |
|||
formatvalue = lambda value: '=' + repr(value) , |
|||
join = joinseq |
|||
) |
Format an argument spec from the 4 values returned by getargvalues. The first four arguments are (args, varargs, varkw, locals). The next four arguments are the corresponding optional formatting functions that are called to turn names and values into strings. The ninth argument is an optional function to format the sequence of arguments.
Definition at line 676 of file inspect.py.
References reconvert.convert(), string.join(), and strseq().
def inspect.getabsfile | ( | object) |
Return an absolute path to the source or compiled file for an object. The idea is for each object to have a unique origin, so this routine normalizes the result as much as possible.
Definition at line 339 of file inspect.py.
References getfile(), and getsourcefile().
def inspect.getargs | ( | co) |
Get information about the arguments accepted by a code object. Three things are returned: (args, varargs, varkw), where 'args' is a list of argument names (possibly containing nested lists), and 'varargs' and 'varkw' are the names of the * and ** arguments or None.
Definition at line 562 of file inspect.py.
References iscode().
def inspect.getargspec | ( | func) |
Get the names and default values of a function's arguments. A tuple of four things is returned: (args, varargs, varkw, defaults). 'args' is a list of the argument names (it may contain nested lists). 'varargs' and 'varkw' are the names of the * and ** arguments or None. 'defaults' is an n-tuple of the default values of the last n arguments.
Definition at line 611 of file inspect.py.
References getargs(), and isfunction().
def inspect.getargvalues | ( | frame) |
Get information about arguments passed into a particular frame. A tuple of four things is returned: (args, varargs, varkw, locals). 'args' is a list of the argument names (it may contain nested lists). 'varargs' and 'varkw' are the names of the * and ** arguments or None. 'locals' is the locals dictionary of the given frame.
Definition at line 622 of file inspect.py.
References getargs().
def inspect.getblock | ( | lines) |
Extract the block of code at the top of the given list of lines.
Definition at line 493 of file inspect.py.
def inspect.getclasstree | ( | classes, | |
unique = 0 |
|||
) |
Arrange the given list of classes into a hierarchy of nested lists. Where a nested list appears, it contains classes derived from the class whose entry immediately precedes the list. Each entry is a 2-tuple containing a class and a tuple of its base classes. If the 'unique' argument is true, exactly one entry appears in the returned structure for each class in the given list. Otherwise, classes using multiple inheritance and their descendants will appear multiple times.
Definition at line 533 of file inspect.py.
References reconvert.append, and walktree().
def inspect.getcomments | ( | object) |
Get lines of comments immediately preceding an object's source code.
Definition at line 420 of file inspect.py.
References string.expandtabs(), findsource(), indentsize(), ismodule(), string.join(), string.lstrip(), and string.strip().
def inspect.getdoc | ( | object) |
Get the documentation string for an object. All tabs are expanded to spaces. To clean up docstrings that are indented to line up with blocks of code, any whitespace than can be uniformly removed from the second line onwards is removed.
Definition at line 260 of file inspect.py.
References string.expandtabs(), string.join(), string.lstrip(), sre_parse.min, and string.split().
def inspect.getfile | ( | object) |
Work out which source or compiled file an object was defined in.
Definition at line 288 of file inspect.py.
References isclass(), iscode(), isframe(), isfunction(), ismethod(), ismodule(), and istraceback().
def inspect.getframeinfo | ( | frame, | |
context = 1 |
|||
) |
Get information about a frame or traceback object. A tuple of five things is returned: the filename, the line number of the current line, the function name, a list of lines of context from the source code, and the index of the current line within that list. The optional second argument specifies the number of lines of context to return, which are centered around the current line.
Definition at line 696 of file inspect.py.
References findsource(), getlineno(), getsourcefile(), isframe(), istraceback(), sre_parse.max, and sre_parse.min.
def inspect.getinnerframes | ( | tb, | |
context = 1 |
|||
) |
Get a list of records for a traceback's frame and all lower frames. Each record contains a frame object, filename, line number, function name, a list of lines of context, and index within the context.
Definition at line 753 of file inspect.py.
References getframeinfo().
def inspect.getlineno | ( | frame) |
Get the line number from a frame object, allowing for optimization.
Definition at line 727 of file inspect.py.
def inspect.getmembers | ( | object, | |
predicate = None |
|||
) |
Return all members of an object as (name, value) pairs sorted by name. Optionally, only return members that satisfy a given predicate.
Definition at line 155 of file inspect.py.
References sre_parse.dir.
def inspect.getmodule | ( | object) |
Return the module an object was defined in, or None if not found.
Definition at line 349 of file inspect.py.
References getabsfile(), isclass(), and ismodule().
def inspect.getmoduleinfo | ( | path) |
Get the module name, suffix, mode, and module type for a given file.
Definition at line 312 of file inspect.py.
def inspect.getmodulename | ( | path) |
Return the module name for a given file, or None.
Definition at line 322 of file inspect.py.
References getmoduleinfo().
def inspect.getmro | ( | cls) |
Definition at line 245 of file inspect.py.
References log_faction_ships.tuple.
def inspect.getouterframes | ( | frame, | |
context = 1 |
|||
) |
Get a list of records for a frame and all higher (calling) frames. Each record contains a frame object, filename, line number, function name, a list of lines of context, and index within the context.
Definition at line 742 of file inspect.py.
References getframeinfo().
def inspect.getsource | ( | object) |
Return the text of the source code for an object. The argument may be a module, class, method, function, traceback, frame, or code object. The source code is returned as a single string. An IOError is raised if the source code cannot be retrieved.
Definition at line 513 of file inspect.py.
References getsourcelines(), and string.join().
def inspect.getsourcefile | ( | object) |
Return the Python source file an object was defined in, if it exists.
Definition at line 327 of file inspect.py.
References getfile(), and string.lower().
def inspect.getsourcelines | ( | object) |
Return a list of source lines and starting line number for an object. The argument may be a module, class, method, function, traceback, frame, or code object. The source code is returned as a list of the lines corresponding to the object and the line number indicates where in the original source file the first line of code was found. An IOError is raised if the source code cannot be retrieved.
Definition at line 500 of file inspect.py.
References findsource(), getblock(), and ismodule().
def inspect.indentsize | ( | line) |
Return the indent size, in spaces, at the start of a line of text.
Definition at line 255 of file inspect.py.
References string.expandtabs(), and string.lstrip().
def inspect.isbuiltin | ( | object) |
Return true if the object is a built-in function or method. Built-in functions and methods provide these attributes: __doc__ documentation string __name__ original name of this function or method __self__ instance to which a method is bound, or None
Definition at line 139 of file inspect.py.
def inspect.isclass | ( | object) |
Return true if the object is a class. Class objects provide these attributes: __doc__ documentation string __module__ name of module in which this class was defined
Definition at line 41 of file inspect.py.
def inspect.iscode | ( | object) |
Return true if the object is a code object. Code objects provide these attributes: co_argcount number of arguments (not including * or ** args) co_code string of raw compiled bytecode co_consts tuple of constants used in the bytecode co_filename name of file in which this code object was created co_firstlineno number of first line in Python source code co_flags bitmap: 1=optimized | 2=newlocals | 4=*arg | 8=**arg co_lnotab encoded mapping of line numbers to bytecode indices co_name name with which this code object was defined co_names tuple of names of local variables co_nlocals number of local variables co_stacksize virtual machine stack space required co_varnames tuple of names of arguments and local variables
Definition at line 121 of file inspect.py.
def inspect.isframe | ( | object) |
Return true if the object is a frame object. Frame objects provide these attributes: f_back next outer frame object (this frame's caller) f_builtins built-in namespace seen by this frame f_code code object being executed in this frame f_exc_traceback traceback if raised in this frame, or None f_exc_type exception type if raised in this frame, or None f_exc_value exception value if raised in this frame, or None f_globals global namespace seen by this frame f_lasti index of last attempted instruction in bytecode f_lineno current line number in Python source code f_locals local namespace seen by this frame f_restricted 0 or 1 if frame is in restricted execution mode f_trace tracing function for this frame, or None
Definition at line 103 of file inspect.py.
def inspect.isfunction | ( | object) |
Return true if the object is a user-defined function. Function objects provide these attributes: __doc__ documentation string __name__ name with which this function was defined func_code code object containing compiled function bytecode func_defaults tuple of any default values for arguments func_doc (same as __doc__) func_globals global namespace in which this function was defined func_name (same as __name__)
Definition at line 80 of file inspect.py.
def inspect.ismethod | ( | object) |
Return true if the object is an instance method. Instance method objects provide these attributes: __doc__ documentation string __name__ name with which this method was defined im_class class object in which this method belongs im_func function object containing implementation of method im_self instance to which this method is bound, or None
Definition at line 49 of file inspect.py.
def inspect.ismethoddescriptor | ( | object) |
Return true if the object is a method descriptor. But not if ismethod() or isclass() or isfunction() are true. This is new in Python 2.2, and, for example, is true of int.__add__. An object passing this test has a __get__ attribute but not a __set__ attribute, but beyond that the set of attributes varies. __name__ is usually sensible, and __doc__ often is. Methods implemented via descriptors that also pass one of the other tests return false from the ismethoddescriptor() test, simply because the other tests promise more -- you can, e.g., count on having the im_func attribute (etc) when an object passes ismethod().
Definition at line 60 of file inspect.py.
References isclass(), isfunction(), and ismethod().
def inspect.ismodule | ( | object) |
Return true if the object is a module. Module objects provide these attributes: __doc__ documentation string __file__ filename (missing for built-in modules)
Definition at line 33 of file inspect.py.
def inspect.isroutine | ( | object) |
Return true if the object is any kind of function or method.
Definition at line 148 of file inspect.py.
References isbuiltin(), isfunction(), ismethod(), and ismethoddescriptor().
def inspect.istraceback | ( | object) |
Return true if the object is a traceback. Traceback objects provide these attributes: tb_frame frame object at this level tb_lasti index of last attempted instruction in bytecode tb_lineno current line number in Python source code tb_next next inner traceback object (called by this level)
Definition at line 93 of file inspect.py.
def inspect.joinseq | ( | seq) |
def inspect.stack | ( | context = 1 ) |
Return a list of records for the stack above the caller's frame.
Definition at line 773 of file inspect.py.
References currentframe(), and getouterframes().
def inspect.strseq | ( | object, | |
convert, | |||
join = joinseq |
|||
) |
Recursively walk a sequence, stringifying each element.
Definition at line 638 of file inspect.py.
References reconvert.convert(), formatargspec(), and dospath.join().
def inspect.trace | ( | context = 1 ) |
Return a list of records for the stack below the current exception.
Definition at line 777 of file inspect.py.
References getinnerframes().
def inspect.walktree | ( | classes, | |
children, | |||
parent | |||
) |
Recursive helper function for getclasstree().
Definition at line 523 of file inspect.py.
References filecmp.cmp().
string __author__ = 'Ka-Ping Yee <ping@lfw.org>' |
Definition at line 27 of file inspect.py.
string __date__ = '1 Jan 2001' |
Definition at line 28 of file inspect.py.
dictionary modulesbyfile = {} |
Definition at line 347 of file inspect.py.