X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/f8e5f031c04122d65d1066077be3920ae95518ae..e82ceed3d3d72dc75697449285a67e0a42a9cc56:/librarian/__init__.py?ds=sidebyside diff --git a/librarian/__init__.py b/librarian/__init__.py index 5997a4e..10c3766 100644 --- a/librarian/__init__.py +++ b/librarian/__init__.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- -# exception classes - +# +# This file is part of Librarian, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# class ParseError(Exception): def __init__(self, cause, message=None): @@ -85,4 +87,21 @@ def wrap_text(ocrtext, creation_date, bookinfo=DEFAULT_BOOKINFO): method='xml', encoding=unicode, pretty_print=True) return u'\n' + dcstring + u'\n\n' + ocrtext +\ - u'\n\n'; \ No newline at end of file + u'\n\n'; + + +def serialize_raw(element): + b = u'' + (element.text or '') + + for child in element.iterchildren(): + e = etree.tostring(child, method='xml', encoding=unicode, pretty_print=True) + b += e + + return b + +SERIALIZERS = { + 'raw': serialize_raw, +} + +def serialize_children(element, format='raw'): + return SERIALIZERS[format](element)