X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/f8e5f031c04122d65d1066077be3920ae95518ae..95e4429c3619b4ed91fa1a392ec0b34410f412a7:/librarian/__init__.py diff --git a/librarian/__init__.py b/librarian/__init__.py index 5997a4e..582ee98 100644 --- a/librarian/__init__.py +++ b/librarian/__init__.py @@ -1,4 +1,24 @@ # -*- coding: utf-8 -*- +# +# This file is part of Librarian. +# +# Copyright © 2008,2009,2010 Fundacja Nowoczesna Polska +# +# For full list of contributors see AUTHORS file. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# # exception classes class ParseError(Exception): @@ -85,4 +105,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)