1.1 --- a/moinformat/output/common.py Sat Apr 13 00:26:57 2019 +0200
1.2 +++ b/moinformat/output/common.py Sat Apr 13 19:25:53 2019 +0200
1.3 @@ -54,7 +54,7 @@
1.4
1.5 "Add 'text' to the output collector."
1.6
1.7 - self.output.append(self.encode(text))
1.8 + self.output.append(text)
1.9
1.10 # Page characteristics.
1.11
1.12 @@ -68,9 +68,9 @@
1.13
1.14 def to_string(self):
1.15
1.16 - "Return the output as a plain string."
1.17 + "Return the output as a single Unicode string."
1.18
1.19 - s = "".join(self.output)
1.20 + s = u"".join(self.output)
1.21 self.reset()
1.22 return s
1.23
2.1 --- a/moinformat/serialisers/common.py Sat Apr 13 00:26:57 2019 +0200
2.2 +++ b/moinformat/serialisers/common.py Sat Apr 13 19:25:53 2019 +0200
2.3 @@ -3,7 +3,7 @@
2.4 """
2.5 Moin serialiser support.
2.6
2.7 -Copyright (C) 2017, 2018 Paul Boddie <paul@boddie.org.uk>
2.8 +Copyright (C) 2017, 2018, 2019 Paul Boddie <paul@boddie.org.uk>
2.9
2.10 This program is free software; you can redistribute it and/or modify it under
2.11 the terms of the GNU General Public License as published by the Free Software
2.12 @@ -75,7 +75,7 @@
2.13
2.14 def get_output(self):
2.15
2.16 - "Return the output as a string."
2.17 + "Return the output as a single Unicode string."
2.18
2.19 return self.output.to_string()
2.20
3.1 --- a/moinformat/themes/common.py Sat Apr 13 00:26:57 2019 +0200
3.2 +++ b/moinformat/themes/common.py Sat Apr 13 19:25:53 2019 +0200
3.3 @@ -3,7 +3,7 @@
3.4 """
3.5 Theming common functionality.
3.6
3.7 -Copyright (C) 2018 Paul Boddie <paul@boddie.org.uk>
3.8 +Copyright (C) 2018, 2019 Paul Boddie <paul@boddie.org.uk>
3.9
3.10 This program is free software; you can redistribute it and/or modify it under
3.11 the terms of the GNU General Public License as published by the Free Software
3.12 @@ -22,11 +22,14 @@
3.13 from os import listdir, makedirs
3.14 from os.path import exists, isfile, join, split
3.15 from shutil import copy
3.16 +import codecs
3.17
3.18 class Theme:
3.19
3.20 "A common theme abstraction."
3.21
3.22 + default_encoding = "utf-8"
3.23 +
3.24 def __init__(self, metadata):
3.25
3.26 "Initialise the theme with the given 'metadata'."
3.27 @@ -91,7 +94,7 @@
3.28
3.29 "Return the textual content of the resource with the given 'filename'."
3.30
3.31 - f = open(self.get_resource(filename))
3.32 + f = codecs.open(self.get_resource(filename), encoding=self.default_encoding)
3.33 try:
3.34 return f.read()
3.35 finally:
4.1 --- a/moinformat/utils/graphviz.py Sat Apr 13 00:26:57 2019 +0200
4.2 +++ b/moinformat/utils/graphviz.py Sat Apr 13 19:25:53 2019 +0200
4.3 @@ -280,7 +280,7 @@
4.4 def get_inline_output(self):
4.5
4.6 """
4.7 - Return a string containing the document element, excluding XML
4.8 + Return a Unicode string containing the document element, excluding XML
4.9 boilerplate.
4.10 """
4.11
4.12 @@ -289,7 +289,7 @@
4.13
4.14 try:
4.15 parser.parse_data(self.output)
4.16 - return f.getvalue()
4.17 + return unicode(f.getvalue(), "utf-8")
4.18 finally:
4.19 f.close()
4.20
5.1 --- a/tests/test_parser.py Sat Apr 13 00:26:57 2019 +0200
5.2 +++ b/tests/test_parser.py Sat Apr 13 19:25:53 2019 +0200
5.3 @@ -29,10 +29,18 @@
5.4 "pagename" : "TestPage",
5.5 })
5.6
5.7 + # Encode the input.
5.8 +
5.9 output = make_output(metadata)
5.10 expected = output.encode(s)
5.11
5.12 + # Obtain and encode the output.
5.13 +
5.14 result = serialise(d, make_serialiser(metadata))
5.15 + result = output.encode(result)
5.16 +
5.17 + # Test encoded input and output.
5.18 +
5.19 identical = result == expected
5.20
5.21 if quiet: