From b1dfade98d1cea191e39ff23ee94759425c814d7 Mon Sep 17 00:00:00 2001 From: Adam Waldenberg Date: Wed, 8 May 2013 18:52:08 +0200 Subject: [PATCH] Fixed compatibility with Python 3. --- blame.py | 3 ++- changes.py | 5 +++-- format.py | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/blame.py b/blame.py index 070a551..b26b6eb 100644 --- a/blame.py +++ b/blame.py @@ -20,6 +20,7 @@ from __future__ import print_function from outputable import Outputable from changes import FileDiff +import codecs import comment import filtering import format @@ -91,7 +92,7 @@ class Blame: for i, row in enumerate(lines): row = row.decode("utf-8", "replace").strip().strip("\"").strip("'") - row = row.decode("string_escape").strip() + row = codecs.getdecoder('unicode_escape')(row.strip())[0] if FileDiff.is_valid_extension(row) and not filtering.set_filtered(FileDiff.get_filename(row)): if not missing.add(row.strip()): diff --git a/changes.py b/changes.py index d72ad5d..234b4bd 100644 --- a/changes.py +++ b/changes.py @@ -19,6 +19,7 @@ from __future__ import print_function from outputable import Outputable +import codecs import extensions import filtering import interval @@ -45,13 +46,13 @@ class FileDiff: @staticmethod def get_extension(string): string = string.split("|")[0].strip().strip("{}").strip("\"").strip("'") - string = string.decode("string_escape").strip() + string = codecs.getdecoder('unicode_escape')(string.strip())[0] return os.path.splitext(string)[1][1:] @staticmethod def get_filename(string): string = string.split("|")[0].strip().strip("{}").strip("\"").strip("'") - return string.decode("string_escape").strip() + return codecs.getdecoder('unicode_escape')(string.strip())[0] @staticmethod def is_valid_extension(string): diff --git a/format.py b/format.py index 754ae28..91a3e1b 100644 --- a/format.py +++ b/format.py @@ -52,7 +52,7 @@ def __get_zip_file_content__(name): zip_file = zipfile.ZipFile(basedir.get_basedir() + "/html/flot.zip", "r") content = zip_file.read(name) zip_file.close() - return content + return content.decode("utf-8", "replace") def output_header(): if __selected_format__ == "html": @@ -67,7 +67,7 @@ def output_header(): logo_file.close() logo = base64.b64encode(logo) - print(html_header.format(version.__version__, jquery_js, flot_js, pie_js, logo)) + print(html_header.format(version.__version__, jquery_js, flot_js, pie_js, logo.decode("utf-8", "replace"))) elif __selected_format__ == "xml": print("") print("\t" + version.__version__ + "")