t.p.reflect : module documentation

Part of twisted.python View Source

Standardized versions of various cool and/or strange things that you can do with Python's reflection capabilities.
Function fullyQualifiedName Return the fully qualified name of a module, class, method or function. Classes and functions need to be module level ones to be correctly qualified.
Function prefixedMethods Given an object obj, returns a list of method objects that match the string prefix.
Function accumulateMethods Given an object obj, add all methods that begin with prefix.
Function prefixedMethodNames Given a class object classObj, returns a list of method names that match the string prefix.
Function addMethodNamesToDict This goes through classObj (and its bases) and puts method names starting with 'prefix' in 'dict' with a value of 1. if baseClass isn't None, methods will only be added if classObj is-a baseClass
Function namedModule Return a module given its name.
Function namedObject Get a fully named module-global object.
Class InvalidName The given name is not a dot-separated list of Python objects.
Class ModuleNotFound The module associated with the given name doesn't exist and it can't be imported.
Class ObjectNotFound The object associated with the given name doesn't exist and it can't be imported.
Function namedAny No summary
Function filenameToModuleName Convert a name in the filesystem to the name of the Python module it is.
Function qual Return full import path of a class.
Function safe_str Returns a string representation of an object, or a string containing a traceback, if that object's __str__ raised an exception.
Function safe_repr Returns a string representation of an object, or a string containing a traceback, if that object's __repr__ raised an exception.
Class Settable No summary
Class AccessorType Metaclass that generates properties automatically.
Class PropertyAccessor A mixin class for Python 2.2 that uses AccessorType.
Class Accessor No summary
Class Summer

Extend from this class to get the capability to maintain 'related sums'. Have a tuple in your class like the following:


Class QueueMethod I represent a method that doesn't exist yet.
Function funcinfo this is more documentation for myself than useful code.
Function fullFuncName Undocumented
Function getcurrent Undocumented
Function getClass Return the class or type of object 'obj'. Returns sensible result for oldstyle and newstyle instances and types.
Function isinst Undocumented
Function allYourBase allYourBase(classObj, baseClass=None) -> list of all base classes that are subclasses of baseClass, unless it is None, in which case all bases will be added.
Function accumulateBases Undocumented
Function accumulateClassDict Accumulate all attributes of a given name in a class hierarchy into a single dictionary.
Function accumulateClassList Accumulate all attributes of a given name in a class heirarchy into a single list.
Function isSame Undocumented
Function isLike Undocumented
Function modgrep Undocumented
Function isOfType Undocumented
Function findInstances Undocumented
Function objgrep An insanely CPU-intensive process for finding stuff.
Function _accumulateBases Undocumented
def fullyQualifiedName(obj): (source)
Return the fully qualified name of a module, class, method or function. Classes and functions need to be module level ones to be correctly qualified.
Returns (type: str.)
def prefixedMethods(obj, prefix=''): (source)
Given an object obj, returns a list of method objects that match the string prefix.
ParametersobjAn arbitrary object from which to collect methods.
prefixA native string giving a prefix. Each method of obj with a name which begins with this prefix will be returned. (type: str)
ReturnsA list of the matching method objects. (type: list)
def accumulateMethods(obj, dict, prefix='', curClass=None): (source)
Given an object obj, add all methods that begin with prefix.
ParametersobjAn arbitrary object to collect methods from.
dictA dict which will be updated with the results of the accumulation. Items are added to this dictionary, with method names as keys and corresponding instance method objects as values. (type: dict)
prefixA native string giving a prefix. Each method of obj with a name which begins with this prefix will be returned. (type: str)
curClassThe class in the inheritance hierarchy at which to start collecting methods. Collection proceeds up. To collect all methods from obj, do not pass a value for this parameter.
ReturnsNone
def prefixedMethodNames(classObj, prefix): (source)
Given a class object classObj, returns a list of method names that match the string prefix.
ParametersclassObjA class object from which to collect method names.
prefixA native string giving a prefix. Each method with a name which begins with this prefix will be returned. (type: str)
ReturnsA list of the names of matching methods of classObj (and base classes of classObj). (type: list of str)
def addMethodNamesToDict(classObj, dict, prefix, baseClass=None): (source)
This goes through classObj (and its bases) and puts method names starting with 'prefix' in 'dict' with a value of 1. if baseClass isn't None, methods will only be added if classObj is-a baseClass

If the class in question has the methods 'prefix_methodname' and 'prefix_methodname2', the resulting dict should look something like: {"methodname": 1, "methodname2": 1}.

