[Python-modules-commits] [python-djvulibre] 01/05: Imported Upstream version 0.7
Daniel Stender
danstender-guest at moszumanska.debian.org
Fri Sep 4 19:49:40 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 50f1f62d44db59214083bdc890e6cfac972fd0b8
Author: Daniel Stender <debian at danielstender.com>
Date: Fri Sep 4 19:55:42 2015 +0200
Imported Upstream version 0.7
---
MANIFEST.in | 3 +-
PKG-INFO | 2 +-
djvu/__init__.py | 16 +-
djvu/common.pxi | 23 +-
djvu/const.py | 142 ++++++++---
djvu/decode.pxd | 37 ++-
djvu/decode.pyx | 118 +++------
djvu/dllpath.py | 16 +-
djvu/sexpr.pxd | 20 +-
djvu/sexpr.pyx | 345 ++++++++++++-------------
doc/api/annotations.rst | 2 +-
doc/api/conf.py | 13 +
doc/api/documents.rst | 8 -
doc/api/exceptions.rst | 5 -
doc/build-reqs.txt | 19 ++
doc/changelog | 44 ++++
doc/todo.txt | 18 ++
examples/djvu-crop-text | 16 +-
examples/djvu-dump-text | 16 +-
examples/djvu2png | 16 +-
private/build-and-test | 48 ++++
private/mingw32-setup-env | 71 ++++++
python_djvulibre.egg-info/PKG-INFO | 2 +-
python_djvulibre.egg-info/SOURCES.txt | 7 +-
setup.py | 135 +++++-----
tests/images/Makefile | 19 +-
tests/images/test0-image.jpeg | Bin 18069 -> 0 bytes
tests/images/test0.djvu | Bin 29187 -> 3955 bytes
tests/images/test0.tex | 80 ++----
tests/sexpr-gc.py | 16 +-
tests/test_const.py | 114 ++++++++-
tests/test_decode.py | 463 +++++++++++++++++++++++++---------
tests/test_sexpr.py | 263 ++++++++++++++-----
tests/{common.py => tools.py} | 73 +++---
34 files changed, 1417 insertions(+), 753 deletions(-)
diff --git a/MANIFEST.in b/MANIFEST.in
index ff7776d..b59516c 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -9,6 +9,7 @@ include doc/api/conf.py
include examples/*
recursive-include djvu *.py *.pxi *.pxd *.pyx
-recursive-exclude djvu config.pxi
recursive-include tests *.py Makefile *.jpeg *.tex *.djvu
+
+include private/*
diff --git a/PKG-INFO b/PKG-INFO
index 62cb069..123cb9a 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: python-djvulibre
-Version: 0.5
+Version: 0.7
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 139d524..3c89343 100644
--- a/djvu/__init__.py
+++ b/djvu/__init__.py
@@ -2,14 +2,16 @@
# 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 file is part of python-djvulibre.
#
-# 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.
+# python-djvulibre is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 as published by
+# the Free Software Foundation.
+#
+# python-djvulibre 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
diff --git a/djvu/common.pxi b/djvu/common.pxi
index 936ae67..3be92d2 100644
--- a/djvu/common.pxi
+++ b/djvu/common.pxi
@@ -1,13 +1,15 @@
# 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
-# the Free Software Foundation; version 2 dated June, 1991.
+# This file is part of python-djvulibre.
#
-# 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.
+# python-djvulibre is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 as published by
+# the Free Software Foundation.
+#
+# python-djvulibre 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.
include 'config.pxi'
@@ -39,6 +41,7 @@ IF PY3K:
from cpython cimport PyNumber_Long as int
ELSE:
from cpython cimport PyNumber_Int as int
+ from cpython cimport PyNumber_Long as long
# Python strings:
@@ -60,7 +63,7 @@ IF PY3K:
ELSE:
from cpython cimport PyString_FromString as charp_to_string
-cdef object decode_utf8(char* s):
+cdef object decode_utf8(const char *s):
return decode_utf8_ex(s, strlen(s), NULL)
cdef extern from 'Python.h':
@@ -107,7 +110,7 @@ from cpython cimport (
cdef extern from 'object.h':
ctypedef struct PyTypeObject:
- char *tp_name
+ const char *tp_name
from cpython cimport PyObject
from cpython cimport PyObject_TypeCheck as _typecheck
@@ -119,7 +122,7 @@ IF PY3K:
cdef object get_type_name(object type):
return decode_utf8((<PyTypeObject*>type).tp_name)
ELSE:
- cdef char* get_type_name(object type):
+ cdef const char* get_type_name(object type):
return (<PyTypeObject*>type).tp_name
cdef int typecheck(object o, object type):
diff --git a/djvu/const.py b/djvu/const.py
index d4e08d8..24cea2f 100644
--- a/djvu/const.py
+++ b/djvu/const.py
@@ -1,15 +1,17 @@
# encoding=UTF-8
-# Copyright © 2008-2010 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
-# the Free Software Foundation; version 2 dated June, 1991.
+# This file is part of python-djvulibre.
#
-# 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.
+# python-djvulibre is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 as published by
+# the Free Software Foundation.
+#
+# python-djvulibre 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.
'''DjVuLibre bindings: various constants.'''
@@ -43,7 +45,7 @@ title
type
volume
year'''.split())
-# Retrieved from <http://www.ctan.org/get/biblio/bibtex/contrib/doc/btxdoc.pdf>
+# Retrieved from <https://www.ctan.org/pkg/bibtex>
METADATA_PDFINFO_KEYS = frozenset(djvu.sexpr.Symbol(x) for x in '''
Author
@@ -104,7 +106,7 @@ class TextZoneType(djvu.sexpr.Symbol):
def __repr__(self):
return '<{mod}.{cls}: {name}>'.format(
mod=self.__module__,
- cls=self.__class__.__name__,
+ cls=type(self).__name__,
name=self
)
@@ -120,36 +122,36 @@ 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_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_LINE: '\n', # Line Feed (LF)
+ TEXT_ZONE_WORD: ' ', # space
TEXT_ZONE_CHARACTER: ''
}
# 8.3.4.2 Maparea (overprinted annotations)
-ANNOTATION_MAPAREA = djvu.sexpr.Symbol('maparea')
+ANNOTATION_MAPAREA = djvu.sexpr.Symbol('maparea')
# 8.3.4.2 Maparea (overprinted annotations):
MAPAREA_SHAPE_RECTANGLE = djvu.sexpr.Symbol('rect')
-MAPAREA_SHAPE_OVAL = djvu.sexpr.Symbol('oval')
-MAPAREA_SHAPE_POLYGON = djvu.sexpr.Symbol('poly')
-MAPAREA_SHAPE_LINE = djvu.sexpr.Symbol('line')
-MAPAREA_SHAPE_TEXT = djvu.sexpr.Symbol('text')
+MAPAREA_SHAPE_OVAL = djvu.sexpr.Symbol('oval')
+MAPAREA_SHAPE_POLYGON = djvu.sexpr.Symbol('poly')
+MAPAREA_SHAPE_LINE = djvu.sexpr.Symbol('line')
+MAPAREA_SHAPE_TEXT = djvu.sexpr.Symbol('text')
MAPAREA_URI = MAPAREA_URL = djvu.sexpr.Symbol('url')
# 8.3.4.2.3.1.1 Border type:
-MAPAREA_BORDER_NONE = djvu.sexpr.Symbol('none')
-MAPAREA_BORDER_XOR = djvu.sexpr.Symbol('xor')
+MAPAREA_BORDER_NONE = djvu.sexpr.Symbol('none')
+MAPAREA_BORDER_XOR = djvu.sexpr.Symbol('xor')
MAPAREA_BORDER_SOLID_COLOR = djvu.sexpr.Symbol('border')
# 8.3.4.2.3.1.1 Border type:
-MAPAREA_BORDER_SHADOW_IN = djvu.sexpr.Symbol('shadow_in')
+MAPAREA_BORDER_SHADOW_IN = djvu.sexpr.Symbol('shadow_in')
MAPAREA_BORDER_SHADOW_OUT = djvu.sexpr.Symbol('shadow_out')
-MAPAREA_BORDER_ETCHED_IN = djvu.sexpr.Symbol('shadow_ein')
+MAPAREA_BORDER_ETCHED_IN = djvu.sexpr.Symbol('shadow_ein')
MAPAREA_BORDER_ETCHED_OUT = djvu.sexpr.Symbol('shadow_eout')
MAPAREA_SHADOW_BORDERS = (MAPAREA_BORDER_SHADOW_IN, MAPAREA_BORDER_SHADOW_OUT, MAPAREA_BORDER_ETCHED_IN, MAPAREA_BORDER_ETCHED_OUT)
MAPAREA_SHADOW_BORDER_MIN_WIDTH = 1
@@ -160,38 +162,102 @@ MAPAREA_BORDER_ALWAYS_VISIBLE = djvu.sexpr.Symbol('border_avis')
# 8.3.4.2.3.1.3 Highlight color and opacity:
MAPAREA_HIGHLIGHT_COLOR = djvu.sexpr.Symbol('hilite')
-MAPAREA_OPACITY = djvu.sexpr.Symbol('opacity')
-MAPAREA_OPACITY_MIN = 0
+MAPAREA_OPACITY = djvu.sexpr.Symbol('opacity')
+MAPAREA_OPACITY_MIN = 0
MAPAREA_OPACITY_DEFAULT = 50
-MAPAREA_OPACITY_MAX = 100
+MAPAREA_OPACITY_MAX = 100
# 8.3.4.2.3.1.4 Line and Text parameters:
-MAPAREA_ARROW = djvu.sexpr.Symbol('arrow')
-MAPAREA_LINE_WIDTH = djvu.sexpr.Symbol('width')
-MAPAREA_LINE_COLOR = djvu.sexpr.Symbol('lineclr')
+MAPAREA_ARROW = djvu.sexpr.Symbol('arrow')
+MAPAREA_LINE_WIDTH = djvu.sexpr.Symbol('width')
+MAPAREA_LINE_COLOR = djvu.sexpr.Symbol('lineclr')
MAPAREA_LINE_MIN_WIDTH = 1
MAPAREA_LINE_COLOR_DEFAULT = '#000000'
# 8.3.4.2.3.1.4 Line and Text parameters:
MAPAREA_BACKGROUND_COLOR = djvu.sexpr.Symbol('backclr')
-MAPAREA_TEXT_COLOR = djvu.sexpr.Symbol('textclr')
-MAPAREA_PUSHPIN = djvu.sexpr.Symbol('pushpin')
+MAPAREA_TEXT_COLOR = djvu.sexpr.Symbol('textclr')
+MAPAREA_PUSHPIN = djvu.sexpr.Symbol('pushpin')
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')
+ANNOTATION_METADATA = djvu.sexpr.Symbol('metadata')
# 8.3.4.3 Printed headers and footers:
ANNOTATION_PRINTED_HEADER = djvu.sexpr.Symbol('phead')
ANNOTATION_PRINTED_FOOTER = djvu.sexpr.Symbol('pfoot')
-PRINTER_HEADER_ALIGN_LEFT = PRINTED_FOOTER_ALIGN_LEFT = djvu.sexpr.Symbol('left')
+PRINTER_HEADER_ALIGN_LEFT = PRINTED_FOOTER_ALIGN_LEFT = djvu.sexpr.Symbol('left')
PRINTER_HEADER_ALIGN_CENTER = PRINTED_FOOTER_ALIGN_CENTER = djvu.sexpr.Symbol('center')
-PRINTER_HEADER_ALIGN_RIGHT = PRINTED_FOOTER_ALIGN_RIGHT = djvu.sexpr.Symbol('right')
+PRINTER_HEADER_ALIGN_RIGHT = PRINTED_FOOTER_ALIGN_RIGHT = djvu.sexpr.Symbol('right')
+
+__all__ = [
+ 'ANNOTATION_ALIGN',
+ 'ANNOTATION_BACKGROUND',
+ 'ANNOTATION_MAPAREA',
+ 'ANNOTATION_METADATA',
+ 'ANNOTATION_MODE',
+ 'ANNOTATION_PRINTED_FOOTER',
+ 'ANNOTATION_PRINTED_HEADER',
+ 'ANNOTATION_ZOOM',
+ 'EMPTY_LIST',
+ 'EMPTY_OUTLINE',
+ 'MAPAREA_ARROW',
+ 'MAPAREA_BACKGROUND_COLOR',
+ 'MAPAREA_BORDER_ALWAYS_VISIBLE',
+ 'MAPAREA_BORDER_ETCHED_IN',
+ 'MAPAREA_BORDER_ETCHED_OUT',
+ 'MAPAREA_BORDER_NONE',
+ 'MAPAREA_BORDER_SHADOW_IN',
+ 'MAPAREA_BORDER_SHADOW_OUT',
+ 'MAPAREA_BORDER_SOLID_COLOR',
+ 'MAPAREA_BORDER_XOR',
+ 'MAPAREA_HIGHLIGHT_COLOR',
+ 'MAPAREA_LINE_COLOR',
+ 'MAPAREA_LINE_COLOR_DEFAULT',
+ 'MAPAREA_LINE_MIN_WIDTH',
+ 'MAPAREA_LINE_WIDTH',
+ 'MAPAREA_OPACITY',
+ 'MAPAREA_OPACITY_DEFAULT',
+ 'MAPAREA_OPACITY_MAX',
+ 'MAPAREA_OPACITY_MIN',
+ 'MAPAREA_PUSHPIN',
+ 'MAPAREA_SHADOW_BORDERS',
+ 'MAPAREA_SHADOW_BORDER_MAX_WIDTH',
+ 'MAPAREA_SHADOW_BORDER_MIN_WIDTH',
+ 'MAPAREA_SHAPE_LINE',
+ 'MAPAREA_SHAPE_OVAL',
+ 'MAPAREA_SHAPE_POLYGON',
+ 'MAPAREA_SHAPE_RECTANGLE',
+ 'MAPAREA_SHAPE_TEXT',
+ 'MAPAREA_TEXT_COLOR',
+ 'MAPAREA_TEXT_COLOR_DEFAULT',
+ 'MAPAREA_URI',
+ 'MAPAREA_URL',
+ 'METADATA_BIBTEX_KEYS',
+ 'METADATA_KEYS',
+ 'METADATA_PDFINFO_KEYS',
+ 'PRINTED_FOOTER_ALIGN_CENTER',
+ 'PRINTED_FOOTER_ALIGN_LEFT',
+ 'PRINTED_FOOTER_ALIGN_RIGHT',
+ 'PRINTER_HEADER_ALIGN_CENTER',
+ 'PRINTER_HEADER_ALIGN_LEFT',
+ 'PRINTER_HEADER_ALIGN_RIGHT',
+ 'TEXT_ZONE_CHARACTER',
+ 'TEXT_ZONE_COLUMN',
+ 'TEXT_ZONE_LINE',
+ 'TEXT_ZONE_PAGE',
+ 'TEXT_ZONE_PARAGRAPH',
+ 'TEXT_ZONE_REGION',
+ 'TEXT_ZONE_SEPARATORS',
+ 'TEXT_ZONE_WORD',
+ 'TextZoneType',
+ 'get_text_zone_type'
+]
# vim:ts=4 sts=4 sw=4 et
diff --git a/djvu/decode.pxd b/djvu/decode.pxd
index 3d19773..bb6c0c9 100644
--- a/djvu/decode.pxd
+++ b/djvu/decode.pxd
@@ -1,13 +1,15 @@
-# Copyright © 2007-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
-# the Free Software Foundation; version 2 dated June, 1991.
+# This file is part of python-djvulibre.
#
-# 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.
+# python-djvulibre is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 as published by
+# the Free Software Foundation.
+#
+# python-djvulibre 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.
cdef extern from 'stdio.h':
ctypedef struct FILE
@@ -37,15 +39,14 @@ cdef extern from 'libdjvu/ddjvuapi.h':
ctypedef void (*ddjvu_message_callback_t)(ddjvu_context_t* context, void* closure) nogil
- cdef enum ddjvu_status_e:
+ ctypedef enum ddjvu_status_t:
DDJVU_JOB_NOTSTARTED
DDJVU_JOB_STARTED
DDJVU_JOB_OK
DDJVU_JOB_FAILED
DDJVU_JOB_STOPPED
- ctypedef ddjvu_status_e ddjvu_status_t
- cdef enum ddjvu_message_tag_t:
+ ctypedef enum ddjvu_message_tag_t:
DDJVU_ERROR
DDJVU_INFO
DDJVU_NEWSTREAM
@@ -85,7 +86,7 @@ cdef extern from 'libdjvu/ddjvuapi.h':
cdef struct ddjvu_message_docinfo_s:
ddjvu_message_any_t any
- cdef enum ddjvu_document_type_t:
+ ctypedef enum ddjvu_document_type_t:
DDJVU_DOCTYPE_UNKNOWN
DDJVU_DOCTYPE_SINGLEPAGE
DDJVU_DOCTYPE_BUNDLED
@@ -123,34 +124,31 @@ cdef extern from 'libdjvu/ddjvuapi.h':
ddjvu_message_any_t any
char* chunkid
- cdef enum ddjvu_page_type_s:
+ ctypedef enum ddjvu_page_type_t:
DDJVU_PAGETYPE_UNKNOWN
DDJVU_PAGETYPE_BITONAL
DDJVU_PAGETYPE_PHOTO
DDJVU_PAGETYPE_COMPOUND
- ctypedef ddjvu_page_type_s ddjvu_page_type_t
- cdef enum ddjvu_page_rotation_s:
+ ctypedef enum ddjvu_page_rotation_t:
DDJVU_ROTATE_0
DDJVU_ROTATE_90
DDJVU_ROTATE_180
DDJVU_ROTATE_270
- ctypedef ddjvu_page_rotation_s ddjvu_page_rotation_t
- cdef enum ddjvu_render_mode_s:
+ ctypedef enum ddjvu_render_mode_t:
DDJVU_RENDER_COLOR
DDJVU_RENDER_BLACK
DDJVU_RENDER_COLORONLY
DDJVU_RENDER_MASKONLY
DDJVU_RENDER_BACKGROUND
DDJVU_RENDER_FOREGROUND
- ctypedef int ddjvu_render_mode_t
cdef struct ddjvu_rect_s:
int x, y
unsigned int w, h
- cdef enum ddjvu_format_style_s:
+ ctypedef enum ddjvu_format_style_t:
DDJVU_FORMAT_BGR24
DDJVU_FORMAT_RGB24
DDJVU_FORMAT_RGBMASK16
@@ -159,7 +157,6 @@ cdef extern from 'libdjvu/ddjvuapi.h':
DDJVU_FORMAT_PALETTE8
DDJVU_FORMAT_MSBTOLSB
DDJVU_FORMAT_LSBTOMSB
- ctypedef int ddjvu_format_style_t
cdef struct ddjvu_message_thumbnail_s:
ddjvu_message_any_t any
diff --git a/djvu/decode.pyx b/djvu/decode.pyx
index bfe56e0..b34b506 100644
--- a/djvu/decode.pyx
+++ b/djvu/decode.pyx
@@ -1,13 +1,15 @@
-# 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
-# the Free Software Foundation; version 2 dated June, 1991.
+# This file is part of python-djvulibre.
#
-# 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.
+# python-djvulibre is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 as published by
+# the Free Software Foundation.
+#
+# python-djvulibre 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.
#cython: autotestdict=False
@@ -56,14 +58,6 @@ import sys
from os import devnull
from traceback import format_exc
-# The two lines below are solely to work-around Cython bug:
-# https://bugs.debian.org/620859
-cdef object MemoryError
-IF PY3K:
- from builtins import MemoryError
-ELSE:
- from exceptions import MemoryError
-
cdef object StringIO
IF PY3K:
from io import StringIO
@@ -86,7 +80,7 @@ _job_weak_loft = weakref.WeakValueDictionary()
loft_lock = allocate_lock()
cdef extern from 'libdjvu/ddjvuapi.h':
- ddjvu_context_t* ddjvu_context_create(char* program_name) nogil
+ ddjvu_context_t* ddjvu_context_create(const char *program_name) nogil
void ddjvu_context_release(ddjvu_context_t* context) nogil
void ddjvu_cache_set_size(ddjvu_context_t* context, unsigned long cachesize) nogil
@@ -107,8 +101,8 @@ cdef extern from 'libdjvu/ddjvuapi.h':
void* ddjvu_job_get_user_data(ddjvu_job_t* job) nogil
void ddjvu_job_release(ddjvu_job_t* job) nogil
- ddjvu_document_t* ddjvu_document_create(ddjvu_context_t* context, char* url, int cache) nogil
- ddjvu_document_t* ddjvu_document_create_by_filename(ddjvu_context_t* context, char* filename, int cache) nogil
+ ddjvu_document_t* ddjvu_document_create(ddjvu_context_t *context, const char *url, int cache) nogil
+ ddjvu_document_t* ddjvu_document_create_by_filename(ddjvu_context_t *context, const char *filename, int cache) nogil
ddjvu_job_t* ddjvu_document_job(ddjvu_document_t* document) nogil
void ddjvu_document_release(ddjvu_document_t* document) nogil
@@ -119,7 +113,7 @@ cdef extern from 'libdjvu/ddjvuapi.h':
int ddjvu_document_decoding_done(ddjvu_document_t* document) nogil
int ddjvu_document_decoding_error(ddjvu_document_t* document) nogil
- void ddjvu_stream_write(ddjvu_document_t* document, int streamid, char* data, unsigned long datalen) nogil
+ void ddjvu_stream_write(ddjvu_document_t* document, int streamid, const char *data, unsigned long datalen) nogil
void ddjvu_stream_close(ddjvu_document_t* document, int streamid, int stop) nogil
ddjvu_document_type_t ddjvu_document_get_type(ddjvu_document_t* document) nogil
@@ -158,7 +152,7 @@ cdef extern from 'libdjvu/ddjvuapi.h':
ddjvu_page_rotation_t ddjvu_page_get_rotation(ddjvu_page_t* page) nogil
ddjvu_page_rotation_t ddjvu_page_get_initial_rotation(ddjvu_page_t* page) nogil
- int ddjvu_page_render(ddjvu_page_t* page, ddjvu_render_mode_t mode, ddjvu_rect_t* pagerect, ddjvu_rect_t* renderrect, ddjvu_format_t* pixelformat, unsigned long rowsize, char* imagebuffer) nogil
+ int ddjvu_page_render(ddjvu_page_t *page, const ddjvu_render_mode_t mode, const ddjvu_rect_t *pagerect, const ddjvu_rect_t *renderrect, const ddjvu_format_t *pixelformat, unsigned long rowsize, char *imagebuffer) nogil
ddjvu_rectmapper_t* ddjvu_rectmapper_create(ddjvu_rect_t* input, ddjvu_rect_t* output) nogil
void ddjvu_rectmapper_modify(ddjvu_rectmapper_t* mapper, int rotation, int mirrorx, int mirrory) nogil
@@ -177,25 +171,25 @@ cdef extern from 'libdjvu/ddjvuapi.h':
ddjvu_status_t ddjvu_thumbnail_status(ddjvu_document_t* document, int pagenum, int start) nogil
- int ddjvu_thumbnail_render(ddjvu_document_t* document, int pagenum, int* wptr, int* hptr, ddjvu_format_t* pixelformat, unsigned long rowsize, char* imagebuffer) nogil
+ int ddjvu_thumbnail_render(ddjvu_document_t *document, int pagenum, int *wptr, int *hptr, const ddjvu_format_t *pixelformat, unsigned long rowsize, char *imagebuffer) nogil
- ddjvu_job_t* ddjvu_document_print(ddjvu_document_t* document, FILE* output, int optc, char** optv) nogil
- ddjvu_job_t* ddjvu_document_save(ddjvu_document_t* document, FILE* output, int optc, char** optv) nogil
+ ddjvu_job_t* ddjvu_document_print(ddjvu_document_t* document, FILE* output, int optc, const char * const *optv) nogil
+ ddjvu_job_t* ddjvu_document_save(ddjvu_document_t* document, FILE* output, int optc, const char * const *optv) nogil
void ddjvu_miniexp_release(ddjvu_document_t* document, cexpr_t expr) nogil
cexpr_t ddjvu_document_get_outline(ddjvu_document_t* document) nogil
cexpr_t ddjvu_document_get_anno(ddjvu_document_t* document, int compat) nogil
- cexpr_t ddjvu_document_get_pagetext(ddjvu_document_t* document, int pageno, char* maxdetail) nogil
+ cexpr_t ddjvu_document_get_pagetext(ddjvu_document_t* document, int pageno, const char *maxdetail) nogil
cexpr_t ddjvu_document_get_pageanno(ddjvu_document_t* document, int pageno) nogil
- char* ddjvu_anno_get_bgcolor(cexpr_t annotations) nogil
- char* ddjvu_anno_get_zoom(cexpr_t annotations) nogil
- char* ddjvu_anno_get_mode(cexpr_t annotations) nogil
- char* ddjvu_anno_get_horizalign(cexpr_t annotations) nogil
- char* ddjvu_anno_get_vertalign(cexpr_t annotations) nogil
+ const char * ddjvu_anno_get_bgcolor(cexpr_t annotations) nogil
+ const char * ddjvu_anno_get_zoom(cexpr_t annotations) nogil
+ const char * ddjvu_anno_get_mode(cexpr_t annotations) nogil
+ const char * ddjvu_anno_get_horizalign(cexpr_t annotations) nogil
+ const char * ddjvu_anno_get_vertalign(cexpr_t annotations) nogil
cexpr_t* ddjvu_anno_get_hyperlinks(cexpr_t annotations) nogil
cexpr_t* ddjvu_anno_get_metadata_keys(cexpr_t annotations) nogil
- char* ddjvu_anno_get_metadata(cexpr_t annotations, cexpr_t key) nogil
+ const char * ddjvu_anno_get_metadata(cexpr_t annotations, cexpr_t key) nogil
# Python files:
@@ -303,20 +297,6 @@ class NotAvailable(Exception):
cdef object _NotAvailable_
_NotAvailable_ = NotAvailable
-class DjVuLibreBug(Exception):
-
- '''
- A DjVuLibre bug was encountered.
- '''
-
- def __init__(self, debian_bug_no):
- Exception.__init__(
- self,
- 'A DjVuLibre bug has been encountered.\n'
- 'See <https://bugs.debian.org/{0}> for details.\n'
- 'Please upgrade your DjVuLibre.'.format(debian_bug_no)
- )
-
cdef class DocumentExtension:
property document:
@@ -1116,12 +1096,8 @@ cdef class Document:
pages argument specifies a subset of saved pages.
If wait is true, wait until the job is done.
-
- .. warning::
- Due to a DjVuLibre (<= 3.5.20) bug, this method may be broken.
- See https://bugs.debian.org/467282 for details.
'''
- cdef char * optv[2]
+ cdef const char * optv[2]
cdef int optc
cdef SaveJob job
optc = 0
@@ -1136,12 +1112,8 @@ cdef class Document:
raise TypeError('file must be None if indirect is specified')
if not is_string(indirect):
raise TypeError('indirect must be a string')
- # XXX ddjvu API documentation says that output should be NULL,
- # but we'd like to spot the DjVuLibre bug
- open(indirect, 'wb').close()
- file = open(devnull, 'wb')
- file_wrapper = _FileWrapper(file, <char*> "wb")
- output = file_wrapper.cfile
+ file_wrapper = None
+ output = NULL
s1 = '--indirect=' + indirect
if is_unicode(s1):
s1 = encode_utf8(s1)
@@ -1160,11 +1132,6 @@ cdef class Document:
release_lock(loft_lock)
if wait:
job.wait()
- if indirect is not None:
- file = open(indirect, 'rb')
- file.seek(0, 2)
- if file.tell() == 0:
- raise DjVuLibreBug(467282)
return job
def export_ps(self, file, pages=None, eps=0, level=None, orientation=PRINT_ORIENTATION_AUTO, mode=DDJVU_RENDER_COLOR, zoom=None, color=1, srgb=1, gamma=None, copies=1, frame=0, crop_marks=0, text=0, booklet=PRINT_BOOKLET_NO, booklet_max=0, booklet_align=0, booklet_fold=(18, 200), wait=1):
@@ -1271,11 +1238,6 @@ cdef class Document:
The default value is (18, 200).
.. [1] 1 pt = 1/72 in = 0.3528 mm
-
- **Warning***
- ------------
- Due to a DjVuLibre (<= 3.5.20) bug, this method may be broken.
- See https://bugs.debian.org/469122 for details.
'''
cdef FILE* output
cdef SaveJob job
@@ -1349,12 +1311,12 @@ cdef class Document:
except TypeError:
raise TypeError('booklet_fold must a be an integer or a pair of integers')
list_append(options, '--bookletfold={0}+{1}'.format(fold_base, fold_incr))
- cdef char **optv
+ cdef const char **optv
cdef int optc
cdef size_t buffer_size
optc = 0
buffer_size = len(options) * sizeof (char*)
- optv = <char**> py_malloc(buffer_size)
+ optv = <const char**> py_malloc(buffer_size)
if optv == NULL:
raise MemoryError('Unable to allocate {0} bytes for print options'.format(buffer_size))
try:
@@ -1753,7 +1715,7 @@ cdef class PixelFormatRgb(PixelFormat):
'''
def __cinit__(self, byte_order='RGB', unsigned int bpp=24):
- cdef unsigned int _format
+ cdef ddjvu_format_style_t _format
if byte_order == 'RGB':
self._rgb = 1
_format = DDJVU_FORMAT_RGB24
@@ -1804,7 +1766,7 @@ cdef class PixelFormatRgbMask(PixelFormat):
'''
def __cinit__(self, unsigned int red_mask, unsigned int green_mask, unsigned int blue_mask, unsigned int xor_value = 0, unsigned int bpp = 16):
- cdef unsigned int _format
+ cdef ddjvu_format_style_t _format
if bpp == 16:
_format = DDJVU_FORMAT_RGBMASK16
red_mask = red_mask & 0xffff
@@ -1908,7 +1870,7 @@ cdef class PixelFormatPackedBits(PixelFormat):
'''
def __cinit__(self, endianness):
- cdef int _format
+ cdef ddjvu_format_style_t _format
if endianness == '<':
self._little_endian = 1
_format = DDJVU_FORMAT_LSBTOMSB
@@ -2127,7 +2089,7 @@ cdef class PageJob(Job):
def __del__(self):
ddjvu_page_set_rotation(<ddjvu_page_t*> self.ddjvu_job, ddjvu_page_get_initial_rotation(<ddjvu_page_t*> self.ddjvu_job))
- def render(self, int mode, page_rect, render_rect, PixelFormat pixel_format not None, long row_alignment=1, buffer=None):
+ def render(self, ddjvu_render_mode_t mode, page_rect, render_rect, PixelFormat pixel_format not None, long row_alignment=1, buffer=None):
'''
J.render(mode, page_rect, render_rect, pixel_format, row_alignment=1, buffer=None) -> data
@@ -3039,7 +3001,7 @@ cdef class Annotations:
Return None if this information is not specified.
'''
def __get__(self):
- cdef char* result
+ cdef const char *result
result = ddjvu_anno_get_bgcolor(self._sexpr._cexpr)
if result == NULL:
return
@@ -3053,7 +3015,7 @@ cdef class Annotations:
Return None if this information is not specified.
'''
def __get__(self):
- cdef char* result
+ cdef const char *result
result = ddjvu_anno_get_zoom(self._sexpr._cexpr)
if result == NULL:
return
@@ -3067,7 +3029,7 @@ cdef class Annotations:
Return zero if this information is not specified.
'''
def __get__(self):
- cdef char* result
+ cdef const char *result
result = ddjvu_anno_get_mode(self._sexpr._cexpr)
if result == NULL:
return
@@ -3081,7 +3043,7 @@ cdef class Annotations:
Return None if this information is not specified.
'''
def __get__(self):
- cdef char* result
+ cdef const char *result
result = ddjvu_anno_get_horizalign(self._sexpr._cexpr)
if result == NULL:
return
@@ -3095,7 +3057,7 @@ cdef class Annotations:
Return None if this information is not specified.
'''
def __get__(self):
- cdef char* result
+ cdef const char *result
result = ddjvu_anno_get_vertalign(self._sexpr._cexpr)
if result == NULL:
return
@@ -3369,7 +3331,7 @@ cdef class Metadata:
def __getitem__(self, key):
cdef _WrappedCExpr cexpr_key
- cdef char *s
+ cdef const char *s
cexpr_key = py2cexpr(Symbol(key))
s = ddjvu_anno_get_metadata(self._annotations._sexpr._cexpr, cexpr_key.cexpr())
if s == NULL:
diff --git a/djvu/dllpath.py b/djvu/dllpath.py
index 5e6d252..bd4a30f 100644
--- a/djvu/dllpath.py
+++ b/djvu/dllpath.py
@@ -2,14 +2,16 @@
# Copyright © 2011 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 file is part of python-djvulibre.
#
-# 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.
+# python-djvulibre is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 as published by
+# the Free Software Foundation.
+#
+# python-djvulibre 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.
'''
Module aimed to ease finding DjVuLibre DLLs in non-standard locations.
diff --git a/djvu/sexpr.pxd b/djvu/sexpr.pxd
index 78afdc6..e2c6056 100644
--- a/djvu/sexpr.pxd
+++ b/djvu/sexpr.pxd
@@ -1,13 +1,15 @@
# 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
-# the Free Software Foundation; version 2 dated June, 1991.
+# This file is part of python-djvulibre.
#
-# 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.
+# python-djvulibre is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 as published by
+# the Free Software Foundation.
+#
+# python-djvulibre 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.
cdef extern from 'libdjvu/miniexp.h':
struct cexpr_s 'miniexp_s'
@@ -19,8 +21,8 @@ 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, int)
- cdef object as_string(self, object, int)
+ cdef object print_into(self, object, object, bint)
+ cdef object as_string(self, object, bint)
cdef object public_c2py(cexpr_t)
cdef _WrappedCExpr public_py2c(object)
diff --git a/djvu/sexpr.pyx b/djvu/sexpr.pyx
index d5b7bd5..1f26d29 100644
--- a/djvu/sexpr.pyx
+++ b/djvu/sexpr.pyx
@@ -1,13 +1,15 @@
# 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
-# the Free Software Foundation; version 2 dated June, 1991.
+# This file is part of python-djvulibre.
#
-# 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.
+# python-djvulibre is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 as published by
+# the Free Software Foundation.
+#
+# python-djvulibre 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.
#cython: autotestdict=False
@@ -15,6 +17,8 @@
DjVuLibre bindings: module for handling Lisp S-expressions
'''
+cimport cython
+
include 'common.pxi'
cdef extern from 'libdjvu/miniexp.h':
@@ -40,9 +44,9 @@ cdef extern from 'libdjvu/miniexp.h':
cexpr_t cexpr_reverse_list 'miniexp_reverse'(cexpr_t exp) nogil
int cexpr_is_str 'miniexp_stringp'(cexpr_t cexpr) nogil
- char* cexpr_to_str 'miniexp_to_str'(cexpr_t cexpr) nogil
- cexpr_t str_to_cexpr 'miniexp_string'(char* s) nogil
- cexpr_t cexpr_substr 'miniexp_substring'(char* s, int n) nogil
+ const char * cexpr_to_str 'miniexp_to_str'(cexpr_t cexpr) nogil
+ cexpr_t str_to_cexpr 'miniexp_string'(const char *s) nogil
+ cexpr_t cexpr_substr 'miniexp_substring'(const char *s, int n) nogil
cexpr_t cexpr_concat 'miniexp_concat'(cexpr_t cexpr_list) nogil
cexpr_t gc_lock 'minilisp_acquire_gc_lock'(cexpr_t cexpr) nogil
@@ -90,6 +94,9 @@ IF PY3K:
ELSE:
from cStringIO import StringIO
+cdef object BytesIO
+from io import BytesIO
+
cdef object weakref
import weakref
@@ -108,7 +115,7 @@ cdef class _ExpressionIO:
cdef cexpr_io_t cio
cdef int flags
ELSE:
- cdef int (*backup_io_puts)(char *s)
+ cdef int (*backup_io_puts)(const char *s)
cdef int (*backup_io_getc)()
cdef int (*backup_io_ungetc)(int c)
cdef int backup_io_7bit
@@ -158,6 +165,7 @@ cdef class _ExpressionIO:
io_7bit = escape_unicode
_myio = self
+ @cython.final
cdef close(self):
IF not HAVE_MINIEXP_IO_T:
global io_7bit, io_puts, io_getc, io_ungetc
@@ -181,29 +189,35 @@ cdef class _ExpressionIO:
IF HAVE_MINIEXP_IO_T:
+ @cython.final
cdef cexpr_t read(self):
return cexpr_read(&self.cio)
+ @cython.final
cdef cexpr_t print_(self, cexpr_t cexpr):
return cexpr_print(&self.cio, cexpr)
+ @cython.final
cdef cexpr_t printw(self, cexpr_t cexpr, int width):
return cexpr_printw(&self.cio, cexpr, width)
ELSE:
+ @cython.final
cdef cexpr_t read(self):
return cexpr_read()
+ @cython.final
cdef cexpr_t print_(self, cexpr_t cexpr):
return cexpr_print(cexpr)
+ @cython.final
cdef cexpr_t printw(self, cexpr_t cexpr, int width):
return cexpr_printw(cexpr, width)
IF HAVE_MINIEXP_IO_T:
- cdef int _myio_puts(cexpr_io_t* cio, char *s):
+ cdef int _myio_puts(cexpr_io_t* cio, const char *s):
cdef _ExpressionIO io
xio = <_ExpressionIO> cio.data[0]
try:
@@ -245,7 +259,7 @@ ELSE:
cdef _ExpressionIO _myio
- cdef int _myio_puts(char *s):
+ cdef int _myio_puts(const char *s):
try:
if _myio.stdout_binary:
_myio.stdout.write(s)
@@ -290,7 +304,7 @@ cdef class _WrappedCExpr:
cdef cexpr_t cexpr(self):
return cvar_ptr(self.cvar)[0]
- cdef object print_into(self, object stdout, object width, int escape_unicode):
+ cdef object print_into(self, object stdout, object width, bint escape_unicode):
cdef cexpr_t cexpr
cdef _ExpressionIO xio
if width is None:
@@ -309,7 +323,7 @@ cdef class _WrappedCExpr:
finally:
xio.close()
- cdef object as_string(self, object width, int escape_unicode):
+ cdef object as_string(self, object width, bint escape_unicode):
stdout = StringIO()
try:
self.print_into(stdout, width, escape_unicode)
@@ -328,10 +342,10 @@ cdef _WrappedCExpr wexpr(cexpr_t cexpr):
cdef class _MissingCExpr(_WrappedCExpr):
- cdef object print_into(self, object stdout, object width, int escape_unicode):
+ cdef object print_into(self, object stdout, object width, bint escape_unicode):
raise NotImplementedError
- cdef object as_string(self, object width, int escape_unicode):
+ cdef object as_string(self, object width, bint escape_unicode):
raise NotImplementedError
cdef _MissingCExpr wexpr_missing():
@@ -387,79 +401,43 @@ cdef class BaseSymbol:
def __reduce__(self):
return (Symbol, (self._bytes,))
-def Symbol__new__(cls, name):
- '''
- Symbol(name) -> a symbol
- '''
- self = None
- if is_unicode(name):
... 2702 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