[Python-modules-commits] [python-djvulibre] 01/06: Imported Upstream version 0.4

Daniel Stender danstender-guest at moszumanska.debian.org
Sun Jul 26 15:23:43 UTC 2015


This is an automated email from the git hooks/post-receive script.

danstender-guest pushed a commit to branch master
in repository python-djvulibre.

commit 61e96ceef22de5fdf9a6651b68470b24b1ea29d0
Author: Daniel Stender <debian at danielstender.com>
Date:   Sun Jul 26 16:29:19 2015 +0200

    Imported Upstream version 0.4
---
 MANIFEST.in                                        |  14 +-
 PKG-INFO                                           |   2 +-
 djvu/__init__.py                                   |  19 ++
 djvu/common.pxi                                    |   6 +-
 djvu/config.pxi                                    |   3 +
 djvu/const.py                                      |  33 +--
 djvu/decode.pxd                                    |   4 +-
 djvu/decode.pyx                                    | 119 ++++++----
 djvu/dllpath.py                                    |   2 +-
 djvu/sexpr.pxd                                     |   8 +-
 djvu/sexpr.pyx                                     | 103 +++++----
 COPYING => doc/COPYING                             |   0
 .../annotations.txt => api/annotations.rst}        | 144 ++++++------
 doc/{source => api}/conf.py                        |  19 +-
 doc/{source/documents.txt => api/documents.rst}    |   2 +-
 .../event-model.txt => api/event-model.rst}        |   2 +-
 doc/{source/exceptions.txt => api/exceptions.rst}  |   2 +-
 .../expressions.txt => api/expressions.rst}        |  27 ++-
 doc/{source/files.txt => api/files.rst}            |   2 +-
 doc/{source/geometry.txt => api/geometry.rst}      |   2 +-
 doc/{source/index.txt => api/index.rst}            |   6 +-
 doc/{source/messages.txt => api/messages.rst}      |   2 +-
 doc/{source/outline.txt => api/outline.rst}        |  14 +-
 doc/{source/pages.txt => api/pages.rst}            |   2 +-
 doc/{source/text-zones.txt => api/text-zones.rst}  |  20 +-
 doc/changelog                                      |  22 +-
 examples/djvu-crop-text                            |  18 +-
 examples/djvu-dump-text                            |  18 +-
 examples/djvu2png                                  |   8 +-
 python_djvulibre.egg-info/PKG-INFO                 |   2 +-
 python_djvulibre.egg-info/SOURCES.txt              |  29 +--
 setup.py                                           |  56 ++---
 tests/common.py                                    | 164 +++++++++++---
 tests/images/Makefile                              |   2 +-
 tests/sexpr-gc.py                                  |  32 +--
 tests/test_const.py                                |  30 ++-
 tests/test_decode.py                               | 190 +++++++++-------
 tests/test_sexpr.py                                | 248 +++++++++++++--------
 38 files changed, 840 insertions(+), 536 deletions(-)

diff --git a/MANIFEST.in b/MANIFEST.in
index 29f788e..e035ff7 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -1,10 +1,14 @@
 include MANIFEST.in