ParametersclassObjA class object from which to collect method names.
dictA dict which will be updated with the results of the accumulation. Items are added to this dictionary, with method names as keys and 1 as values. (type: dict)
prefixA native string giving a prefix. Each method of classObj (and base classes of classObj) with a name which begins with this prefix will be returned. (type: str)
baseClassA class object at which to stop searching upwards for new methods. To collect all method names, do not pass a value for this parameter.
ReturnsNone
def namedModule(name): (source)
Return a module given its name.
def namedObject(name): (source)
Get a fully named module-global object.
def namedAny(name): (source)
Retrieve a Python object by its fully qualified name from the global Python module namespace. The first part of the name, that describes a module, will be discovered and imported. Each subsequent part of the name is treated as the name of an attribute of the object specified by all of the name which came before it. For example, the fully-qualified name of this object is 'twisted.python.reflect.namedAny'.
ParametersnameThe name of the object to return. (type: str)
Returnsthe Python object identified by 'name'.
RaisesInvalidNameIf the name is an empty string, starts or ends with a '.', or is otherwise syntactically incorrect.
ModuleNotFoundIf the name is syntactically correct but the module it specifies cannot be imported because it does not appear to exist.
ObjectNotFoundIf the name is syntactically correct, includes at least one '.', but the module it specifies cannot be imported because it does not appear to exist.
AttributeErrorIf an attribute of an object along the way cannot be accessed, or a module along the way is not found.
def filenameToModuleName(fn): (source)
Convert a name in the filesystem to the name of the Python module it is.

This is aggressive about getting a module name back from a file; it will always return a string. Aggressive means 'sometimes wrong'; it won't look at the Python path or try to do any error checking: don't use this method unless you already know that the filename you're talking about is a Python module.

ParametersfnA filesystem path to a module or package; bytes on Python 2, bytes or unicode on Python 3.
ReturnsA hopefully importable module name. (type: str)
def qual(clazz): (source)
Return full import path of a class.
def safe_str(o): (source)
Returns a string representation of an object, or a string containing a traceback, if that object's __str__ raised an exception.
ParametersoAny object.
Returns (type: str)
def safe_repr(o): (source)
Returns a string representation of an object, or a string containing a traceback, if that object's __repr__ raised an exception.
ParametersoAny object.
Returns (type: str)
def funcinfo(function): (source)
this is more documentation for myself than useful code.
def fullFuncName(func): (source)
Undocumented
def getcurrent(clazz): (source)
Undocumented
def getClass(obj): (source)
Return the class or type of object 'obj'. Returns sensible result for oldstyle and newstyle instances and types.
def isinst(inst, clazz): (source)
Undocumented
@deprecated(Version('Twisted', 11, 0, 0), 'inspect.getmro')
def allYourBase(classObj, baseClass=None): (source)
allYourBase(classObj, baseClass=None) -> list of all base classes that are subclasses of baseClass, unless it is None, in which case all bases will be added.
@deprecated(Version('Twisted', 11, 0, 0), 'inspect.getmro')
def accumulateBases(classObj, l, baseClass=None): (source)
Undocumented
def _accumulateBases(classObj, l, baseClass=None): (source)
Undocumented
def accumulateClassDict(classObj, attr, adict, baseClass=None): (source)
Accumulate all attributes of a given name in a class hierarchy into a single dictionary.

Assuming all class attributes of this name are dictionaries. If any of the dictionaries being accumulated have the same key, the one highest in the class heirarchy wins. (XXX: If "higest" means "closest to the starting class".)

Ex:

 class Soy:
   properties = {"taste": "bland"}

 class Plant:
   properties = {"colour": "green"}

 class Seaweed(Plant):
   pass

 class Lunch(Soy, Seaweed):
   properties = {"vegan": 1 }

 dct = {}

 accumulateClassDict(Lunch, "properties", dct)

 print dct

{"taste": "bland", "colour": "green", "vegan": 1}

def accumulateClassList(classObj, attr, listObj, baseClass=None): (source)
Accumulate all attributes of a given name in a class heirarchy into a single list.

Assuming all class attributes of this name are lists.

def isSame(a, b): (source)
Undocumented
def isLike(a, b): (source)
Undocumented
def modgrep(goal): (source)
Undocumented
def isOfType(start, goal): (source)
Undocumented
def findInstances(start, t): (source)
Undocumented
def objgrep(start, goal, eq=isLike, path='', paths=None, seen=None, showUnknowns=0, maxDepth=None): (source)
An insanely CPU-intensive process for finding stuff.
API Documentation for Twisted, generated by pydoctor at 2013-04-03 11:20:05.