Package gavo :: Package rscdef :: Module builtingrammars
[frames] | no frames]

Source Code for Module gavo.rscdef.builtingrammars

 1  """ 
 2  The built-in grammars of DaCHS. 
 3   
 4  Amend this GRAMMAR_REGISTRY if you write a new grammar distributed with DaCHS. 
 5   
 6  We had self-registration of grammars at one point, but having to 
 7  import all grammars seemed quite a bit of waste, so how there's this 
 8  manual registry. 
 9  """ 
10   
11  #c Copyright 2008-2019, the GAVO project 
12  #c 
13  #c This program is free software, covered by the GNU GPL.  See the 
14  #c COPYING file in the source distribution. 
15   
16   
17  from gavo import base 
18  from gavo import utils 
19   
20  GRAMMAR_REGISTRY = { 
21  # elementName -> (module (without gavo.), class name) 
22          "binaryGrammar": ("grammars.binarygrammar", "BinaryGrammar"), 
23          "cdfHeaderGrammar": ("grammars.cdfgrammar", "CDFHeaderGrammar"), 
24          "columnGrammar": ("grammars.columngrammar", "ColumnGrammar"), 
25          "contextGrammar": ("svcs.inputdef", "ContextGrammar"), 
26          "customGrammar": ("grammars.customgrammar", "CustomGrammar"), 
27          "dictlistGrammar": ("grammars.dictlistgrammar", "DictlistGrammar"), 
28          "directGrammar": ("grammars.directgrammar", "DirectGrammar"), 
29          "embeddedGrammar": ("grammars.embeddedgrammar", "EmbeddedGrammar"), 
30          "fitsProdGrammar": ("grammars.fitsprodgrammar", "FITSProdGrammar"), 
31          "freeREGrammar": ("grammars.freeregrammar", "FreeREGrammar"), 
32          "keyValueGrammar": ("grammars.kvgrammar", "KeyValueGrammar"), 
33          "mySQLDumpGrammar": ("grammars.mysqldumpgrammar", "MySQLDumpGrammar"), 
34          "nullGrammar": ("grammars.common", "NullGrammar"), 
35          "transparentGrammar": ("grammars.common", "TransparentGrammar"), 
36          "odbcGrammar": ("grammars.odbcgrammar", "ODBCGrammar"), 
37          "pdsGrammar": ("grammars.pdsgrammar", "PDSGrammar"), 
38          "reGrammar": ("grammars.regrammar", "REGrammar"), 
39          "rowsetGrammar": ("grammars.rowsetgrammar", "RowsetGrammar"), 
40          "voTableGrammar": ("grammars.votablegrammar", "VOTableGrammar"), 
41          "csvGrammar": ("grammars.csvgrammar", "CSVGrammar"), 
42          "fitsTableGrammar": ("grammars.fitstablegrammar", "FITSTableGrammar"), 
43  } 
44 45 @utils.memoized 46 -def getGrammar(grammarName):
47 if grammarName not in GRAMMAR_REGISTRY: 48 raise base.NotFoundError(grammarName, "grammar", "defined grammars") 49 grammarClass = utils.loadInternalObject(*GRAMMAR_REGISTRY[grammarName]) 50 if grammarClass.name_!=grammarName: 51 raise base.ReportableError("Internal Error: Grammar %s is registred" 52 " under the wrong name."%grammarName, 53 hint="This is probably a typo in grammars.__init__; it needs" 54 " to be fixed there") 55 return grammarClass
56