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

Class ParseContext

source code

object --+
         |
        ParseContext
Known Subclasses:

is a scratchpad for any kind of data parsers want to pass to feed methods.

These objects are available to the feed methods as their first objects.

If restricted is True, embedded code must raise an error.

You should set an eventSource using the setter provided. This is the iterparse instance the events are coming from (or something else that has a pos attribute returning the current position).

You can register exit functions to do some "global" cleanup. Parsers should call runExitFuncs right before they return the results; this arranges for these functions to be called. The signature of an exit function is exitfunc(rootStruct, parseContext) -> whatever.

Instance Methods
 
__init__(self, restricted=False, forRD=None)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
setEventSource(self, evSource) source code
 
addExitFunc(self, callable) source code
 
replaying(*args, **kwds)
is called by active tags to indicate they're replaying events.
source code
 
setPositionOn(self, struct)
calls a struct's setPosition method to tell it where it came from.
source code
 
getQualifiedId(self, id)
returns an id including the current RD's id, if known, otherwise id itself.
source code
 
registerId(self, elId, value, silentOverwrite=False)
enters a value in the id map.
source code
 
getById(self, id, forceType=None)
returns the object last registred for id.
source code
 
resolveId(self, id, instance=None, forceType=None)
returns the object referred to by the complex id.
source code
 
runExitFuncs(self, root) source code

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

Properties
  pos
returns a token stringifying into a position guess.

Inherited from object: __class__

Method Details

__init__(self, restricted=False, forRD=None)
(Constructor)

source code 

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

Overrides: object.__init__
(inherited documentation)

replaying(*args, **kwds)

source code 

is called by active tags to indicate they're replaying events.

The main effect right now is to suppress diagnostics for overwritten ids. But let's see what else we might want to use it for.

The API to see if we're replaying: replayLevel>0.

Decorators:
  • @contextlib.contextmanager

registerId(self, elId, value, silentOverwrite=False)

source code 

enters a value in the id map.

We allow overriding in id. That should not happen while parsing and XML document because of their uniqueness requirement, but might come in handy for programmatic manipulations.

We'll still emit an Info in that case (and may need to find a way to suppress it).

getById(self, id, forceType=None)

source code 

returns the object last registred for id.

You probably want to use resolveId; getById does no namePath or resource descriptor resolution.

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

source code 

returns the object referred to by the complex id.

See the resolveId function.


Property Details

pos

returns a token stringifying into a position guess.

Get Method:
unreachable.pos(self) - returns a token stringifying into a position guess.