- doc_file = cStringIO.StringIO()
- expr = re.compile(r'/\s', re.MULTILINE | re.UNICODE);
-
- f = open(input_filename, 'r')
- for line in f:
- line = line.decode('utf-8')
- line = expr.sub(u'<br/>\n', line)
- doc_file.write(line.encode('utf-8'))
- f.close()
-
- doc_file.seek(0)
-
- parser = etree.XMLParser(remove_blank_text=True)
- doc = etree.parse(doc_file, parser)
-
- result = doc.xslt(style)
- output_file = codecs.open(output_filename, 'wb', encoding='utf-8')
- output_file.write(unicode(result) % dcparser.parse(input_filename).url)
+ document = parser.WLDocument.from_file(input_file, True, parse_dublincore=parse_dublincore)
+ result = document.transform(style, **options)
+
+ if parse_dublincore:
+ parsed_dc = dcparser.BookInfo.from_element(document.edoc)
+ description = parsed_dc.description
+ url = parsed_dc.url
+ 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, license)
+ else:
+ license_description = u"Ten utwór nie jest chroniony prawem autorskim i znajduje się w domenie publicznej, co oznacza, że możesz go swobodnie wykorzystywać, publikować i rozpowszechniać"
+ source = parsed_dc.source_name
+ if source:
+ source = "\n\nNa podstawie: " + source
+ else:
+ source = ''
+ else:
+ description = 'Publikacja zrealizowana w ramach projektu Wolne Lektury (http://wolnelektury.pl).'
+ url = '*' * 10
+ license = ""
+ license_description = ""
+ source = ""
+ output_file.write((TEMPLATE % {
+ 'description': description,
+ 'url': url,
+ 'license_description': license_description,
+ 'text': unicode(result),
+ 'source': source,
+ }).encode('utf-8'))