Package twisted :: Package python :: Module reflect

[show private | hide private]
[frames | no frames]

## Module twisted.python.reflect

Standardized versions of various cool and/or strange things that you can do with Python's reflection capabilities.

Classes
`Accessor` | Extending this class will give you explicit accessor methods; a method called `set_foo`, for example, is the same as an if statement in `__setattr__` looking for `'foo'`.
`AccessorType` | Metaclass that generates properties automatically.
`OriginalAccessor` | Extending this class will give you explicit accessor methods; a method called `set_foo`, for example, is the same as an if statement in `__setattr__` looking for `'foo'`.
`Promise` | I represent an object not yet available.
`QueueMethod` | I represent a method that doesn't exist yet.
`RegexType` |
`Settable` | A mixin class for syntactic sugar.
`Summer` | Extend from this class to get the capability to maintain 'related sums'.

Function Summary
| `accumulateBases(classObj, l, baseClass)`
| ``accumulateClassDict`(classObj, attr, adict, baseClass)` Accumulate all attributes of a given name in a class heirarchy into a single dictionary.
| ``accumulateClassList`(classObj, attr, listObj, baseClass)` Accumulate all attributes of a given name in a class heirarchy into a single list.
| ``accumulateMethods`(obj, dict, prefix, curClass)` 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}.
| ``addMethodNamesToDict`(classObj, dict, prefix, baseClass)` 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.
| ``allYourBase`(classObj, baseClass)` 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.
| ``filenameToModuleName`(fn)` Convert a name in the filesystem to the name of the Python module it is.
| `findInstances(start, t)`
| `fullFuncName(func)`
| ``funcinfo`(function)` this is more documentation for myself than useful code.
| `getcurrent(clazz)`
| `isinst(inst, clazz)`
| `isLike(a, b)`
| `isOfType(start, goal)`
| `isSame(a, b)`
| ``macro`(name, filename, source, **identifiers)` macro(name, source, **identifiers)
| `modgrep(goal)`
| ``namedAny`(name)` Get a fully named package, module, module-global object, or attribute.
| ``namedClass`(name)` Get a fully named module-global object.
| ``namedModule`(name)` Return a module given its name.
| ``namedObject`(name)` Get a fully named module-global object.
| ``objgrep`(start, goal, eq, path, paths, seen, showUnknowns)` An insanely CPU-intensive process for finding stuff.
| ``prefixedMethodNames`(classObj, prefix)` A list of method names with a given prefix in a given class.
| ``prefixedMethods`(obj, prefix)` A list of methods with a given prefix on a given instance.
| `qual(clazz)`
| ``safe_repr`(obj)` safe_repr(anything) -> string Returns a string representation of an object (or a traceback, if that object's __repr__ raised an exception)
| `_reclass(clazz)`
| `_startswith(s, sub)`

Variable Summary
`int` | `False`
`int` | `IS`
`int` | `ISNT`
`_Feature` | `nested_scopes`
`AccessorType` | `PropertyAccessor`
`instance method` | `repr`
`tuple` | `StringTypes`
`int` | `True`
`int` | `WAS`
`TextRepr` | `_textRepr`

Function Details

### accumulateClassDict(classObj, attr, adict, baseClass=None)

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}

### accumulateClassList(classObj, attr, listObj, baseClass=None)

Accumulate all attributes of a given name in a class heirarchy into a single list.

Assuming all class attributes of this name are lists.

### accumulateMethods(obj, dict, prefix='', curClass=None)

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}.

### addMethodNamesToDict(classObj, dict, prefix, baseClass=None)

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}.

### allYourBase(classObj, baseClass=None)

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.

### filenameToModuleName(fn)

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.

### funcinfo(function)

this is more documentation for myself than useful code.

### macro(name, filename, source, **identifiers)

macro(name, source, **identifiers)

This allows you to create macro-like behaviors in python. See twisted.python.hook for an example of its usage.

### namedAny(name)

Get a fully named package, module, module-global object, or attribute.

### namedClass(name)

Get a fully named module-global object.

### namedModule(name)

Return a module given its name.

### namedObject(name)

Get a fully named module-global object.

### objgrep(start, goal, eq=<function isLike at 0x81d2a2c>, path='', paths=None, seen=None, showUnknowns=0)

An insanely CPU-intensive process for finding stuff.

### prefixedMethodNames(classObj, prefix)

A list of method names with a given prefix in a given class.

### prefixedMethods(obj, prefix)

A list of methods with a given prefix on a given instance.

### safe_repr(obj)

safe_repr(anything) -> string Returns a string representation of an object (or a traceback, if that object's __repr__ raised an exception)

Variable Details

### False

  Type:
    `int`
  Value:

        0

### IS

  Type:
    `int`
  Value:

        2

### ISNT

  Type:
    `int`
  Value:

        0

### nested_scopes

  Type:
    `_Feature`
  Value:

        _Feature((2, 1, 0, 'beta', 1), (2, 2, 0, 'alpha', 0), 16)

### PropertyAccessor

  Type:
    `AccessorType`
  Value:

        <class 'twisted.python.reflect.PropertyAccessor'>

### repr

`repr` = `pydoc.TextRepr.repr`

  Type:
    `instance method`
  Value:

        <bound method TextRepr.repr of <pydoc.TextRepr instance at 0x82743cc>>

### StringTypes

  Type:
    `tuple`
  Value:

        (<type 'str'>, <type 'unicode'>)

### True

  Type:
    `int`
  Value:

        1

### WAS

  Type:
    `int`
  Value:

        1

### _textRepr

  Type:
    `TextRepr`
  Value:

        <pydoc.TextRepr instance at 0x82743cc>

Generated by Epydoc 1.1 on Thu May 8 13:18:57 2003 | http://epydoc.sf.net