-include COPYING
-include doc/changelog
+
 include doc/*.txt
-include doc/source/conf.py
-include doc/source/*.txt
+include doc/COPYING
+include doc/changelog
+include doc/api/*.rst
+include doc/api/conf.py
+
 include examples/*
-recursive-include djvu *.py *.pxi *.pxd *.pyx
+
 recursive-exclude djvu config.pxi
+recursive-include djvu *.py *.pxi *.pxd *.pyx
+
 recursive-include tests *.py Makefile *.jpeg *.tex *.djvu
diff --git a/PKG-INFO b/PKG-INFO
index a95379a..f202e05 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: python-djvulibre
-Version: 0.3.10
+Version: 0.4
 Summary: Python support for the DjVu image format
 Home-page: http://jwilk.net/software/python-djvulibre
 Author: Jakub Wilk
diff --git a/djvu/__init__.py b/djvu/__init__.py
index e69de29..139d524 100644
--- a/djvu/__init__.py
+++ b/djvu/__init__.py
@@ -0,0 +1,19 @@
+# encoding=UTF-8
+
+# Copyright © 2015 Jakub Wilk <jwilk at jwilk.net>
+#
+# This package is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 dated June, 1991.
+#
+# This package 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
+# General Public License for more details.
+
+import sys
+
+if sys.version_info < (2, 6):
+    raise RuntimeError('Python >= 2.6 is required')
+
+# vim:ts=4 sts=4 sts=4 sw=4 et
diff --git a/djvu/common.pxi b/djvu/common.pxi
index e90d200..b93f349 100644
--- a/djvu/common.pxi
+++ b/djvu/common.pxi
@@ -1,4 +1,4 @@
-# Copyright © 2008-2012 Jakub Wilk <jwilk at jwilk.net>
+# Copyright © 2008-2015 Jakub Wilk <jwilk at jwilk.net>
 #
 # This package is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -122,7 +122,7 @@ cdef int is_file(object o):
         return typecheck(o, file)
 
 cdef void raise_instantiation_error(object cls) except *:
-    raise TypeError, 'cannot create \'%s\' instances' % get_type_name(cls)
+    raise TypeError, 'cannot create \'{tp}\' instances'.format(tp=get_type_name(cls))
 
 cdef object decode_utf8(char* s):
     return decode_utf8_ex(s, strlen(s), NULL)
@@ -131,4 +131,4 @@ cdef extern from 'pyerrors.h':
     ctypedef class __builtin__.Exception [object PyBaseExceptionObject]:
         pass
 
-# vim:ts=4 sw=4 et ft=pyrex
+# vim:ts=4 sts=4 sw=4 et ft=pyrex
diff --git a/djvu/config.pxi b/djvu/config.pxi
new file mode 100644
index 0000000..9ac1fdd
--- /dev/null
+++ b/djvu/config.pxi
@@ -0,0 +1,3 @@
+DEF PY3K = False
+DEF PYTHON_DJVULIBRE_VERSION = "0.4"
+DEF HAVE_LANGINFO_H = True
diff --git a/djvu/const.py b/djvu/const.py
index fdafef4..d4e08d8 100644
--- a/djvu/const.py
+++ b/djvu/const.py
@@ -18,7 +18,7 @@ import djvu.sexpr
 EMPTY_LIST = djvu.sexpr.Expression([])
 EMPTY_OUTLINE = djvu.sexpr.Expression([djvu.sexpr.Symbol('bookmarks')])
 
-METADATA_BIBTEX_KEYS = frozenset(djvu.sexpr.Symbol(x) for x in '''\
+METADATA_BIBTEX_KEYS = frozenset(djvu.sexpr.Symbol(x) for x in '''
 address
 annote
 author
@@ -45,7 +45,7 @@ volume
 year'''.split())
 # Retrieved from <http://www.ctan.org/get/biblio/bibtex/contrib/doc/btxdoc.pdf>
 
-METADATA_PDFINFO_KEYS = frozenset(djvu.sexpr.Symbol(x) for x in '''\
+METADATA_PDFINFO_KEYS = frozenset(djvu.sexpr.Symbol(x) for x in '''
 Author
 CreationDate
 Creator
@@ -102,7 +102,11 @@ class TextZoneType(djvu.sexpr.Symbol):
         return self.__rank >= other.__rank
 
     def __repr__(self):
-        return '<%s.%s: %s>' % (self.__module__, self.__class__.__name__, self)
+        return '<{mod}.{cls}: {name}>'.format(
+            mod=self.__module__,
+            cls=self.__class__.__name__,
+            name=self
+        )
 
 TEXT_ZONE_PAGE = TextZoneType('page', 7)
 TEXT_ZONE_COLUMN = TextZoneType('column', 6)
@@ -115,14 +119,13 @@ TEXT_ZONE_CHARACTER = TextZoneType('char', 1)
 def get_text_zone_type(symbol):
     return TextZoneType.from_symbol(symbol)
 
-TEXT_ZONE_SEPARATORS = \
-{
-    TEXT_ZONE_PAGE:      '\f',   # Form Feed (FF)
-    TEXT_ZONE_COLUMN:    '\v',   # Vertical tab (VT, LINE TABULATION)
-    TEXT_ZONE_REGION:    '\035', # Group Separator (GS, INFORMATION SEPARATOR THREE)
-    TEXT_ZONE_PARAGRAPH: '\037', # Unit Separator (US, INFORMATION SEPARATOR ONE)
-    TEXT_ZONE_LINE:      '\n',   # Line Feed (LF)
-    TEXT_ZONE_WORD:      ' ',    # space
+TEXT_ZONE_SEPARATORS = {
+    TEXT_ZONE_PAGE:      '\f',  # Form Feed (FF)
+    TEXT_ZONE_COLUMN:    '\v',  # Vertical tab (VT, LINE TABULATION)
+    TEXT_ZONE_REGION:    '\035',  # Group Separator (GS, INFORMATION SEPARATOR THREE)
+    TEXT_ZONE_PARAGRAPH: '\037',  # Unit Separator (US, INFORMATION SEPARATOR ONE)
+    TEXT_ZONE_LINE:      '\n',  # Line Feed (LF)
+    TEXT_ZONE_WORD:      ' ',  # space
     TEXT_ZONE_CHARACTER: ''
 }
 
@@ -177,9 +180,9 @@ MAPAREA_TEXT_COLOR_DEFAULT = '#000000'
 
 # 8.3.4.1 Initial Document View :
 ANNOTATION_BACKGROUND = djvu.sexpr.Symbol('background')  # 8.3.4.1.1 Background Color
-ANNOTATION_ZOOM       = djvu.sexpr.Symbol('zoom') # 8.3.4.1.2 Initial Zoom
-ANNOTATION_MODE       = djvu.sexpr.Symbol('mode') # 8.3.4.1.3 Initial Display level
-ANNOTATION_ALIGN      = djvu.sexpr.Symbol('align') # 8.3.4.1.4 Alignment
+ANNOTATION_ZOOM       = djvu.sexpr.Symbol('zoom')  # 8.3.4.1.2 Initial Zoom
+ANNOTATION_MODE       = djvu.sexpr.Symbol('mode')  # 8.3.4.1.3 Initial Display level
+ANNOTATION_ALIGN      = djvu.sexpr.Symbol('align')  # 8.3.4.1.4 Alignment
 
 # djvuchanges.txt, sections "Metadata Annotations" and "Document Annotations and Metadata":
 ANNOTATION_METADATA   = djvu.sexpr.Symbol('metadata')
@@ -191,4 +194,4 @@ PRINTER_HEADER_ALIGN_LEFT   = PRINTED_FOOTER_ALIGN_LEFT   = djvu.sexpr.Symbol('l
 PRINTER_HEADER_ALIGN_CENTER = PRINTED_FOOTER_ALIGN_CENTER = djvu.sexpr.Symbol('center')
 PRINTER_HEADER_ALIGN_RIGHT  = PRINTED_FOOTER_ALIGN_RIGHT  = djvu.sexpr.Symbol('right')
 
-# vim:ts=4 sw=4 et
+# vim:ts=4 sts=4 sw=4 et
diff --git a/djvu/decode.pxd b/djvu/decode.pxd
index 03229f6..3d19773 100644
--- a/djvu/decode.pxd
+++ b/djvu/decode.pxd
@@ -1,4 +1,4 @@
-# Copyright © 2007, 2008, 2009 Jakub Wilk <jwilk at jwilk.net>
+# Copyright © 2007-2009 Jakub Wilk <jwilk at jwilk.net>
 #
 # This package is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -353,4 +353,4 @@ cdef class ProgressMessage(Message):
 cdef class Thumbnail:
     cdef Page _page
 
-# vim:ts=4 sw=4 et ft=pyrex
+# vim:ts=4 sts=4 sw=4 et ft=pyrex
diff --git a/djvu/decode.pyx b/djvu/decode.pyx
index b1cbe45..0ba53ca 100644
--- a/djvu/decode.pyx
+++ b/djvu/decode.pyx
@@ -232,7 +232,9 @@ cdef object write_unraisable_exception(object cause):
         # This mostly happens during interpreter cleanup.
         # It's worthless to try to recover.
         raise SystemExit
-    sys.stderr.write('Unhandled exception in thread started by %r\n%s\n' % (cause, message))
+    sys.stderr.write(
+        'Unhandled exception in thread started by {obj!r}\n{msg}\n'.format(obj=cause, msg=message)
+    )
 
 cdef class _FileWrapper:
 
@@ -298,8 +300,8 @@ class DjVuLibreBug(Exception):
         Exception.__init__(
             self,
             'A DjVuLibre bug has been encountered.\n'
-            'See <https://bugs.debian.org/%d> for details.\n'
-            'Please upgrade your DjVuLibre.' % (debian_bug_no,)
+            'See <https://bugs.debian.org/{0}> for details.\n'
+            'Please upgrade your DjVuLibre.'.format(debian_bug_no)
         )
 
 cdef class DocumentExtension:
@@ -561,7 +563,11 @@ cdef class Page:
             return PageText(self)
 
     def __repr__(self):
-        return '%s(%r, %r)' % (get_type_name(Page), self._document, self._n)
+        return '{tp}({doc!r}, {n})'.format(
+            tp=get_type_name(Page),
+            doc=self._document,
+            n=self._n,
+        )
 
 cdef class Thumbnail:
 
@@ -644,7 +650,10 @@ cdef class Thumbnail:
             raise _NotAvailable_
 
     def __repr__(self):
-        return '%s(%r)' % (get_type_name(Thumbnail), self._page)
+        return '{tp}({page!r})'.format(
+            tp=get_type_name(Thumbnail),
+            page=self._page,
+        )
 
 cdef class DocumentFiles(DocumentExtension):
 
@@ -911,8 +920,7 @@ PRINT_ORIENTATION_LANDSCAPE = 'landscape'
 PRINT_ORIENTATION_PORTRAIT = 'portrait'
 
 cdef object PRINT_RENDER_MODE_MAP
-PRINT_RENDER_MODE_MAP = \
-{
+PRINT_RENDER_MODE_MAP = {
     DDJVU_RENDER_COLOR: None,
     DDJVU_RENDER_BLACK: 'bw',
     DDJVU_RENDER_FOREGROUND: 'fore',
@@ -962,10 +970,13 @@ cdef class DocumentDecodingJob(Job):
         self.ddjvu_job = <ddjvu_job_t*> document.ddjvu_document
 
     def __dealloc__(self):
-        self.ddjvu_job = NULL # Don't allow Job.__dealloc__ to release the job.
+        self.ddjvu_job = NULL  # Don't allow Job.__dealloc__ to release the job.
 
     def __repr__(self):
-        return '<%s for %r>' % (get_type_name(DocumentDecodingJob), self._document)
+        return '<{tp} for {doc!r}>'.format(
+            tp=get_type_name(DocumentDecodingJob),
+            doc=self._document,
+        )
 
 cdef class Document:
 
@@ -1266,7 +1277,7 @@ cdef class Document:
         if level is not None:
             if not is_int(level):
                 raise TypeError('level must be an integer')
-            list_append(options, '--level=%d' % level)
+            list_append(options, '--level={0}'.format(level))
         if orientation is not None:
             if not is_string(orientation):
                 raise TypeError('orientation must be a string or none')
@@ -1282,7 +1293,7 @@ cdef class Document:
         if zoom is not None:
             if not is_int(zoom):
                 raise TypeError('zoom must be an integer or none')
-            list_append(options, '--zoom=%d' % zoom)
+            list_append(options, '--zoom={0}'.format(zoom))
         if not color:
             list_append(options, '--color=no')
         if not srgb:
@@ -1290,11 +1301,11 @@ cdef class Document:
         if gamma is not None:
             if not is_int(gamma) and not is_float(gamma):
                 raise TypeError('gamma must be a number or none')
-            list_append(options, '--gamma=%.16f' % gamma)
+            list_append(options, '--gamma={0:.16f}'.format(gamma))
         if not is_int(copies):
             raise TypeError('copies must be an integer')
         if copies != 1:
-            list_append(options, '--options=%d' % copies)
+            list_append(options, '--options={0}'.format(copies))
         if frame:
             list_append(options, '--frame')
         if crop_marks:
@@ -1310,13 +1321,13 @@ cdef class Document:
         if not is_int(booklet_max):
             raise TypeError('booklet_max must be an integer')
         if booklet_max:
-            list_append(options, '--bookletmax=%d' % booklet_max)
+            list_append(options, '--bookletmax={0}'.format(booklet_max))
         if not is_int(booklet_align):
             raise TypeError('booklet_align must be an integer')
         if booklet_align:
-            list_append(options, '--bookletalign=%d' % booklet_align)
+            list_append(options, '--bookletalign={0}'.format(booklet_align))
         if is_int(booklet_fold):
-            list_append(options, '--bookletfold=%d' % booklet_fold)
+            list_append(options, '--bookletfold={0}'.format(booklet_fold))
         else:
             try:
                 fold_base, fold_incr = booklet_fold
@@ -1324,7 +1335,7 @@ cdef class Document:
                     raise TypeError
             except TypeError:
                 raise TypeError('booklet_fold must a be an integer or a pair of integers')
-            list_append(options, '--bookletfold=%d+%d' % (fold_base, fold_incr))
+            list_append(options, '--bookletfold={0}+{1}'.format(fold_base, fold_incr))
         cdef char **optv
         cdef int optc
         cdef size_t buffer_size
@@ -1332,7 +1343,7 @@ cdef class Document:
         buffer_size = len(options) * sizeof (char*)
         optv = <char**> py_malloc(buffer_size)
         if optv == NULL:
-            raise MemoryError('Unable to allocate %d bytes for print options' % buffer_size)
+            raise MemoryError('Unable to allocate {0} bytes for print options'.format(buffer_size))
         try:
             for optc from 0 <= optc < len(options):
                 option = options[optc]
@@ -1429,7 +1440,7 @@ def _Context_message_distributor(Context self not None, **kwargs):
                 if job.is_done:
                     job.__clear()
             elif message._page_job is not None:
-                raise SystemError # should not happen
+                raise SystemError  # should not happen
             elif message._document is not None:
                 document = message._document
                 document._condition.acquire()
@@ -1502,7 +1513,7 @@ cdef class Context:
         if message._job is not None:
             message._job._queue.put(message)
         elif message._page_job is not None:
-            raise SystemError # should not happen
+            raise SystemError  # should not happen
         elif message._document is not None:
             message._document._queue.put(message)
         else:
@@ -1713,7 +1724,7 @@ cdef class PixelFormat:
             ddjvu_format_release(self.ddjvu_format)
 
     def __repr__(self):
-        return '%s()' % (get_type_name(type(self)),)
+        return '{tp}()'.format(tp=get_type_name(type(self)))
 
 cdef class PixelFormatRgb(PixelFormat):
 
@@ -1756,11 +1767,10 @@ cdef class PixelFormatRgb(PixelFormat):
                 return 'BGR'
 
     def __repr__(self):
-        return '%s(byte_order = %r, bpp = %d)' % \
-        (
-            get_type_name(PixelFormatRgb),
-            self.byte_order,
-            self.bpp
+        return '{tp}(byte_order = {bo!r}, bpp = {bpp})'.format(
+            tp=get_type_name(PixelFormatRgb),
+            bo=self.byte_order,
+            bpp=self.bpp,
         )
 
 cdef class PixelFormatRgbMask(PixelFormat):
@@ -1801,14 +1811,14 @@ cdef class PixelFormatRgbMask(PixelFormat):
         self.ddjvu_format = ddjvu_format_create(_format, 4, self._params)
 
     def __repr__(self):
-        return '%s(red_mask = 0x%0*x, green_mask = 0x%0*x, blue_mask = 0x%0*x, xor_value = 0x%0*x, bpp = %d)' % \
-        (
-            get_type_name(PixelFormatRgbMask),
-            self.bpp//4, self._params[0],
-            self.bpp//4, self._params[1],
-            self.bpp//4, self._params[2],
-            self.bpp//4, self._params[3],
-            self.bpp,
+        return '{tp}(red_mask = 0x{r:0{w}x}, green_mask = 0x{g:0{w}x}, blue_mask = 0x{b:0{w}x}, xor_value = 0x{x:0{w}x}, bpp = {bpp})'.format(
+            tp=get_type_name(PixelFormatRgbMask),
+            r=self._params[0],
+            g=self._params[1],
+            b=self._params[2],
+            x=self._params[3],
+            w=self.bpp//4,
+            bpp=self.bpp,
         )
 
 cdef class PixelFormatGrey(PixelFormat):
@@ -1827,7 +1837,10 @@ cdef class PixelFormatGrey(PixelFormat):
         self.ddjvu_format = ddjvu_format_create(DDJVU_FORMAT_GREY8, 0, NULL)
 
     def __repr__(self):
-        return '%s(bpp = %d)' % (get_type_name(PixelFormatGrey), self.bpp)
+        return '{tp}(bpp = {bpp!r})'.format(
+            tp=get_type_name(PixelFormatGrey),
+            bpp=self.bpp,
+        )
 
 cdef class PixelFormatPalette(PixelFormat):
 
@@ -1860,14 +1873,14 @@ cdef class PixelFormatPalette(PixelFormat):
     def __repr__(self):
         cdef int i
         io = StringIO()
-        io.write('%s({' % (get_type_name(PixelFormatPalette),))
+        io.write(get_type_name(PixelFormatPalette) + '({')
         for i from 0 <= i < 6:
             for j from 0 <= j < 6:
                 for k from 0 <= k < 6:
-                    io.write('(%d, %d, %d): 0x%02x' % (i, j, k, self._palette[i * 6 * 6 + j * 6 + k]))
+                    io.write('({i}, {j}, {k}): 0x{v:02x}'.format(i=i, j=j, k=k, v=self._palette[i * 6 * 6 + j * 6 + k]))
                     if not (i == j == k == 5):
                         io.write(', ')
-        io.write('}, bpp = %d)' % self.bpp)
+        io.write('}}, bpp = {bpp})'.format(bpp=self.bpp))
         return io.getvalue()
 
 cdef class PixelFormatPackedBits(PixelFormat):
@@ -1908,7 +1921,10 @@ cdef class PixelFormatPackedBits(PixelFormat):
                 return '>'
 
     def __repr__(self):
-        return '%s(%r)' % (get_type_name(PixelFormatPackedBits), self.endianness)
+        return '{tp}({end!r})'.format(
+            tp=get_type_name(PixelFormatPackedBits),
+            end=self.endianness,
+        )
 
 cdef object calculate_row_size(long width, long row_alignment, int bpp):
     cdef long result
@@ -1930,7 +1946,7 @@ cdef object allocate_image_memory(long width, long height, object buffer, void *
     try:
         c_requested_size = py_requested_size
     except OverflowError:
-        raise MemoryError('Unable to allocate %d bytes for an image memory' % py_requested_size)
+        raise MemoryError('Unable to allocate {0} bytes for an image memory'.format(py_requested_size))
     if buffer is None:
         result = charp_to_bytes(NULL, c_requested_size)
         memory[0] = <char*> result
@@ -1938,7 +1954,7 @@ cdef object allocate_image_memory(long width, long height, object buffer, void *
         result = buffer
         buffer_to_writable_memory(buffer, memory, &c_memory_size)
         if c_memory_size < c_requested_size:
-            raise ValueError('Image buffer is too small (%d > %d)' % (c_requested_size, c_memory_size))
+            raise ValueError('Image buffer is too small ({0} > {1})'.format(c_requested_size, c_memory_size))
     return result
 
 
@@ -2529,7 +2545,11 @@ cdef class ErrorMessage(Message):
             return self.message
 
     def __repr__(self):
-        return '<%s: %r at %r>' % (get_type_name(ErrorMessage), self.message, self.location)
+        return '<{tp}: {msg!r} at {loc!r}>'.format(
+            tp=get_type_name(ErrorMessage),
+            msg=self.message,
+            loc=self.location,
+        )
 
 cdef class InfoMessage(Message):
     '''
@@ -2762,8 +2782,7 @@ cdef class ProgressMessage(Message):
             return JobException_from_c(self._status)
 
 cdef object MESSAGE_MAP
-MESSAGE_MAP = \
-{
+MESSAGE_MAP = {
     DDJVU_ERROR: ErrorMessage,
     DDJVU_INFO: InfoMessage,
     DDJVU_NEWSTREAM: NewStreamMessage,
@@ -2848,8 +2867,7 @@ class JobStopped(JobFailed):
     Operation was interrupted by user.
     '''
 
-JOB_EXCEPTION_MAP = \
-{
+JOB_EXCEPTION_MAP = {
     DDJVU_JOB_NOTSTARTED: JobNotStarted,
     DDJVU_JOB_STARTED: JobStarted,
     DDJVU_JOB_OK: JobOK,
@@ -2938,7 +2956,10 @@ cdef class DocumentOutline(DocumentExtension):
                 raise _NotAvailable_
 
     def __repr__(self):
-        return '%s(%r)' % (get_type_name(DocumentOutline), self._document)
+        return '{tp}({doc!r})'.format(
+            tp=get_type_name(DocumentOutline),
+            doc=self._document,
+        )
 
 cdef class Annotations:
     '''
@@ -3399,6 +3420,6 @@ IF PY3K:
     __version__ = decode_utf8(PYTHON_DJVULIBRE_VERSION)
 ELSE:
     __version__ = PYTHON_DJVULIBRE_VERSION
-__version__ = '%s/%d' % (__version__, DDJVU_VERSION)
+__version__ = '{0}/{1}'.format(__version__, DDJVU_VERSION)
 
-# vim:ts=4 sw=4 et ft=pyrex
+# vim:ts=4 sts=4 sw=4 et ft=pyrex
diff --git a/djvu/dllpath.py b/djvu/dllpath.py
index bb97076..5e6d252 100644
--- a/djvu/dllpath.py
+++ b/djvu/dllpath.py
@@ -53,4 +53,4 @@ def set_dll_search_path(path=None):
 
 del os
 
-# vim:ts=4 sw=4 et
+# vim:ts=4 sts=4 sw=4 et
diff --git a/djvu/sexpr.pxd b/djvu/sexpr.pxd
index 35f3397..78afdc6 100644
--- a/djvu/sexpr.pxd
+++ b/djvu/sexpr.pxd
@@ -1,4 +1,4 @@
-# Copyright © 2007, 2008, 2009 Jakub Wilk <jwilk at jwilk.net>
+# Copyright © 2007-2015 Jakub Wilk <jwilk at jwilk.net>
 #
 # This package is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -19,10 +19,10 @@ cdef extern from 'libdjvu/miniexp.h':
 cdef class _WrappedCExpr:
     cdef cvar_t* cvar
     cdef cexpr_t cexpr(self)
-    cdef object print_into(self, object, object)
-    cdef object as_string(self, object)
+    cdef object print_into(self, object, object, int)
+    cdef object as_string(self, object, int)
 
 cdef object public_c2py(cexpr_t)
 cdef _WrappedCExpr public_py2c(object)
 
-# vim:ts=4 sw=4 et ft=pyrex
+# vim:ts=4 sts=4 sw=4 et ft=pyrex
diff --git a/djvu/sexpr.pyx b/djvu/sexpr.pyx
index 8ff4c96..060bc54 100644
--- a/djvu/sexpr.pyx
+++ b/djvu/sexpr.pyx
@@ -1,4 +1,4 @@
-# Copyright © 2007-2014 Jakub Wilk <jwilk at jwilk.net>
+# Copyright © 2007-2015 Jakub Wilk <jwilk at jwilk.net>
 #
 # This package is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -97,9 +97,11 @@ cdef int (*_backup_io_ungetc)(int c)
 
 cdef object write_unraisable_exception(object cause):
     message = format_exc()
-    sys.stderr.write('Unhandled exception (%r)\n%s\n' % (cause, message))
+    sys.stderr.write(
+        'Unhandled exception ({obj!r})\n{msg}\n'.format(obj=cause, msg=message)
+    )
 
-cdef void myio_set(stdin, stdout):
+cdef void myio_set(object stdin, object stdout, int escape_unicode=True):
     global _myio_stdin, _myio_stdout, _myio_stdout_binary, _myio_buffer
     global _backup_io_7bit, _backup_io_puts, _backup_io_getc, _backup_io_ungetc
     global io_7bit, io_puts, io_getc, io_ungetc
@@ -120,7 +122,7 @@ cdef void myio_set(stdin, stdout):
         IF not PY3K:
             io_set_input(file_to_cfile(stdin))
         ELSE:
-            pass # TODO
+            pass  # TODO
     else:
         io_getc = _myio_getc
         io_ungetc = _myio_ungetc
@@ -133,10 +135,10 @@ cdef void myio_set(stdin, stdout):
         IF not PY3K:
             io_set_output(file_to_cfile(stdout))
         ELSE:
-            pass # TODO
+            pass  # TODO
     else:
         io_puts = _myio_puts
-    io_7bit = 1
+    io_7bit = escape_unicode
     _myio_buffer = []
 
 cdef void myio_reset():
@@ -201,7 +203,7 @@ cdef class _WrappedCExpr:
     cdef cexpr_t cexpr(self):
         return cvar_ptr(self.cvar)[0]
 
-    cdef object print_into(self, object stdout, object width):
+    cdef object print_into(self, object stdout, object width, int escape_unicode):
         cdef cexpr_t cexpr
         if width is None:
             pass
@@ -210,7 +212,7 @@ cdef class _WrappedCExpr:
         elif width <= 0:
             raise ValueError('width <= 0')
         cexpr = self.cexpr()
-        myio_set(None, stdout)
+        myio_set(None, stdout, escape_unicode)
         try:
             if width is None:
                 cexpr_print(cexpr)
@@ -219,10 +221,10 @@ cdef class _WrappedCExpr:
         finally:
             myio_reset()
 
-    cdef object as_string(self, object width):
+    cdef object as_string(self, object width, int escape_unicode):
         stdout = StringIO()
         try:
-            self.print_into(stdout, width)
+            self.print_into(stdout, width, escape_unicode)
             return stdout.getvalue()
         finally:
             stdout.close()
@@ -238,10 +240,10 @@ cdef _WrappedCExpr wexpr(cexpr_t cexpr):
 
 cdef class _MissingCExpr(_WrappedCExpr):
 
-    cdef object print_into(self, object stdout, object width):
+    cdef object print_into(self, object stdout, object width, int escape_unicode):
         raise NotImplementedError
 
-    cdef object as_string(self, object width):
+    cdef object as_string(self, object width, int escape_unicode):
         raise NotImplementedError
 
 cdef _MissingCExpr wexpr_missing():
@@ -266,7 +268,7 @@ cdef class BaseSymbol:
                 string = self._bytes
         ELSE:
             string = self._bytes
-        return '%s(%r)' % (get_type_name(_Symbol_), string)
+        return '{tp}({s!r})'.format(tp=get_type_name(_Symbol_), s=string)
 
     def __richcmp__(self, object other, int op):
         cdef BaseSymbol _self, _other
@@ -274,9 +276,7 @@ cdef class BaseSymbol:
             return NotImplemented
         _self = self
         _other = other
-        if op == 2 or op == 3:
-            return richcmp(_self._bytes, _other._bytes, op)
-        return NotImplemented
+        return richcmp(_self._bytes, _other._bytes, op)
 
     def __hash__(self):
         return hash(self._bytes)
@@ -432,40 +432,52 @@ cdef class BaseExpression:
     def __cinit__(self, *args, **kwargs):
         self.wexpr = wexpr_missing()
 
-    def print_into(self, stdout, width=None):
+    def print_into(self, stdout, width=None, escape_unicode=True):
         '''
-        expr.print_into(file[, width]) -> None
+        expr.print_into(file, width=None, escape_unicode=True) -> None
 
         Print the expression into the file.
         '''
-        self.wexpr.print_into(stdout, width)
+        self.wexpr.print_into(stdout, width, escape_unicode)
 
-    def as_string(self, width=None):
+    def as_string(self, width=None, escape_unicode=True):
         '''
-        expr.as_string([width]) -> a string
+        expr.as_string(width=None, escape_unicode=True) -> a string
 
         Return a string representation of the expression.
         '''
-        return self.wexpr.as_string(width)
+        return self.wexpr.as_string(width, escape_unicode)
 
     def __str__(self):
         return self.as_string()
 
     property value:
         '''
-        The actual "pythonic" value of the expression.
+        The "pythonic" value of the expression.
+        Lisp lists as mapped to Python tuples.
         '''
         def __get__(self):
             return self._get_value()
 
+    property lvalue:
+        '''
+        The "pythonic" value of the expression.
+        Lisp lists as mapped to Python lists.
+        '''
+        def __get__(self):
+            return self._get_lvalue()
+
     def _get_value(self):
+        return self._get_lvalue()
+
+    def _get_lvalue(self):
         raise NotImplementedError
 
     def __richcmp__(self, other, int op):
         return BaseExpression_richcmp(self, other, op)
 
     def __repr__(self):
-        return '%s(%r)' % (get_type_name(_Expression_), self.value)
+        return '{tp}({expr!r})'.format(tp=get_type_name(_Expression_), expr=self.lvalue)
 
     def __copy__(self):
         # Most of S-expressions are immutable.
@@ -520,7 +532,7 @@ class IntExpression(_Expression_):
     def __long__(self):
         return 0L + self.value
 
-    def _get_value(BaseExpression self not None):
+    def _get_lvalue(BaseExpression self not None):
         return cexpr_to_int(self.wexpr.cexpr())
 
     def __richcmp__(self, other, int op):
@@ -554,7 +566,7 @@ class SymbolExpression(_Expression_):
 
     __new__ = staticmethod(SymbolExpression__new__)
 
-    def _get_value(BaseExpression self not None):
+    def _get_lvalue(BaseExpression self not None):
         return _Symbol_(cexpr_to_symbol(self.wexpr.cexpr()))
 
     def __richcmp__(self, other, int op):
@@ -574,7 +586,7 @@ def StringExpression__new__(cls, value):
     if typecheck(value, _WrappedCExpr):
         self.wexpr = value
     elif is_bytes(value):
-        gc_lock(NULL) # protect from collecting a just-created object
+        gc_lock(NULL)  # protect from collecting a just-created object
         try:
             self.wexpr = wexpr(str_to_cexpr(value))
         finally:
@@ -593,7 +605,7 @@ class StringExpression(_Expression_):
         return cexpr_to_str(self.wexpr.cexpr())
     bytes = property(bytes)
 
-    def _get_value(BaseExpression self not None):
+    def _get_lvalue(BaseExpression self not None):
         cdef char *bytes
         bytes = cexpr_to_str(self.wexpr.cexpr())
         IF PY3K:
@@ -609,7 +621,7 @@ class StringExpression(_Expression_):
                 string = decode_utf8(bytes)
             except UnicodeDecodeError:
                 string = bytes
-            return '%s(%r)' % (get_type_name(_Expression_), string)
+            return '{tp}({s!r})'.format(tp=get_type_name(_Expression_), s=string)
 
     def __richcmp__(self, other, int op):
         return BaseExpression_richcmp(self, other, op)
@@ -657,7 +669,7 @@ cdef BaseExpression _c2py(cexpr_t cexpr):
 cdef _WrappedCExpr _build_list_cexpr(object items):
     cdef cexpr_t cexpr
     cdef BaseExpression citem
-    gc_lock(NULL) # protect from collecting a just-created object
+    gc_lock(NULL)  # protect from collecting a just-created object
     try:
         cexpr = cexpr_nil
         for item in items:
@@ -826,7 +838,7 @@ class ListExpression(_Expression_):
         if citem is None:
             raise TypeError
         if index == 0 or cexpr == cexpr_nil:
-            gc_lock(NULL) # protect from collecting a just-created object
+            gc_lock(NULL)  # protect from collecting a just-created object
             try:
                 new_cexpr = pair_to_cexpr(citem.wexpr.cexpr(), cexpr)
                 self.wexpr = wexpr(new_cexpr)
@@ -839,7 +851,7 @@ class ListExpression(_Expression_):
                 index = index - 1
                 cexpr = cexpr_tail(cexpr)
             else:
-                gc_lock(NULL) # protect from collecting a just-created object
+                gc_lock(NULL)  # protect from collecting a just-created object
                 try:
                     new_cexpr = pair_to_cexpr(citem.wexpr.cexpr(), cexpr_tail(cexpr))
                     cexpr_replace_tail(cexpr, new_cexpr)
@@ -852,7 +864,7 @@ class ListExpression(_Expression_):
 
     def reverse(BaseExpression self not None):
         cdef cexpr_t cexpr, new_cexpr
-        gc_lock(NULL) # protect from collecting a just-created object
+        gc_lock(NULL)  # protect from collecting a just-created object
         try:
             new_cexpr = cexpr_reverse_list(self.wexpr.cexpr())
             self.wexpr = wexpr(new_cexpr)
@@ -918,10 +930,7 @@ class ListExpression(_Expression_):
     def __iter__(self):
         return _ListExpressionIterator(self)
 
-    # TODO: Once we don't support Python <2.6, this can be replaced by simpler:
-    # __hash__ = None
-    def __hash__(self):
-        raise TypeError('unhashable type: \'%s\'' % (get_type_name(type(self)),))
+    __hash__ = None
 
     def _get_value(BaseExpression self not None):
         cdef cexpr_t current
@@ -932,18 +941,24 @@ class ListExpression(_Expression_):
             current = cexpr_tail(current)
         return tuple(result)
 
+    def _get_lvalue(BaseExpression self not None):
+        cdef cexpr_t current
+        current = self.wexpr.cexpr()
+        result = []
+        while current != cexpr_nil:
+            list_append(result, _c2py(cexpr_head(current))._get_lvalue())
+            current = cexpr_tail(current)
+        return result
+
     def __copy__(self):
         return _Expression_(self)
 
     def __deepcopy__(self, memo):
         return _Expression_(self._get_value())
 
-del ListExpression__new__
-
-if sys.version_info >= (2, 6):
-    import collections
-    collections.MutableSequence.register(ListExpression)
-    del collections
+import collections
+collections.MutableSequence.register(ListExpression)
+del collections
 
 cdef class _ListExpressionIterator:
 
@@ -974,4 +989,4 @@ IF PY3K:
 ELSE:
     __version__ = PYTHON_DJVULIBRE_VERSION
 
-# vim:ts=4 sw=4 et ft=pyrex
+# vim:ts=4 sts=4 sw=4 et ft=pyrex
diff --git a/COPYING b/doc/COPYING
similarity index 100%
rename from COPYING
rename to doc/COPYING
diff --git a/doc/source/annotations.txt b/doc/api/annotations.rst
similarity index 76%
rename from doc/source/annotations.txt
rename to doc/api/annotations.rst
index 77b7500..37e0d1a 100644
--- a/doc/source/annotations.txt
+++ b/doc/api/annotations.rst
@@ -1,5 +1,11 @@
 Annotations
 ===========
+
+.. testsetup::
+
+   from djvu.decode import *
+   from djvu.const import *
+
 .. seealso::
 
    - |djvu3ref|_: 8.3.4 *Annotation Chunk*;
@@ -126,57 +132,57 @@ The following symbols are pre-defined:
 
    .. data:: MAPAREA_BORDER_XOR
 
-		>>> MAPAREA_BORDER_XOR
-		Symbol('xor')
+      >>> MAPAREA_BORDER_XOR
+      Symbol('xor')
 
    .. data:: MAPAREA_BORDER_SOLID_COLOR
 
-		>>> MAPAREA_BORDER_SOLID_COLOR
-		Symbol('border')
+      >>> MAPAREA_BORDER_SOLID_COLOR
+      Symbol('border')
 
    .. data:: MAPAREA_BORDER_SHADOW_IN
 
-		>>> MAPAREA_BORDER_SHADOW_IN
-		Symbol('shadow_in')
+      >>> MAPAREA_BORDER_SHADOW_IN
+      Symbol('shadow_in')
 
    .. data:: MAPAREA_BORDER_SHADOW_OUT
 
-		>>> MAPAREA_BORDER_SHADOW_OUT
-		Symbol('shadow_out')
+      >>> MAPAREA_BORDER_SHADOW_OUT
+      Symbol('shadow_out')
 
    .. data:: MAPAREA_BORDER_ETCHED_IN
 
-		>>> MAPAREA_BORDER_ETCHED_IN
-		Symbol('shadow_ein')
+      >>> MAPAREA_BORDER_ETCHED_IN
+      Symbol('shadow_ein')
 
    .. data:: MAPAREA_BORDER_ETCHED_OUT
 
-		>>> MAPAREA_BORDER_ETCHED_OUT
-		Symbol('shadow_eout')
+      >>> MAPAREA_BORDER_ETCHED_OUT
+      Symbol('shadow_eout')
 
    .. data:: MAPAREA_SHADOW_BORDERS
 
       A sequence of all shadow border types.
 
-		>>> MAPAREA_SHADOW_BORDERS
-		(Symbol('shadow_in'), Symbol('shadow_out'), Symbol('shadow_ein'), Symbol('shadow_eout'))
+      >>> MAPAREA_SHADOW_BORDERS
+      (Symbol('shadow_in'), Symbol('shadow_out'), Symbol('shadow_ein'), Symbol('shadow_eout'))
 
    .. data:: MAPAREA_BORDER_ALWAYS_VISIBLE
 
-		>>> MAPAREA_BORDER_ALWAYS_VISIBLE
-		Symbol('border_avis')
+      >>> MAPAREA_BORDER_ALWAYS_VISIBLE
+      Symbol('border_avis')
 
 The following numeric constant are pre-defined:
 
    .. data:: MAPAREA_SHADOW_BORDER_MIN_WIDTH
 
-		>>> MAPAREA_SHADOW_BORDER_MIN_WIDTH
-		1
+      >>> MAPAREA_SHADOW_BORDER_MIN_WIDTH
+      1
 
    .. data:: MAPAREA_SHADOW_BORDER_MAX_WIDTH
 
-		>>> MAPAREA_SHADOW_BORDER_MAX_WIDTH
-		32
+      >>> MAPAREA_SHADOW_BORDER_MAX_WIDTH
+      32
 
 
 Highlight color and opacity
@@ -190,13 +196,13 @@ The following symbols are pre-defined:
 
    .. data:: MAPAREA_HIGHLIGHT_COLOR
 
-		>>> MAPAREA_HIGHLIGHT_COLOR
-		Symbol('hilite')
+      >>> MAPAREA_HIGHLIGHT_COLOR
+      Symbol('hilite')
... 2340 lines suppressed ...

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-djvulibre.git



More information about the Python-modules-commits mailing list