Module t.p.reflect

Part of twisted.python View Source

Standardized versions of various cool and/or strange things that you can do with Python's reflection capabilities.
Line # Kind Name Docs
35 Class Settable A mixin class for syntactic sugar. Lets you assign attributes by
52 Class AccessorType Metaclass that generates properties automatically.
109 Class PropertyAccessor A mixin class for Python 2.2 that uses AccessorType.
146 Class Accessor Extending this class will give you explicit accessor methods; a
200 Class Summer Extend from this class to get the capability to maintain 'related
242 Class QueueMethod I represent a method that doesn't exist yet.
251 Function funcinfo this is more documentation for myself than useful code.
284 Function fullFuncName Undocumented
290 Function qual Return full import path of a class.
294 Function getcurrent Undocumented
302 Function getClass Return the class or type of object 'obj'.
313 Function isinst Undocumented
329 Function namedModule Return a module given its name.
339 Function namedObject Get a fully named module-global object.
356 Class InvalidName The given name is not a dot-separated list of Python objects.
362 Class ModuleNotFound The module associated with the given name doesn't exist and it can't be
369 Class ObjectNotFound The object associated with the given name doesn't exist and it can't be
409 Function namedAny Retrieve a Python object by its fully qualified name from the global Python
479 Function macro macro(name, source, **identifiers)
533 Function safe_repr safe_repr(anything) -> string
552 Function safe_str safe_str(anything) -> string
571 Function allYourBase allYourBase(classObj, baseClass=None) -> list of all base
581 Function accumulateBases Undocumented
588 Function prefixedMethodNames A list of method names with a given prefix in a given class.
596 Function addMethodNamesToDict addMethodNamesToDict(classObj, dict, prefix, baseClass=None) -> dict
618 Function prefixedMethods A list of methods with a given prefix on a given instance.
625 Function accumulateMethods accumulateMethods(instance, dict, prefix)
643 Function accumulateClassDict Accumulate all attributes of a given name in a class heirarchy into a single dictionary.
679 Function accumulateClassList Accumulate all attributes of a given name in a class heirarchy into a single list.
690 Function isSame Undocumented
693 Function isLike Undocumented
696 Function modgrep Undocumented
699 Function isOfType Undocumented
705 Function findInstances Undocumented
708 Function objgrep An insanely CPU-intensive process for finding stuff.
756 Function filenameToModuleName Convert a name in the filesystem to the name of the Python module it is.
782 Function fullyQualifiedName Return the fully qualified name of a module, class, method or function.
350 Class _NoModuleFound No module was found because none exists.
376 Function _importAndCheckStack Import the given name as a module, then walk the stack to determine whether
471 Function _reclass Undocumented
517 Function _determineClass Undocumented
523 Function _determineClassName Undocumented
def funcinfo(function): (source)
this is more documentation for myself than useful code.
def fullFuncName(func): (source)
Undocumented
def qual(clazz): (source)
Return full import path of a class.
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
def namedModule(name): (source)
Return a module given its name.
def namedObject(name): (source)
Get a fully named module-global object.
def _importAndCheckStack(importName): (source)
Import the given name as a module, then walk the stack to determine whether the failure was the module not existing, or some code in the module (for example a dependent import) failing. This can be helpful to determine whether any actual application code was run. For example, to distiguish administrative error (entering the wrong module name), from programmer error (writing buggy code in a module that fails to import).
RaisesExceptionif something bad happens. This can be any type of exception, since nobody knows what loading some arbitrary code might do.
_NoModuleFoundif no module was found.
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 _reclass(clazz): (source)
Undocumented
def macro(name, filename, source, **identifiers): (source)

macro(name, source, **identifiers)

This allows you to create macro-like behaviors in python. See twisted.python.hook for an example of its usage.
def _determineClass(x): (source)
Undocumented
def _determineClassName(x): (source)
Undocumented
def safe_repr(o): (source)

safe_repr(anything) -> string

Returns a string representation of an object, or a string containing a traceback, if that object's __repr__ raised an exception.
def safe_str(o): (source)

safe_str(anything) -> string

Returns a string representation of an object, or a string containing a traceback, if that object's __str__ raised an exception.
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.
def accumulateBases(classObj, l, baseClass=None): (source)
Undocumented
def prefixedMethodNames(classObj, prefix): (source)
A list of method names with a given prefix in a given class.
def addMethodNamesToDict(classObj, dict, prefix, baseClass=None): (source)

addMethodNamesToDict(classObj, dict, prefix, baseClass=None) -> dict 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}.
def prefixedMethods(obj, prefix=''): (source)
A list of methods with a given prefix on a given instance.
def accumulateMethods(obj, dict, prefix='', curClass=None): (source)
accumulateMethods(instance, dict, prefix) I recurse through the bases of instance.__class__, and add methods beginning with 'prefix' to 'dict', in the form of {'methodname':*instance*method_object}.
def accumulateClassDict(classObj, attr, adict, baseClass=None): (source)

Accumulate all attributes of a given name in a class heirarchy 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.
def filenameToModuleName(fn): (source)

Convert a name in the filesystem to the name of the Python module it is.

This is agressive about getting a module name back from a file; it will always return a string. Agressive 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.
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. )
API Documentation for Twisted, generated by pydoctor at 2008-10-26 16:12:37.