Python 3.4-3.7 support;
[librarian.git] / librarian / text.py
index 0eb7b59..7ba6d29 100644 (file)
@@ -3,10 +3,13 @@
 # This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
 #
+from __future__ import unicode_literals
+
 import copy
 from librarian import functions, OutputFile
 from lxml import etree
 import os
+import six
 
 
 functions.reg_substitute_entities()
@@ -24,9 +27,9 @@ Wersja lektury w opracowaniu merytorycznym i krytycznym (przypisy i motywy) dost
 
 Utwór opracowany został w ramach projektu Wolne Lektury przez fundację Nowoczesna Polska.
 
-%(license_description)s.%(source)s
+%(license_description)s.%(source)s%(publisher)s
 
-%(description)s%(contributors)s%(funders)s
+%(description)s%(contributors)s%(funders)s%(isbn)s
 """
 
 
@@ -60,7 +63,7 @@ def transform(wldoc, flags=None, **options):
             license_description = parsed_dc.license_description
             license = parsed_dc.license
             if license:
-                license_description = u"Ten utwór jest udostepniony na licencji %s: \n%s" % (
+                license_description = u"Ten utwór jest udostępniony na licencji %s: \n%s" % (
                     license_description, license)
             else:
                 license_description = u"Ten utwór nie jest objęty majątkowym prawem autorskim i znajduje się " \
@@ -83,7 +86,13 @@ def transform(wldoc, flags=None, **options):
                 contributors = "\n\nOpracowanie redakcyjne i przypisy: %s." % contributors
             funders = ', '.join(parsed_dc.funders)
             if funders:
-                funders = u"\n\nPublikację ufundowali i ufundowały: %s." % funders
+                funders = u"\n\nPublikację wsparli i wsparły: %s." % funders
+            publisher = '\n\nWydawca: ' + ', '.join(parsed_dc.publisher)
+            isbn = getattr(parsed_dc, 'isbn_txt', None)
+            if isbn:
+                isbn = '\n\n' + isbn
+            else:
+                isbn = ''
         else:
             description = 'Publikacja zrealizowana w ramach projektu Wolne Lektury (http://wolnelektury.pl).'
             url = '*' * 10
@@ -91,15 +100,19 @@ def transform(wldoc, flags=None, **options):
             source = ""
             contributors = ""
             funders = ""
+            publisher = ""
+            isbn = ""
         result = (TEMPLATE % {
             'description': description,
             'url': url,
             'license_description': license_description,
-            'text': unicode(result),
+            'text': six.text_type(result),
             'source': source,
             'contributors': contributors,
             'funders': funders,
+            'publisher': publisher,
+            'isbn': isbn,
         }).encode('utf-8')
     else:
-        result = unicode(result).encode('utf-8')
-    return OutputFile.from_string("\r\n".join(result.splitlines()) + "\r\n")
+        result = six.text_type(result).encode('utf-8')
+    return OutputFile.from_bytes(b"\r\n".join(result.splitlines()) + b"\r\n")