diff --git a/fluffy/component/backends.py b/fluffy/component/backends.py index 28e88eb..1df1453 100644 --- a/fluffy/component/backends.py +++ b/fluffy/component/backends.py @@ -19,7 +19,7 @@ class FileBackend: def _store(self, path_key, obj): path = app.config['STORAGE_BACKEND'][path_key].format(name=obj.name) - with open(path, 'wb') as f: + with open(path, 'wb+') as f: shutil.copyfileobj(obj.open_file, f) obj.open_file.seek(0) diff --git a/fluffy/component/highlighting.py b/fluffy/component/highlighting.py index 9a993b8..feba4f4 100644 --- a/fluffy/component/highlighting.py +++ b/fluffy/component/highlighting.py @@ -1,3 +1,4 @@ +import difflib import functools import re from collections import namedtuple @@ -178,6 +179,24 @@ def get_highlighter(text, language, filename): return PygmentsHighlighter(lexer) +def create_diff(text, text2): + """ + The diff between two texts is calculated + """ + delta = difflib.unified_diff(text.split('\n'), text2.split('\n')) + diff_lines = list(delta) + # if we find differences, we return them with the original code + # if not, we just return the original texts (otherwise we would get empty strings) + if diff_lines: + diff_lines = diff_lines[3:] + diff = '\n'.join((line if not line.startswith('+') else '') for line in diff_lines) + diff2 = '\n'.join((line if not line.startswith('-') else '') for line in diff_lines) + print(diff, diff2) + return diff, diff2 + else: + return text, text2 + + # All guesslang titles with available Pygments lexers match automatically # except for these exceptions. GUESSLANG_LANGUAGE_MAP = { diff --git a/fluffy/templates/home.html b/fluffy/templates/home.html index 83a072d..8cb012f 100644 --- a/fluffy/templates/home.html +++ b/fluffy/templates/home.html @@ -35,9 +35,10 @@

upload files instead

-

- -

+
+ + +

- +