Package gavo :: Package base :: Module structure :: Class StructureBase
[frames] | no frames]

Class StructureBase

source code

object --+
         |
        StructureBase
Known Subclasses:

is a base class for all structures.

You must arrange for calling its constructor from classes inheriting this.

The constructor receives a parent (another structure, or None) and keyword arguments containing values for actual attributes (which will be set without any intervening consultation of the AttributeDef).

The attribute definitions talking about structures let you set parent to None when constructing default values; they will then insert the actual parent.

Nested Classes
  __metaclass__
is a metaclass for the representation of structured data.
  name_
a sentinel for all kinds of undefined values.
Instance Methods
 
__init__(self, parent, **kwargs)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
setPosition(self, fName, lineNumber)
should be called by parsers to what file at what line the serialisation came from.
source code
 
getSourcePosition(self)
returns a string representation of where the struct was parsed from.
source code
 
getAttributes(self, attDefsFrom=None)
returns a dict of the current attributes, suitable for making a shallow copy of self.
source code
 
getCopyableAttributes(self, ignoreKeys=set([]), ctx=None)
returns a dictionary mapping attribute names to copyable children.
source code
 
change(self, **kwargs)
returns a copy of self with all attributes in kwargs overridden with the passed values.
source code
 
copy(self, parent, ctx=None)
returns a deep copy of self, reparented to parent.
source code
 
adopt(self, struct) source code
 
iterChildren(self)
iterates over structure children of self.
source code
 
breakCircles(self)
removes the parent attributes from all child structures recusively.
source code
 
__providedBy__(...)
Object Specification Descriptor
source code
 
__provides__(...)
Special descriptor for class __provides__

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Methods
 
fromStructure(cls, newParent, oldStructure) source code
Class Variables
  __implemented__ = <implementedBy gavo.base.structure.Structure...
  attrSeq = [<gavo.base.parsecontext.IdAttribute object>]
  completedCallbacks = []
  managedAttrs = {'id': <gavo.base.parsecontext.IdAttribute obje...
Properties

Inherited from object: __class__

Method Details

__init__(self, parent, **kwargs)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

getAttributes(self, attDefsFrom=None)

source code 

returns a dict of the current attributes, suitable for making a shallow copy of self.

Struct attributes will not be reparented, so there are limits to what you can do with such shallow copies.

getCopyableAttributes(self, ignoreKeys=set([]), ctx=None)

source code 

returns a dictionary mapping attribute names to copyable children.

ignoreKeys can be a set or dict of additional attribute names to ignore. The children are orphan deep copies.

copy(self, parent, ctx=None)

source code 

returns a deep copy of self, reparented to parent.

This is a shallow wrapper around change, present for backward compatibility.

iterChildren(self)

source code 

iterates over structure children of self.

To make this work, attributes containing structs must define iterChildren methods (and the others must not).

breakCircles(self)

source code 

removes the parent attributes from all child structures recusively.

The struct will probably be broken after this, but this is sometimes necessary to help the python garbage collector.

In case you're asking: parent cannot be a weak reference with the current parse architecture, as it usually is the only reference to the embedding object. Yes, we should probably change that.

__provides__(...)

 

Special descriptor for class __provides__

The descriptor caches the implementedBy info, so that we can get declarations for objects without instance-specific interfaces a bit quicker.


Class Variable Details

__implemented__

Value:
<implementedBy gavo.base.structure.StructureBase>

managedAttrs

Value:
{'id': <gavo.base.parsecontext.IdAttribute object>}