From 7fc288cb1008713fb339659b464d912cb7226b5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=A1=D0=B5=D1=80?= =?UTF-8?q?=D0=B3=D0=B5=D0=B9=20=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD?= =?UTF-8?q?=D0=B4=D1=80=D0=BE=D0=B2=D0=B8=D1=87?= Date: Mon, 19 Aug 2024 11:03:32 +0300 Subject: [PATCH 1/2] - Fix russian UTF-8 result encoding - Add 'six' package to requirements.txt --- plantuml.py | 5 +++-- requirements.txt | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plantuml.py b/plantuml.py index 2b6fa2c..fcea09c 100755 --- a/plantuml.py +++ b/plantuml.py @@ -173,7 +173,7 @@ def processes(self, plantuml_text): raise PlantUMLHTTPError(response, content) return content - def processes_file(self, filename, outfile=None, errorfile=None, directory=''): + def processes_file(self, filename, outfile=None, errorfile=None, directory='', enconding="utf8"): """Take a filename of a file containing plantuml text and processes it into a .png image. @@ -185,6 +185,7 @@ def processes_file(self, filename, outfile=None, errorfile=None, directory=''): to. If this is not supplined, then it will be the input ``filename`` with the extension replaced with '_error.html'. + :param str encoding: Input file encoding, default UTF-8 :returns: ``True`` if the image write succedded, ``False`` if there was an error written to ``errorfile``. """ @@ -194,7 +195,7 @@ def processes_file(self, filename, outfile=None, errorfile=None, directory=''): errorfile = path.splitext(filename)[0] + '_error.html' if directory and not path.exists(directory): makedirs(directory) - data = open(filename).read() + data = open(filename, encoding=enconding).read() try: content = self.processes(data) except PlantUMLHTTPError as e: diff --git a/requirements.txt b/requirements.txt index a85f635..90f2fe1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ sphinx httplib2 twine wheel +six From da3c31099fcea1c16461c9eca1cb659c32347300 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=A1=D0=B5=D1=80?= =?UTF-8?q?=D0=B3=D0=B5=D0=B9=20=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD?= =?UTF-8?q?=D0=B4=D1=80=D0=BE=D0=B2=D0=B8=D1=87?= Date: Mon, 19 Aug 2024 11:09:02 +0300 Subject: [PATCH 2/2] - Code formatting --- plantuml.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/plantuml.py b/plantuml.py index fcea09c..503374a 100755 --- a/plantuml.py +++ b/plantuml.py @@ -24,9 +24,8 @@ __author__ = 'Doug Napoleone, Samuel Marks, Eric Frederich' __email__ = 'doug.napoleone+plantuml@gmail.com' - plantuml_alphabet = string.digits + string.ascii_uppercase + string.ascii_lowercase + '-_' -base64_alphabet = string.ascii_uppercase + string.ascii_lowercase + string.digits + '+/' +base64_alphabet = string.ascii_uppercase + string.ascii_lowercase + string.digits + '+/' b64_to_plantuml = maketrans(base64_alphabet.encode('utf-8'), plantuml_alphabet.encode('utf-8')) @@ -224,7 +223,7 @@ def main(): args = _build_parser().parse_args() pl = PlantUML(args.server) print(list(map(lambda filename: {'filename': filename, - 'gen_success': pl.processes_file(filename, directory=args.out)}, args.files))) + 'gen_success': pl.processes_file(filename, directory=args.out)}, args.files))) if __name__ == '__main__':