Ver código fonte

Add the workaround for broken YAML unicode

Vadim Markovtsev 7 anos atrás
pai
commit
a431fead30
2 arquivos alterados com 18 adições e 5 exclusões
  1. 7 0
      fix_yaml_unicode.py
  2. 11 5
      labours.py

+ 7 - 0
fix_yaml_unicode.py

@@ -0,0 +1,7 @@
+import yaml
+import sys
+
+yaml_invalid = yaml.reader.Reader.NON_PRINTABLE
+
+for line in sys.stdin:
+    sys.stdout.write(yaml_invalid.sub("", line))

+ 11 - 5
labours.py

@@ -56,12 +56,18 @@ def read_input(args):
     try:
     try:
         loader = yaml.CLoader
         loader = yaml.CLoader
     except AttributeError:
     except AttributeError:
+        print("Warning: failed to import yaml.CLoader, falling back to slow yaml.Loader")
         loader = yaml.Loader
         loader = yaml.Loader
-    if args.input != "-":
-        with open(args.input) as fin:
-            data = yaml.load(fin, Loader=loader)
-    else:
-        data = yaml.load(sys.stdin, Loader=loader)
+    try:
+        if args.input != "-":
+            with open(args.input) as fin:
+                data = yaml.load(fin, Loader=loader)
+        else:
+            data = yaml.load(sys.stdin, Loader=loader)
+    except UnicodeEncodeError as e:
+        print("\nInvalid unicode in the input: %s\nPlease filter it through fix_yaml_unicode.py" %
+              e)
+        sys.exit(1)
     print("done")
     print("done")
     return data["burndown"], data["project"], data.get("files"), data.get("people_sequence"), \
     return data["burndown"], data["project"], data.get("files"), data.get("people_sequence"), \
            data.get("people"), data.get("people_interaction"), data.get("files_coocc"), \
            data.get("people"), data.get("people_interaction"), data.get("files_coocc"), \