summaryrefslogtreecommitdiff
path: root/pdfrw/objects/pdfarray.py
diff options
context:
space:
mode:
authorMatthias Klose <doko@debian.org>2014-07-13 17:50:59 +0200
committerMatthias Klose <doko@debian.org>2014-07-13 17:50:59 +0200
commita1959ba9c0c9f3881c3e593e5aef1046750880f2 (patch)
treee4fc630e9e26b227d9a7e41db65d80f6158e8ae9 /pdfrw/objects/pdfarray.py
pdfrw (0.1-3) unstable; urgency=medium
* QA upload. * Build using dh_python2 # imported from the archive
Diffstat (limited to 'pdfrw/objects/pdfarray.py')
-rw-r--r--pdfrw/objects/pdfarray.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/pdfrw/objects/pdfarray.py b/pdfrw/objects/pdfarray.py
new file mode 100644
index 0000000..8cf6bbb
--- /dev/null
+++ b/pdfrw/objects/pdfarray.py
@@ -0,0 +1,59 @@
+# A part of pdfrw (pdfrw.googlecode.com)
+# Copyright (C) 2006-2012 Patrick Maupin, Austin, Texas
+# MIT license -- See LICENSE.txt for details
+
+from pdfrw.objects.pdfindirect import PdfIndirect
+from pdfrw.objects.pdfobject import PdfObject
+
+def _resolved():
+ pass
+
+class PdfArray(list):
+ ''' A PdfArray maps the PDF file array object into a Python list.
+ It has an indirect attribute which defaults to False.
+ '''
+ indirect = False
+
+ def __init__(self, source=[]):
+ self._resolve = self._resolver
+ self.extend(source)
+
+ def _resolver(self, isinstance=isinstance, enumerate=enumerate,
+ listiter=list.__iter__,
+ PdfIndirect=PdfIndirect, resolved=_resolved,
+ PdfNull=PdfObject('null')):
+ for index, value in enumerate(list.__iter__(self)):
+ if isinstance(value, PdfIndirect):
+ value = value.real_value()
+ if value is None:
+ value = PdfNull
+ self[index] = value
+ self._resolve = resolved
+
+ def __getitem__(self, index, listget=list.__getitem__):
+ self._resolve()
+ return listget(self, index)
+
+ def __getslice__(self, index, listget=list.__getslice__):
+ self._resolve()
+ return listget(self, index)
+
+ def __iter__(self, listiter=list.__iter__):
+ self._resolve()
+ return listiter(self)
+
+ def count(self, item):
+ self._resolve()
+ return list.count(self, item)
+ def index(self, item):
+ self._resolve()
+ return list.index(self, item)
+ def remove(self, item):
+ self._resolve()
+ return list.remove(self, item)
+ def sort(self, *args, **kw):
+ self._resolve()
+ return list.sort(self, *args, **kw)
+ def pop(self, *args):
+ self._resolve()
+ return list.pop(self, *args)