gavo.grammars.uniongrammar module¶
A grammar switching between subordinate grammars by file name patterns.
- class gavo.grammars.uniongrammar.HandlesDeclaration(parent, **kwargs)[source]¶
Bases:
Structure
A declaration of what grammar to use within a UnionGrammar.
Each handler has a (full, python) regular expression defining what file names the grammar is responsible in the filePattern attribute; note that the pattern is matched against the full file name using search so you can match path parts, but you must take care not to overmatch. The other child is a normal DaCHS grammar.
- attrSeq = [<gavo.base.complexattrs.MultiStructAttribute object>, <gavo.base.parsecontext.IdAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>]¶
- completedCallbacks = []¶
- managedAttrs = {'binaryGrammar': <gavo.base.complexattrs.MultiStructAttribute object>, 'cdfHeaderGrammar': <gavo.base.complexattrs.MultiStructAttribute object>, 'columnGrammar': <gavo.base.complexattrs.MultiStructAttribute object>, 'contextGrammar': <gavo.base.complexattrs.MultiStructAttribute object>, 'csvGrammar': <gavo.base.complexattrs.MultiStructAttribute object>, 'customGrammar': <gavo.base.complexattrs.MultiStructAttribute object>, 'dictlistGrammar': <gavo.base.complexattrs.MultiStructAttribute object>, 'directGrammar': <gavo.base.complexattrs.MultiStructAttribute object>, 'embeddedGrammar': <gavo.base.complexattrs.MultiStructAttribute object>, 'fitsProdGrammar': <gavo.base.complexattrs.MultiStructAttribute object>, 'fitsTableGrammar': <gavo.base.complexattrs.MultiStructAttribute object>, 'freeREGrammar': <gavo.base.complexattrs.MultiStructAttribute object>, 'grammar': <gavo.base.complexattrs.MultiStructAttribute object>, 'hdf5Grammar': <gavo.base.complexattrs.MultiStructAttribute object>, 'id': <gavo.base.parsecontext.IdAttribute object>, 'keyValueGrammar': <gavo.base.complexattrs.MultiStructAttribute object>, 'mySQLDumpGrammar': <gavo.base.complexattrs.MultiStructAttribute object>, 'nullGrammar': <gavo.base.complexattrs.MultiStructAttribute object>, 'odbcGrammar': <gavo.base.complexattrs.MultiStructAttribute object>, 'pattern': <gavo.base.attrdef.UnicodeAttribute object>, 'pdsGrammar': <gavo.base.complexattrs.MultiStructAttribute object>, 'reGrammar': <gavo.base.complexattrs.MultiStructAttribute object>, 'rowsetGrammar': <gavo.base.complexattrs.MultiStructAttribute object>, 'transparentGrammar': <gavo.base.complexattrs.MultiStructAttribute object>, 'unionGrammar': <gavo.base.complexattrs.MultiStructAttribute object>, 'voTableGrammar': <gavo.base.complexattrs.MultiStructAttribute object>, 'xmlGrammar': <gavo.base.complexattrs.MultiStructAttribute object>}¶
- name_ = 'handles'¶
- class gavo.grammars.uniongrammar.UnionGrammar(parent, **kwargs)[source]¶
Bases:
Grammar
A grammar using one of a sequence of grammars to parse its sources.
(since version 2.7.2)
Use this if you have differing input formats eventually processible by the same row maker (of course, you can make the row maker flexible enough to cope with different grammar outputs). To do that, use two or more handles definitions, each giving a regular expression against the full file name (but matched with re.search) and a grammar to use for such files.
Handles definitions will be tried in sequence; you can hence have special cases early and catch-alls later.
The basic idea is that you write something like:
<unionGrammar> <handles pattern=".*\.txt$"> <reGrammar...> </handles> <handles pattern=".*\.csv$"> <csvGrammar...> </handles> </unionGrammar>
- attrSeq = [<gavo.base.attrdef.UnicodeAttribute object>, <gavo.base.complexattrs.StructListAttribute object>, <gavo.base.parsecontext.IdAttribute object>, <gavo.base.complexattrs.StructAttribute object>, <gavo.base.parsecontext.OriginalAttribute object>, <gavo.base.complexattrs.PropertyAttribute object>, <gavo.rscdef.common.RDAttribute object>, <gavo.base.complexattrs.StructListAttribute object>, <gavo.base.complexattrs.StructAttribute object>]¶
- clearProperty(name)¶
- completedCallbacks = []¶
- getFullId()¶
- getProperty(name, default=<Undefined>)¶
- hasProperty(name)¶
- managedAttrs = {'enc': <gavo.base.attrdef.UnicodeAttribute object>, 'handles': <gavo.base.complexattrs.StructListAttribute object>, 'id': <gavo.base.parsecontext.IdAttribute object>, 'ignoreOn': <gavo.base.complexattrs.StructAttribute object>, 'original': <gavo.base.parsecontext.OriginalAttribute 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>}¶
- name_ = 'unionGrammar'¶
- property rd¶
- setProperty(name, value)¶