Package gavo :: Package base :: Module parsecontext
[frames] | no frames]

Module parsecontext

source code

ParseContexts for parsing into structures.

A Context is a scratchpad for struct parsing. It always provides an idmap, but you're free to insert additional attributes.

Based on this, we provide some attribute definitions.

Classes
  IdAttribute
is an attribute that registers its parent in the context's id map in addition to setting its id attribute.
  OriginalAttribute
is an attribute that resolves an item copies over the managed attributes from the referenced item.
  ReferenceAttribute
An attribute keeping a reference to some other structure
  ReferenceListAttribute
A list of references.
  ParseContext
is a scratchpad for any kind of data parsers want to pass to feed methods.
Functions
 
assertType(id, ob, forceType)
raises a StructureError if forceType is not None and ob is not of type forceType, returns ob otherwise.
source code
 
resolveCrossId(id, forceType=None, **kwargs)
resolves ``id``, where id is of the form ``rdId#id``.
source code
 
resolveNameBased(container, id, forceType=None)
Tries to find a thing with name id within container.
source code
 
resolveComplexId(ctx, id, forceType=None)
resolves a dotted id.
source code
 
resolveId(ctx, id, instance=None, forceType=None)
tries to resolve id in context.
source code
 
getTableDefForTable(connection, tableName)
returns a TableDef object for a SQL table name.
source code
Variables
  __package__ = 'gavo.base'
Function Details

resolveCrossId(id, forceType=None, **kwargs)

source code 

resolves ``id``, where id is of the form ``rdId#id``.

``forceType``, if non-None must be a DaCHS struct type (e.g., rscdef.Table); a ``StructureError`` will be raised if the reference resolves to something else than an instance of that type.

``id`` can also be a simple rd id.

``kwargs`` lets you pass additional keyword arguments to the ``getRD`` calls that may be triggered by this.

resolveNameBased(container, id, forceType=None)

source code 

Tries to find a thing with name id within container.

If container defines a method getElementForName, it will be called; it must either return some element with this name or raise a NotFoundError.

If no such method exists, the function iterates over container until it finds an element with el.name==id. If no such element exists, it again raises a NotFoundError.

The function raises a NotFoundError when no such thing exists.

resolveComplexId(ctx, id, forceType=None)

source code 

resolves a dotted id.

See resolveId.

resolveId(ctx, id, instance=None, forceType=None)

source code 

tries to resolve id in context.

ctx is some object having a getById method; this could be an RD or a parse context.

The rules for id are as follows:

(#) if id has a # in it, split it and take the first part to be an RD id, the second and id built according to the rest of this spec.

(#) if id has a dot in it, split at the first dot to get a pair of id and name. Iterate over the element with id, and look for something with a "name" attribute valued name. If this fails, raise a NotFoundError.

(#) if instance is not None and has a resolveName method or has a parent, and that parent has a resolveName method, pass id to it. If it does not raise a NotFoundError, return the result. This is for parents with a rscdef.NamePathAttribute.

(#) ask the ParseContext ctx's getById method to resolve id, not catching the NotFoundError this will raise if the id is not known.

getTableDefForTable(connection, tableName)

source code 

returns a TableDef object for a SQL table name.

connection needs to be TableConnection of higher.

This really has little to do with resolving identifiers, but this module already has getRDs and similar, so it seemed the least unnatural place.