[Python-modules-commits] r13336 - in packages/pdfminer/trunk/debian/patches (poppler-data.diff)

jwilk at users.alioth.debian.org jwilk at users.alioth.debian.org
Tue Jun 8 18:17:24 UTC 2010


    Date: Tuesday, June 8, 2010 @ 18:17:12
  Author: jwilk
Revision: 13336

cmapdb: cache results; fix reading to-unicode cmaps.

Modified:
  packages/pdfminer/trunk/debian/patches/poppler-data.diff

Modified: packages/pdfminer/trunk/debian/patches/poppler-data.diff
===================================================================
--- packages/pdfminer/trunk/debian/patches/poppler-data.diff	2010-06-08 16:51:04 UTC (rev 13335)
+++ packages/pdfminer/trunk/debian/patches/poppler-data.diff	2010-06-08 18:17:12 UTC (rev 13336)
@@ -16,7 +16,38 @@
  from struct import pack, unpack
  from psparser import PSStackParser
  from psparser import PSException, PSSyntaxError, PSTypeError, PSEOF
-@@ -225,8 +226,19 @@
+@@ -204,6 +205,22 @@
+     def __repr__(self):
+         return '<PyUnicodeMap: %s>' % (self.name)
+ 
++def _cache(method):
++
++    def wrapped_method(self, *args):
++        cache_attr_name = '_%s_cache' % method.__name__
++        cache = getattr(self, cache_attr_name, None)
++        if cache is None:
++            cache = {}
++            setattr(self, cache_attr_name, cache)
++        try:
++            return cache[args]
++        except KeyError:
++            result = method(self, *args)
++            cache[args] = result
++            return result
++
++    return wrapped_method
+ 
+ ##  CMapDB
+ ##
+@@ -214,6 +231,7 @@
+     class CMapNotFound(CMapError): pass
+ 
+     @classmethod
++    @_cache
+     def get_cmap(klass, name):
+         if name == 'Identity-H':
+             return IdentityCMap(False)
+@@ -225,10 +243,22 @@
          try:
              module = __import__(modname, fromlist=['pdfminer.cmap'])
          except ImportError:
@@ -36,15 +67,20 @@
 +            return PyCMap(name, module)
  
      @classmethod
++    @_cache
      def get_unicode_map(klass, name, vertical=False):
-@@ -236,8 +248,18 @@
+         modname = 'pdfminer.cmap.TO_UNICODE_%s' % name.replace('-','_')
+         if klass.debug:
+@@ -236,8 +266,20 @@
          try:
              module = __import__(modname, fromlist=['pdfminer.cmap'])
          except ImportError:
-+            directory = '/usr/share/poppler/cidToUnicode/'
-+            if os.path.exists(directory + name):
++            for directory in glob.glob('/usr/share/poppler/cMap/*/'):
++                filename = directory + name + '-UCS2'
++                if not os.path.exists(filename):
++                    continue
 +                cmap = FileUnicodeMap()
-+                fp = file(directory + name, 'rb')
++                fp = file(filename, 'rb')
 +                try:
 +                    CMapParser(cmap, fp).run()
 +                finally:




More information about the Python-modules-commits mailing list