gavo.grammars.kvgrammar module

A grammar parsing key-value pairs from plain text files.

class gavo.grammars.kvgrammar.KVIterator(grammar, sourceToken, **kwargs)[source]

Bases: FileRowIterator

is an iterator over a file containing key, value pairs.

Depending on the parent grammar, it returns the whole k,v record as one row or one pair per row.

getLocator()[source]
phase = '(nothing read yet)'
class gavo.grammars.kvgrammar.KeyValueGrammar(parent, **kwargs)[source]

Bases: Grammar

A grammar to parse key-value pairs from files.

The default assumes one pair per line, with # comments and = as separating character.

yieldPairs makes the grammar return an empty docdict and {“key”:, “value”:} rowdicts.

Whitespace around key and value is ignored.

attrSeq = [<gavo.grammars.common.REAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>, <gavo.base.parsecontext.IdAttribute object>, <gavo.base.complexattrs.StructAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>, <gavo.base.complexattrs.StructAttribute object>, <gavo.base.parsecontext.OriginalAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>, <gavo.base.complexattrs.PropertyAttribute object>, <gavo.rscdef.common.RDAttribute object>, <gavo.base.complexattrs.StructListAttribute object>, <gavo.base.complexattrs.StructAttribute object>, <gavo.base.attrdef.BooleanAttribute object>]
clearProperty(name)
completedCallbacks = []
getFullId()
getProperty(name, default=<Undefined>)
hasProperty(name)
managedAttrs = {'commentPattern': <gavo.grammars.common.REAttribute object>, 'enc': <gavo.base.attrdef.UnicodeAttribute object>, 'id': <gavo.base.parsecontext.IdAttribute object>, 'ignoreOn': <gavo.base.complexattrs.StructAttribute object>, 'kvSeparators': <gavo.base.attrdef.UnicodeAttribute object>, 'mapKeys': <gavo.base.complexattrs.StructAttribute object>, 'original': <gavo.base.parsecontext.OriginalAttribute object>, 'pairSeparators': <gavo.base.attrdef.UnicodeAttribute object>, 'properties': <gavo.base.complexattrs.PropertyAttribute object>, 'property': <gavo.base.complexattrs.PropertyAttribute object>, 'rd': <gavo.rscdef.common.RDAttribute object>, 'rowfilter': <gavo.base.complexattrs.StructListAttribute object>, 'rowfilters': <gavo.base.complexattrs.StructListAttribute object>, 'sourceFields': <gavo.base.complexattrs.StructAttribute object>, 'yieldPairs': <gavo.base.attrdef.BooleanAttribute object>}
name_ = 'keyValueGrammar'
onElementComplete()[source]
property rd
rowIterator

alias of KVIterator

setProperty(name, value)