summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarian Sigler <m@qjym.de>2018-04-09 00:39:52 +0200
committerMarian Sigler <m@qjym.de>2018-04-09 00:39:52 +0200
commite6c88107426c589157f61292d67bacc76320fb7b (patch)
tree193230b04e778323dc0c3e20dc588d5f8b4e579a
parentf2a762714adca7671cfb2d783c659560cba85269 (diff)
downloadklausuren-e6c88107426c589157f61292d67bacc76320fb7b.tar.gz
klausuren-e6c88107426c589157f61292d67bacc76320fb7b.tar.bz2
klausuren-e6c88107426c589157f61292d67bacc76320fb7b.zip
fix unicode problems:
always encode before doing filesystem stuff, always decode after.
-rw-r--r--app/backend.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/app/backend.py b/app/backend.py
index e601c0c..94e7c67 100644
--- a/app/backend.py
+++ b/app/backend.py
@@ -9,8 +9,8 @@ class Storage:
self.path = path_app
self.root = path_rel
- def _join(self, *arg):
- return os.path.join(self.path, *arg)
+ def _join(self, *components):
+ return os.path.join(self.path, *(ensureutf8(c) for c in components))
def get_courses(self):
""" Lists all courses of a study """
@@ -35,7 +35,7 @@ class Storage:
def get_exams(self, name):
""" Lists all exams of a given course """
# loop over all directories which do not contain any subdirs
- for root, dirs, files in os.walk(self._join(name).encode('utf-8')):
+ for root, dirs, files in os.walk(self._join(name)):
if len(dirs) == 0:
# metainformation is encoded in path: course/year/exam.pdf
splitted = root.split(os.path.sep)
@@ -45,5 +45,12 @@ class Storage:
if year.isdigit():
# yield entries as tuples (name, path) grouped by years
func = partial(os.path.join, self.root, course, year)
- entries = [(f, func(f)) for f in files]
+ # filenames created by this app are always ascii-only, but let's
+ # decode it nonetheless just to be sure...
+ entries = [(f.decode('utf-8'), func(f)) for f in files]
yield (year, entries)
+
+def ensureutf8(s):
+ if isinstance(s, unicode):
+ return s.encode('utf-8')
+ return s