# This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
# This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
+ args = self.args[0] if len(self.args) == 1 else self.args
+ try:
+ message = six.text_type(args)
+ except UnicodeDecodeError:
+ message = six.text_type(args, encoding='utf-8', errors='ignore')
+ return message
+
+class ParseError(UnicodeException):
+ pass
pass
class NoDublinCore(ValidationError):
"""There's no DublinCore section, and it's required."""
pass
pass
class NoDublinCore(ValidationError):
"""There's no DublinCore section, and it's required."""
pass
RDFNS = XMLNamespace('http://www.w3.org/1999/02/22-rdf-syntax-ns#')
DCNS = XMLNamespace('http://purl.org/dc/elements/1.1/')
XINS = XMLNamespace("http://www.w3.org/2001/XInclude")
XHTMLNS = XMLNamespace("http://www.w3.org/1999/xhtml")
NCXNS = XMLNamespace("http://www.daisy.org/z3986/2005/ncx/")
OPFNS = XMLNamespace("http://www.idpf.org/2007/opf")
RDFNS = XMLNamespace('http://www.w3.org/1999/02/22-rdf-syntax-ns#')
DCNS = XMLNamespace('http://purl.org/dc/elements/1.1/')
XINS = XMLNamespace("http://www.w3.org/2001/XInclude")
XHTMLNS = XMLNamespace("http://www.w3.org/1999/xhtml")
NCXNS = XMLNamespace("http://www.daisy.org/z3986/2005/ncx/")
OPFNS = XMLNamespace("http://www.idpf.org/2007/opf")
class WLURI(object):
"""Represents a WL URI. Extracts slug from it."""
slug = None
example = 'http://wolnelektury.pl/katalog/lektura/template/'
class WLURI(object):
"""Represents a WL URI. Extracts slug from it."""
slug = None
example = 'http://wolnelektury.pl/katalog/lektura/template/'
- raise ValueError('Supplied URI (%s) does not match '
- 'the template: %s.' % (uri, cls._re_wl_uri))
+ raise ValidationError(u'Invalid URI (%s). Should match: %s' % (
+ uri, cls._re_wl_uri.pattern))
return cls(uri)
@classmethod
def from_slug(cls, slug):
"""Contructs an URI from slug.
return cls(uri)
@classmethod
def from_slug(cls, slug):
"""Contructs an URI from slug.
DEFAULT_BOOKINFO = dcparser.BookInfo(
{ RDFNS('about'): u'http://wiki.wolnepodreczniki.pl/Lektury:Template'},
DEFAULT_BOOKINFO = dcparser.BookInfo(
{ RDFNS('about'): u'http://wiki.wolnepodreczniki.pl/Lektury:Template'},
def wrap_text(ocrtext, creation_date, bookinfo=DEFAULT_BOOKINFO):
"""Wrap the text within the minimal XML structure with a DC template."""
bookinfo.created_at = creation_date
dcstring = etree.tostring(bookinfo.to_etree(), \
def wrap_text(ocrtext, creation_date, bookinfo=DEFAULT_BOOKINFO):
"""Wrap the text within the minimal XML structure with a DC template."""
bookinfo.created_at = creation_date
dcstring = etree.tostring(bookinfo.to_etree(), \
- e = etree.tostring(child, method='xml', encoding=unicode,
+ e = etree.tostring(child, method='xml', encoding='unicode',
- if self._string is not None:
- from StringIO import StringIO
- return StringIO(self._string)
+ if self._bytes is not None:
+ return six.BytesIO(self._bytes)
"""Save file to a path. Create directories, if necessary."""
dirname = os.path.dirname(os.path.abspath(path))
"""Save file to a path. Create directories, if necessary."""
dirname = os.path.dirname(os.path.abspath(path))