[GRASS-SVN] r72753 - sandbox/wenzeslaus/g.citation

svn_grass at osgeo.org svn_grass at osgeo.org
Thu May 31 19:28:56 PDT 2018


Author: wenzeslaus
Date: 2018-05-31 19:28:56 -0700 (Thu, 31 May 2018)
New Revision: 72753

Modified:
   sandbox/wenzeslaus/g.citation/g.citation.py
Log:
g.citation: use dict to pick function based on string

Modified: sandbox/wenzeslaus/g.citation/g.citation.py
===================================================================
--- sandbox/wenzeslaus/g.citation/g.citation.py	2018-05-31 21:02:20 UTC (rev 72752)
+++ sandbox/wenzeslaus/g.citation/g.citation.py	2018-06-01 02:28:56 UTC (rev 72753)
@@ -231,15 +231,20 @@
     print(authors_text)
 
 
+# private dict for format name to function call
+# use print_citation()
+_FORMAT_FUNCTION = {
+    'bibtex': print_bibtex,
+    'plain': print_plain,
+    'dict': pprint,
+}
+
+
 def print_citation(citation, format):
     """Create citation from dictionary in a given format"""
-    if format == 'bibtex':
-        print_bibtex(citation)
-    elif format == 'plain':
-        print_plain(citation)
-    elif format == 'dict':
-        pprint(citation)
-    else:
+    try:
+        _FORMAT_FUNCTION[format](citation)
+    except KeyError:
         raise RuntimeError(_("Unsupported format or style"))
 
 



More information about the grass-commit mailing list