Explorar o código

Delegated format recognition to exporter_factory in main.get_export

Vsevolod Levitan hai 1 ano
pai
achega
ed7d87d5b5
Modificáronse 1 ficheiros con 4 adicións e 9 borrados
  1. 4 9
      main.py

+ 4 - 9
main.py

@@ -38,15 +38,10 @@ def get_export_format(storage_key: str, format: str):
 def get_export(storage_key: str):
     global setman, start, strg
     format = setman.settings.export_format
-    exp = None
-    format = format.lower().strip()
-    fac = exporter_factory()
-    if format == "csv":
-        exp = fac.make_csv()
-    elif format == "json":
-        exp = fac.make_json()
-    elif format == "markdown":
-        exp = fac.make_markdown()
+    try:
+        exp = exporter_factory().create(format)
+    except argument_exception as e:
+        return "Wrong format: " + e.error.error_text, 400
 
     if storage_key not in strg.data:
         return "Key not found", 404