Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +2 -0
- 670proj-master/app/app/static/img/background.png +3 -0
- 670proj-master/app/app/static/img/graph.png +3 -0
- 670proj-master/app/app/static/img/log_tag.png +3 -0
- 670proj-master/app/app/static/img/logo.png +3 -0
- 670proj-master/app/app/static/img/logo_tag.png +3 -0
- 670proj-master/app/app/static/img/model_details2.png +3 -0
- 670proj-master/app/app/static/img/music-words-facebook-cover.jpg +3 -0
- 670proj-master/app/app/static/img/simpledesktop.png +3 -0
- 670proj-master/app/app/static/img/spyroBlack_rainbow-01.png +3 -0
- 670proj-master/app/app/static/img/tm-img-270x270-2.jpg +3 -0
- 670proj-master/app/app/static/img/tm-img-270x270-3.jpg +3 -0
- 670proj-master/app/app/static/img/tm-img-320x320-2.jpg +3 -0
- 670proj-master/app/app/static/img/tm-img-320x320-3.jpg +3 -0
- 670proj-master/app/app/static/img/top-bg-1.jpg +3 -0
- 670proj-master/app/app/static/img/top-bg-3.jpg +3 -0
- 670proj-master/app/data/checkpoints/model-3200.data-00000-of-00001 +3 -0
- 730ne-master/wsgi/static/adu.png +3 -0
- 730ne-master/wsgi/static/link-external.png +3 -0
- 8004-master/alloc_en/static/alloc_en/Img_T1.jpeg +3 -0
- 8004-master/fixed_en/static/fixed_en/Img_I2.png +3 -0
- 8004-master/fixed_en/static/fixed_en/Img_I3.png +3 -0
- 8004-master/fixed_en/static/fixed_en/Img_I4.png +3 -0
- 8004-master/fixed_en/static/fixed_en/triangle.png +3 -0
- 8004-master/fluid_en/static/fluid_en/Img_I2.png +3 -0
- 8004-master/fluid_en/static/fluid_en/Img_T4.jpeg +3 -0
- 8004-master/inst_fixed_en/static/inst_fixed_en/Img_A6.jpeg +3 -0
- 8004-master/inst_fixed_en/static/inst_fixed_en/Img_B1.png +3 -0
- 8004-master/inst_fixed_en/static/inst_fixed_en/Img_B3.png +3 -0
- 8004-master/inst_fixed_en/static/inst_fixed_en/Img_C4.png +3 -0
- 8004-master/inst_fluid_en/static/inst_fluid_en/Img_X2.jpeg +3 -0
- 8004-master/inst_fluid_en/static/inst_fluid_en/Img_X3.jpeg +3 -0
- 8004-master/task_sums/static/task_sums/Img_A6.png +3 -0
- 8210_A1P3-master/Lib/site-packages/PIL/_imagingft.cp37-win32.pyd +3 -0
- 8210_A1P3-master/Lib/site-packages/html5lib/treebuilders/etree.py +340 -0
- 8210_A1P3-master/Lib/site-packages/html5lib/treebuilders/etree_lxml.py +366 -0
- 8210_A1P3-master/Lib/site-packages/html5lib/treewalkers/__init__.py +154 -0
- 8210_A1P3-master/Lib/site-packages/html5lib/treewalkers/base.py +252 -0
- 8210_A1P3-master/Lib/site-packages/html5lib/treewalkers/dom.py +43 -0
- 8210_A1P3-master/Lib/site-packages/html5lib/treewalkers/etree.py +130 -0
- 8210_A1P3-master/Lib/site-packages/html5lib/treewalkers/etree_lxml.py +213 -0
- 8210_A1P3-master/Lib/site-packages/html5lib/treewalkers/genshi.py +69 -0
- 8210_A1P3-master/Lib/site-packages/mathfilters/templatetags/mathfilters.py +136 -0
- 8210_A1P3-master/Lib/site-packages/mathfilters/tests.py +306 -0
- 8210_A1P3-master/Lib/site-packages/pdfrw-0.4.dist-info/DESCRIPTION.rst +791 -0
- 8210_A1P3-master/Lib/site-packages/pdfrw-0.4.dist-info/INSTALLER +1 -0
- 8210_A1P3-master/Lib/site-packages/pdfrw-0.4.dist-info/METADATA +820 -0
- 8210_A1P3-master/Lib/site-packages/pdfrw-0.4.dist-info/RECORD +48 -0
- 8210_A1P3-master/Lib/site-packages/pdfrw-0.4.dist-info/WHEEL +6 -0
- 8210_A1P3-master/Lib/site-packages/pdfrw-0.4.dist-info/metadata.json +1 -0
.gitattributes
CHANGED
|
@@ -127,3 +127,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 127 |
670proj-master/app/songcleaned2.csv filter=lfs diff=lfs merge=lfs -text
|
| 128 |
5dolar-website-meme-master/static/webfonts/fa-brands-400.eot filter=lfs diff=lfs merge=lfs -text
|
| 129 |
5485-master/demos/node_modules/mongoose/node_modules/bson/node_modules/bson-ext/build/Release/obj.target/bson/ext/bson.o filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 127 |
670proj-master/app/songcleaned2.csv filter=lfs diff=lfs merge=lfs -text
|
| 128 |
5dolar-website-meme-master/static/webfonts/fa-brands-400.eot filter=lfs diff=lfs merge=lfs -text
|
| 129 |
5485-master/demos/node_modules/mongoose/node_modules/bson/node_modules/bson-ext/build/Release/obj.target/bson/ext/bson.o filter=lfs diff=lfs merge=lfs -text
|
| 130 |
+
670proj-master/app/data/checkpoints/model-3200.data-00000-of-00001 filter=lfs diff=lfs merge=lfs -text
|
| 131 |
+
8210_A1P3-master/Lib/site-packages/PIL/_imagingft.cp37-win32.pyd filter=lfs diff=lfs merge=lfs -text
|
670proj-master/app/app/static/img/background.png
ADDED
|
Git LFS Details
|
670proj-master/app/app/static/img/graph.png
ADDED
|
Git LFS Details
|
670proj-master/app/app/static/img/log_tag.png
ADDED
|
Git LFS Details
|
670proj-master/app/app/static/img/logo.png
ADDED
|
Git LFS Details
|
670proj-master/app/app/static/img/logo_tag.png
ADDED
|
Git LFS Details
|
670proj-master/app/app/static/img/model_details2.png
ADDED
|
Git LFS Details
|
670proj-master/app/app/static/img/music-words-facebook-cover.jpg
ADDED
|
Git LFS Details
|
670proj-master/app/app/static/img/simpledesktop.png
ADDED
|
Git LFS Details
|
670proj-master/app/app/static/img/spyroBlack_rainbow-01.png
ADDED
|
Git LFS Details
|
670proj-master/app/app/static/img/tm-img-270x270-2.jpg
ADDED
|
Git LFS Details
|
670proj-master/app/app/static/img/tm-img-270x270-3.jpg
ADDED
|
Git LFS Details
|
670proj-master/app/app/static/img/tm-img-320x320-2.jpg
ADDED
|
Git LFS Details
|
670proj-master/app/app/static/img/tm-img-320x320-3.jpg
ADDED
|
Git LFS Details
|
670proj-master/app/app/static/img/top-bg-1.jpg
ADDED
|
Git LFS Details
|
670proj-master/app/app/static/img/top-bg-3.jpg
ADDED
|
Git LFS Details
|
670proj-master/app/data/checkpoints/model-3200.data-00000-of-00001
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8544ca5736536209b18a3d256ecf42945a69c87c7615c099d08cfe07f8182ee8
|
| 3 |
+
size 1410120
|
730ne-master/wsgi/static/adu.png
ADDED
|
Git LFS Details
|
730ne-master/wsgi/static/link-external.png
ADDED
|
Git LFS Details
|
8004-master/alloc_en/static/alloc_en/Img_T1.jpeg
ADDED
|
Git LFS Details
|
8004-master/fixed_en/static/fixed_en/Img_I2.png
ADDED
|
Git LFS Details
|
8004-master/fixed_en/static/fixed_en/Img_I3.png
ADDED
|
Git LFS Details
|
8004-master/fixed_en/static/fixed_en/Img_I4.png
ADDED
|
Git LFS Details
|
8004-master/fixed_en/static/fixed_en/triangle.png
ADDED
|
Git LFS Details
|
8004-master/fluid_en/static/fluid_en/Img_I2.png
ADDED
|
Git LFS Details
|
8004-master/fluid_en/static/fluid_en/Img_T4.jpeg
ADDED
|
Git LFS Details
|
8004-master/inst_fixed_en/static/inst_fixed_en/Img_A6.jpeg
ADDED
|
Git LFS Details
|
8004-master/inst_fixed_en/static/inst_fixed_en/Img_B1.png
ADDED
|
Git LFS Details
|
8004-master/inst_fixed_en/static/inst_fixed_en/Img_B3.png
ADDED
|
Git LFS Details
|
8004-master/inst_fixed_en/static/inst_fixed_en/Img_C4.png
ADDED
|
Git LFS Details
|
8004-master/inst_fluid_en/static/inst_fluid_en/Img_X2.jpeg
ADDED
|
Git LFS Details
|
8004-master/inst_fluid_en/static/inst_fluid_en/Img_X3.jpeg
ADDED
|
Git LFS Details
|
8004-master/task_sums/static/task_sums/Img_A6.png
ADDED
|
Git LFS Details
|
8210_A1P3-master/Lib/site-packages/PIL/_imagingft.cp37-win32.pyd
ADDED
|
@@ -0,0 +1,3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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import absolute_import, division, unicode_literals
|
| 2 |
+
# pylint:disable=protected-access
|
| 3 |
+
|
| 4 |
+
from six import text_type
|
| 5 |
+
|
| 6 |
+
import re
|
| 7 |
+
|
| 8 |
+
from . import base
|
| 9 |
+
from .. import _ihatexml
|
| 10 |
+
from .. import constants
|
| 11 |
+
from ..constants import namespaces
|
| 12 |
+
from .._utils import moduleFactoryFactory
|
| 13 |
+
|
| 14 |
+
tag_regexp = re.compile("{([^}]*)}(.*)")
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def getETreeBuilder(ElementTreeImplementation, fullTree=False):
|
| 18 |
+
ElementTree = ElementTreeImplementation
|
| 19 |
+
ElementTreeCommentType = ElementTree.Comment("asd").tag
|
| 20 |
+
|
| 21 |
+
class Element(base.Node):
|
| 22 |
+
def __init__(self, name, namespace=None):
|
| 23 |
+
self._name = name
|
| 24 |
+
self._namespace = namespace
|
| 25 |
+
self._element = ElementTree.Element(self._getETreeTag(name,
|
| 26 |
+
namespace))
|
| 27 |
+
if namespace is None:
|
| 28 |
+
self.nameTuple = namespaces["html"], self._name
|
| 29 |
+
else:
|
| 30 |
+
self.nameTuple = self._namespace, self._name
|
| 31 |
+
self.parent = None
|
| 32 |
+
self._childNodes = []
|
| 33 |
+
self._flags = []
|
| 34 |
+
|
| 35 |
+
def _getETreeTag(self, name, namespace):
|
| 36 |
+
if namespace is None:
|
| 37 |
+
etree_tag = name
|
| 38 |
+
else:
|
| 39 |
+
etree_tag = "{%s}%s" % (namespace, name)
|
| 40 |
+
return etree_tag
|
| 41 |
+
|
| 42 |
+
def _setName(self, name):
|
| 43 |
+
self._name = name
|
| 44 |
+
self._element.tag = self._getETreeTag(self._name, self._namespace)
|
| 45 |
+
|
| 46 |
+
def _getName(self):
|
| 47 |
+
return self._name
|
| 48 |
+
|
| 49 |
+
name = property(_getName, _setName)
|
| 50 |
+
|
| 51 |
+
def _setNamespace(self, namespace):
|
| 52 |
+
self._namespace = namespace
|
| 53 |
+
self._element.tag = self._getETreeTag(self._name, self._namespace)
|
| 54 |
+
|
| 55 |
+
def _getNamespace(self):
|
| 56 |
+
return self._namespace
|
| 57 |
+
|
| 58 |
+
namespace = property(_getNamespace, _setNamespace)
|
| 59 |
+
|
| 60 |
+
def _getAttributes(self):
|
| 61 |
+
return self._element.attrib
|
| 62 |
+
|
| 63 |
+
def _setAttributes(self, attributes):
|
| 64 |
+
# Delete existing attributes first
|
| 65 |
+
# XXX - there may be a better way to do this...
|
| 66 |
+
for key in list(self._element.attrib.keys()):
|
| 67 |
+
del self._element.attrib[key]
|
| 68 |
+
for key, value in attributes.items():
|
| 69 |
+
if isinstance(key, tuple):
|
| 70 |
+
name = "{%s}%s" % (key[2], key[1])
|
| 71 |
+
else:
|
| 72 |
+
name = key
|
| 73 |
+
self._element.set(name, value)
|
| 74 |
+
|
| 75 |
+
attributes = property(_getAttributes, _setAttributes)
|
| 76 |
+
|
| 77 |
+
def _getChildNodes(self):
|
| 78 |
+
return self._childNodes
|
| 79 |
+
|
| 80 |
+
def _setChildNodes(self, value):
|
| 81 |
+
del self._element[:]
|
| 82 |
+
self._childNodes = []
|
| 83 |
+
for element in value:
|
| 84 |
+
self.insertChild(element)
|
| 85 |
+
|
| 86 |
+
childNodes = property(_getChildNodes, _setChildNodes)
|
| 87 |
+
|
| 88 |
+
def hasContent(self):
|
| 89 |
+
"""Return true if the node has children or text"""
|
| 90 |
+
return bool(self._element.text or len(self._element))
|
| 91 |
+
|
| 92 |
+
def appendChild(self, node):
|
| 93 |
+
self._childNodes.append(node)
|
| 94 |
+
self._element.append(node._element)
|
| 95 |
+
node.parent = self
|
| 96 |
+
|
| 97 |
+
def insertBefore(self, node, refNode):
|
| 98 |
+
index = list(self._element).index(refNode._element)
|
| 99 |
+
self._element.insert(index, node._element)
|
| 100 |
+
node.parent = self
|
| 101 |
+
|
| 102 |
+
def removeChild(self, node):
|
| 103 |
+
self._childNodes.remove(node)
|
| 104 |
+
self._element.remove(node._element)
|
| 105 |
+
node.parent = None
|
| 106 |
+
|
| 107 |
+
def insertText(self, data, insertBefore=None):
|
| 108 |
+
if not(len(self._element)):
|
| 109 |
+
if not self._element.text:
|
| 110 |
+
self._element.text = ""
|
| 111 |
+
self._element.text += data
|
| 112 |
+
elif insertBefore is None:
|
| 113 |
+
# Insert the text as the tail of the last child element
|
| 114 |
+
if not self._element[-1].tail:
|
| 115 |
+
self._element[-1].tail = ""
|
| 116 |
+
self._element[-1].tail += data
|
| 117 |
+
else:
|
| 118 |
+
# Insert the text before the specified node
|
| 119 |
+
children = list(self._element)
|
| 120 |
+
index = children.index(insertBefore._element)
|
| 121 |
+
if index > 0:
|
| 122 |
+
if not self._element[index - 1].tail:
|
| 123 |
+
self._element[index - 1].tail = ""
|
| 124 |
+
self._element[index - 1].tail += data
|
| 125 |
+
else:
|
| 126 |
+
if not self._element.text:
|
| 127 |
+
self._element.text = ""
|
| 128 |
+
self._element.text += data
|
| 129 |
+
|
| 130 |
+
def cloneNode(self):
|
| 131 |
+
element = type(self)(self.name, self.namespace)
|
| 132 |
+
for name, value in self.attributes.items():
|
| 133 |
+
element.attributes[name] = value
|
| 134 |
+
return element
|
| 135 |
+
|
| 136 |
+
def reparentChildren(self, newParent):
|
| 137 |
+
if newParent.childNodes:
|
| 138 |
+
newParent.childNodes[-1]._element.tail += self._element.text
|
| 139 |
+
else:
|
| 140 |
+
if not newParent._element.text:
|
| 141 |
+
newParent._element.text = ""
|
| 142 |
+
if self._element.text is not None:
|
| 143 |
+
newParent._element.text += self._element.text
|
| 144 |
+
self._element.text = ""
|
| 145 |
+
base.Node.reparentChildren(self, newParent)
|
| 146 |
+
|
| 147 |
+
class Comment(Element):
|
| 148 |
+
def __init__(self, data):
|
| 149 |
+
# Use the superclass constructor to set all properties on the
|
| 150 |
+
# wrapper element
|
| 151 |
+
self._element = ElementTree.Comment(data)
|
| 152 |
+
self.parent = None
|
| 153 |
+
self._childNodes = []
|
| 154 |
+
self._flags = []
|
| 155 |
+
|
| 156 |
+
def _getData(self):
|
| 157 |
+
return self._element.text
|
| 158 |
+
|
| 159 |
+
def _setData(self, value):
|
| 160 |
+
self._element.text = value
|
| 161 |
+
|
| 162 |
+
data = property(_getData, _setData)
|
| 163 |
+
|
| 164 |
+
class DocumentType(Element):
|
| 165 |
+
def __init__(self, name, publicId, systemId):
|
| 166 |
+
Element.__init__(self, "<!DOCTYPE>")
|
| 167 |
+
self._element.text = name
|
| 168 |
+
self.publicId = publicId
|
| 169 |
+
self.systemId = systemId
|
| 170 |
+
|
| 171 |
+
def _getPublicId(self):
|
| 172 |
+
return self._element.get("publicId", "")
|
| 173 |
+
|
| 174 |
+
def _setPublicId(self, value):
|
| 175 |
+
if value is not None:
|
| 176 |
+
self._element.set("publicId", value)
|
| 177 |
+
|
| 178 |
+
publicId = property(_getPublicId, _setPublicId)
|
| 179 |
+
|
| 180 |
+
def _getSystemId(self):
|
| 181 |
+
return self._element.get("systemId", "")
|
| 182 |
+
|
| 183 |
+
def _setSystemId(self, value):
|
| 184 |
+
if value is not None:
|
| 185 |
+
self._element.set("systemId", value)
|
| 186 |
+
|
| 187 |
+
systemId = property(_getSystemId, _setSystemId)
|
| 188 |
+
|
| 189 |
+
class Document(Element):
|
| 190 |
+
def __init__(self):
|
| 191 |
+
Element.__init__(self, "DOCUMENT_ROOT")
|
| 192 |
+
|
| 193 |
+
class DocumentFragment(Element):
|
| 194 |
+
def __init__(self):
|
| 195 |
+
Element.__init__(self, "DOCUMENT_FRAGMENT")
|
| 196 |
+
|
| 197 |
+
def testSerializer(element):
|
| 198 |
+
rv = []
|
| 199 |
+
|
| 200 |
+
def serializeElement(element, indent=0):
|
| 201 |
+
if not(hasattr(element, "tag")):
|
| 202 |
+
element = element.getroot()
|
| 203 |
+
if element.tag == "<!DOCTYPE>":
|
| 204 |
+
if element.get("publicId") or element.get("systemId"):
|
| 205 |
+
publicId = element.get("publicId") or ""
|
| 206 |
+
systemId = element.get("systemId") or ""
|
| 207 |
+
rv.append("""<!DOCTYPE %s "%s" "%s">""" %
|
| 208 |
+
(element.text, publicId, systemId))
|
| 209 |
+
else:
|
| 210 |
+
rv.append("<!DOCTYPE %s>" % (element.text,))
|
| 211 |
+
elif element.tag == "DOCUMENT_ROOT":
|
| 212 |
+
rv.append("#document")
|
| 213 |
+
if element.text is not None:
|
| 214 |
+
rv.append("|%s\"%s\"" % (' ' * (indent + 2), element.text))
|
| 215 |
+
if element.tail is not None:
|
| 216 |
+
raise TypeError("Document node cannot have tail")
|
| 217 |
+
if hasattr(element, "attrib") and len(element.attrib):
|
| 218 |
+
raise TypeError("Document node cannot have attributes")
|
| 219 |
+
elif element.tag == ElementTreeCommentType:
|
| 220 |
+
rv.append("|%s<!-- %s -->" % (' ' * indent, element.text))
|
| 221 |
+
else:
|
| 222 |
+
assert isinstance(element.tag, text_type), \
|
| 223 |
+
"Expected unicode, got %s, %s" % (type(element.tag), element.tag)
|
| 224 |
+
nsmatch = tag_regexp.match(element.tag)
|
| 225 |
+
|
| 226 |
+
if nsmatch is None:
|
| 227 |
+
name = element.tag
|
| 228 |
+
else:
|
| 229 |
+
ns, name = nsmatch.groups()
|
| 230 |
+
prefix = constants.prefixes[ns]
|
| 231 |
+
name = "%s %s" % (prefix, name)
|
| 232 |
+
rv.append("|%s<%s>" % (' ' * indent, name))
|
| 233 |
+
|
| 234 |
+
if hasattr(element, "attrib"):
|
| 235 |
+
attributes = []
|
| 236 |
+
for name, value in element.attrib.items():
|
| 237 |
+
nsmatch = tag_regexp.match(name)
|
| 238 |
+
if nsmatch is not None:
|
| 239 |
+
ns, name = nsmatch.groups()
|
| 240 |
+
prefix = constants.prefixes[ns]
|
| 241 |
+
attr_string = "%s %s" % (prefix, name)
|
| 242 |
+
else:
|
| 243 |
+
attr_string = name
|
| 244 |
+
attributes.append((attr_string, value))
|
| 245 |
+
|
| 246 |
+
for name, value in sorted(attributes):
|
| 247 |
+
rv.append('|%s%s="%s"' % (' ' * (indent + 2), name, value))
|
| 248 |
+
if element.text:
|
| 249 |
+
rv.append("|%s\"%s\"" % (' ' * (indent + 2), element.text))
|
| 250 |
+
indent += 2
|
| 251 |
+
for child in element:
|
| 252 |
+
serializeElement(child, indent)
|
| 253 |
+
if element.tail:
|
| 254 |
+
rv.append("|%s\"%s\"" % (' ' * (indent - 2), element.tail))
|
| 255 |
+
serializeElement(element, 0)
|
| 256 |
+
|
| 257 |
+
return "\n".join(rv)
|
| 258 |
+
|
| 259 |
+
def tostring(element): # pylint:disable=unused-variable
|
| 260 |
+
"""Serialize an element and its child nodes to a string"""
|
| 261 |
+
rv = []
|
| 262 |
+
filter = _ihatexml.InfosetFilter()
|
| 263 |
+
|
| 264 |
+
def serializeElement(element):
|
| 265 |
+
if isinstance(element, ElementTree.ElementTree):
|
| 266 |
+
element = element.getroot()
|
| 267 |
+
|
| 268 |
+
if element.tag == "<!DOCTYPE>":
|
| 269 |
+
if element.get("publicId") or element.get("systemId"):
|
| 270 |
+
publicId = element.get("publicId") or ""
|
| 271 |
+
systemId = element.get("systemId") or ""
|
| 272 |
+
rv.append("""<!DOCTYPE %s PUBLIC "%s" "%s">""" %
|
| 273 |
+
(element.text, publicId, systemId))
|
| 274 |
+
else:
|
| 275 |
+
rv.append("<!DOCTYPE %s>" % (element.text,))
|
| 276 |
+
elif element.tag == "DOCUMENT_ROOT":
|
| 277 |
+
if element.text is not None:
|
| 278 |
+
rv.append(element.text)
|
| 279 |
+
if element.tail is not None:
|
| 280 |
+
raise TypeError("Document node cannot have tail")
|
| 281 |
+
if hasattr(element, "attrib") and len(element.attrib):
|
| 282 |
+
raise TypeError("Document node cannot have attributes")
|
| 283 |
+
|
| 284 |
+
for child in element:
|
| 285 |
+
serializeElement(child)
|
| 286 |
+
|
| 287 |
+
elif element.tag == ElementTreeCommentType:
|
| 288 |
+
rv.append("<!--%s-->" % (element.text,))
|
| 289 |
+
else:
|
| 290 |
+
# This is assumed to be an ordinary element
|
| 291 |
+
if not element.attrib:
|
| 292 |
+
rv.append("<%s>" % (filter.fromXmlName(element.tag),))
|
| 293 |
+
else:
|
| 294 |
+
attr = " ".join(["%s=\"%s\"" % (
|
| 295 |
+
filter.fromXmlName(name), value)
|
| 296 |
+
for name, value in element.attrib.items()])
|
| 297 |
+
rv.append("<%s %s>" % (element.tag, attr))
|
| 298 |
+
if element.text:
|
| 299 |
+
rv.append(element.text)
|
| 300 |
+
|
| 301 |
+
for child in element:
|
| 302 |
+
serializeElement(child)
|
| 303 |
+
|
| 304 |
+
rv.append("</%s>" % (element.tag,))
|
| 305 |
+
|
| 306 |
+
if element.tail:
|
| 307 |
+
rv.append(element.tail)
|
| 308 |
+
|
| 309 |
+
serializeElement(element)
|
| 310 |
+
|
| 311 |
+
return "".join(rv)
|
| 312 |
+
|
| 313 |
+
class TreeBuilder(base.TreeBuilder): # pylint:disable=unused-variable
|
| 314 |
+
documentClass = Document
|
| 315 |
+
doctypeClass = DocumentType
|
| 316 |
+
elementClass = Element
|
| 317 |
+
commentClass = Comment
|
| 318 |
+
fragmentClass = DocumentFragment
|
| 319 |
+
implementation = ElementTreeImplementation
|
| 320 |
+
|
| 321 |
+
def testSerializer(self, element):
|
| 322 |
+
return testSerializer(element)
|
| 323 |
+
|
| 324 |
+
def getDocument(self):
|
| 325 |
+
if fullTree:
|
| 326 |
+
return self.document._element
|
| 327 |
+
else:
|
| 328 |
+
if self.defaultNamespace is not None:
|
| 329 |
+
return self.document._element.find(
|
| 330 |
+
"{%s}html" % self.defaultNamespace)
|
| 331 |
+
else:
|
| 332 |
+
return self.document._element.find("html")
|
| 333 |
+
|
| 334 |
+
def getFragment(self):
|
| 335 |
+
return base.TreeBuilder.getF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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Module for supporting the lxml.etree library. The idea here is to use as much
|
| 2 |
+
of the native library as possible, without using fragile hacks like custom element
|
| 3 |
+
names that break between releases. The downside of this is that we cannot represent
|
| 4 |
+
all possible trees; specifically the following are known to cause problems:
|
| 5 |
+
|
| 6 |
+
Text or comments as siblings of the root element
|
| 7 |
+
Docypes with no name
|
| 8 |
+
|
| 9 |
+
When any of these things occur, we emit a DataLossWarning
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
from __future__ import absolute_import, division, unicode_literals
|
| 13 |
+
# pylint:disable=protected-access
|
| 14 |
+
|
| 15 |
+
import warnings
|
| 16 |
+
import re
|
| 17 |
+
import sys
|
| 18 |
+
|
| 19 |
+
from . import base
|
| 20 |
+
from ..constants import DataLossWarning
|
| 21 |
+
from .. import constants
|
| 22 |
+
from . import etree as etree_builders
|
| 23 |
+
from .. import _ihatexml
|
| 24 |
+
|
| 25 |
+
import lxml.etree as etree
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
fullTree = True
|
| 29 |
+
tag_regexp = re.compile("{([^}]*)}(.*)")
|
| 30 |
+
|
| 31 |
+
comment_type = etree.Comment("asd").tag
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class DocumentType(object):
|
| 35 |
+
def __init__(self, name, publicId, systemId):
|
| 36 |
+
self.name = name
|
| 37 |
+
self.publicId = publicId
|
| 38 |
+
self.systemId = systemId
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
class Document(object):
|
| 42 |
+
def __init__(self):
|
| 43 |
+
self._elementTree = None
|
| 44 |
+
self._childNodes = []
|
| 45 |
+
|
| 46 |
+
def appendChild(self, element):
|
| 47 |
+
self._elementTree.getroot().addnext(element._element)
|
| 48 |
+
|
| 49 |
+
def _getChildNodes(self):
|
| 50 |
+
return self._childNodes
|
| 51 |
+
|
| 52 |
+
childNodes = property(_getChildNodes)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def testSerializer(element):
|
| 56 |
+
rv = []
|
| 57 |
+
infosetFilter = _ihatexml.InfosetFilter(preventDoubleDashComments=True)
|
| 58 |
+
|
| 59 |
+
def serializeElement(element, indent=0):
|
| 60 |
+
if not hasattr(element, "tag"):
|
| 61 |
+
if hasattr(element, "getroot"):
|
| 62 |
+
# Full tree case
|
| 63 |
+
rv.append("#document")
|
| 64 |
+
if element.docinfo.internalDTD:
|
| 65 |
+
if not (element.docinfo.public_id or
|
| 66 |
+
element.docinfo.system_url):
|
| 67 |
+
dtd_str = "<!DOCTYPE %s>" % element.docinfo.root_name
|
| 68 |
+
else:
|
| 69 |
+
dtd_str = """<!DOCTYPE %s "%s" "%s">""" % (
|
| 70 |
+
element.docinfo.root_name,
|
| 71 |
+
element.docinfo.public_id,
|
| 72 |
+
element.docinfo.system_url)
|
| 73 |
+
rv.append("|%s%s" % (' ' * (indent + 2), dtd_str))
|
| 74 |
+
next_element = element.getroot()
|
| 75 |
+
while next_element.getprevious() is not None:
|
| 76 |
+
next_element = next_element.getprevious()
|
| 77 |
+
while next_element is not None:
|
| 78 |
+
serializeElement(next_element, indent + 2)
|
| 79 |
+
next_element = next_element.getnext()
|
| 80 |
+
elif isinstance(element, str) or isinstance(element, bytes):
|
| 81 |
+
# Text in a fragment
|
| 82 |
+
assert isinstance(element, str) or sys.version_info[0] == 2
|
| 83 |
+
rv.append("|%s\"%s\"" % (' ' * indent, element))
|
| 84 |
+
else:
|
| 85 |
+
# Fragment case
|
| 86 |
+
rv.append("#document-fragment")
|
| 87 |
+
for next_element in element:
|
| 88 |
+
serializeElement(next_element, indent + 2)
|
| 89 |
+
elif element.tag == comment_type:
|
| 90 |
+
rv.append("|%s<!-- %s -->" % (' ' * indent, element.text))
|
| 91 |
+
if hasattr(element, "tail") and element.tail:
|
| 92 |
+
rv.append("|%s\"%s\"" % (' ' * indent, element.tail))
|
| 93 |
+
else:
|
| 94 |
+
assert isinstance(element, etree._Element)
|
| 95 |
+
nsmatch = etree_builders.tag_regexp.match(element.tag)
|
| 96 |
+
if nsmatch is not None:
|
| 97 |
+
ns = nsmatch.group(1)
|
| 98 |
+
tag = nsmatch.group(2)
|
| 99 |
+
prefix = constants.prefixes[ns]
|
| 100 |
+
rv.append("|%s<%s %s>" % (' ' * indent, prefix,
|
| 101 |
+
infosetFilter.fromXmlName(tag)))
|
| 102 |
+
else:
|
| 103 |
+
rv.append("|%s<%s>" % (' ' * indent,
|
| 104 |
+
infosetFilter.fromXmlName(element.tag)))
|
| 105 |
+
|
| 106 |
+
if hasattr(element, "attrib"):
|
| 107 |
+
attributes = []
|
| 108 |
+
for name, value in element.attrib.items():
|
| 109 |
+
nsmatch = tag_regexp.match(name)
|
| 110 |
+
if nsmatch is not None:
|
| 111 |
+
ns, name = nsmatch.groups()
|
| 112 |
+
name = infosetFilter.fromXmlName(name)
|
| 113 |
+
prefix = constants.prefixes[ns]
|
| 114 |
+
attr_string = "%s %s" % (prefix, name)
|
| 115 |
+
else:
|
| 116 |
+
attr_string = infosetFilter.fromXmlName(name)
|
| 117 |
+
attributes.append((attr_string, value))
|
| 118 |
+
|
| 119 |
+
for name, value in sorted(attributes):
|
| 120 |
+
rv.append('|%s%s="%s"' % (' ' * (indent + 2), name, value))
|
| 121 |
+
|
| 122 |
+
if element.text:
|
| 123 |
+
rv.append("|%s\"%s\"" % (' ' * (indent + 2), element.text))
|
| 124 |
+
indent += 2
|
| 125 |
+
for child in element:
|
| 126 |
+
serializeElement(child, indent)
|
| 127 |
+
if hasattr(element, "tail") and element.tail:
|
| 128 |
+
rv.append("|%s\"%s\"" % (' ' * (indent - 2), element.tail))
|
| 129 |
+
serializeElement(element, 0)
|
| 130 |
+
|
| 131 |
+
return "\n".join(rv)
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def tostring(element):
|
| 135 |
+
"""Serialize an element and its child nodes to a string"""
|
| 136 |
+
rv = []
|
| 137 |
+
|
| 138 |
+
def serializeElement(element):
|
| 139 |
+
if not hasattr(element, "tag"):
|
| 140 |
+
if element.docinfo.internalDTD:
|
| 141 |
+
if element.docinfo.doctype:
|
| 142 |
+
dtd_str = element.docinfo.doctype
|
| 143 |
+
else:
|
| 144 |
+
dtd_str = "<!DOCTYPE %s>" % element.docinfo.root_name
|
| 145 |
+
rv.append(dtd_str)
|
| 146 |
+
serializeElement(element.getroot())
|
| 147 |
+
|
| 148 |
+
elif element.tag == comment_type:
|
| 149 |
+
rv.append("<!--%s-->" % (element.text,))
|
| 150 |
+
|
| 151 |
+
else:
|
| 152 |
+
# This is assumed to be an ordinary element
|
| 153 |
+
if not element.attrib:
|
| 154 |
+
rv.append("<%s>" % (element.tag,))
|
| 155 |
+
else:
|
| 156 |
+
attr = " ".join(["%s=\"%s\"" % (name, value)
|
| 157 |
+
for name, value in element.attrib.items()])
|
| 158 |
+
rv.append("<%s %s>" % (element.tag, attr))
|
| 159 |
+
if element.text:
|
| 160 |
+
rv.append(element.text)
|
| 161 |
+
|
| 162 |
+
for child in element:
|
| 163 |
+
serializeElement(child)
|
| 164 |
+
|
| 165 |
+
rv.append("</%s>" % (element.tag,))
|
| 166 |
+
|
| 167 |
+
if hasattr(element, "tail") and element.tail:
|
| 168 |
+
rv.append(element.tail)
|
| 169 |
+
|
| 170 |
+
serializeElement(element)
|
| 171 |
+
|
| 172 |
+
return "".join(rv)
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
class TreeBuilder(base.TreeBuilder):
|
| 176 |
+
documentClass = Document
|
| 177 |
+
doctypeClass = DocumentType
|
| 178 |
+
elementClass = None
|
| 179 |
+
commentClass = None
|
| 180 |
+
fragmentClass = Document
|
| 181 |
+
implementation = etree
|
| 182 |
+
|
| 183 |
+
def __init__(self, namespaceHTMLElements, fullTree=False):
|
| 184 |
+
builder = etree_builders.getETreeModule(etree, fullTree=fullTree)
|
| 185 |
+
infosetFilter = self.infosetFilter = _ihatexml.InfosetFilter(preventDoubleDashComments=True)
|
| 186 |
+
self.namespaceHTMLElements = namespaceHTMLElements
|
| 187 |
+
|
| 188 |
+
class Attributes(dict):
|
| 189 |
+
def __init__(self, element, value=None):
|
| 190 |
+
if value is None:
|
| 191 |
+
value = {}
|
| 192 |
+
self._element = element
|
| 193 |
+
dict.__init__(self, value) # pylint:disable=non-parent-init-called
|
| 194 |
+
for key, value in self.items():
|
| 195 |
+
if isinstance(key, tuple):
|
| 196 |
+
name = "{%s}%s" % (key[2], infosetFilter.coerceAttribute(key[1]))
|
| 197 |
+
else:
|
| 198 |
+
name = infosetFilter.coerceAttribute(key)
|
| 199 |
+
self._element._element.attrib[name] = value
|
| 200 |
+
|
| 201 |
+
def __setitem__(self, key, value):
|
| 202 |
+
dict.__setitem__(self, key, value)
|
| 203 |
+
if isinstance(key, tuple):
|
| 204 |
+
name = "{%s}%s" % (key[2], infosetFilter.coerceAttribute(key[1]))
|
| 205 |
+
else:
|
| 206 |
+
name = infosetFilter.coerceAttribute(key)
|
| 207 |
+
self._element._element.attrib[name] = value
|
| 208 |
+
|
| 209 |
+
class Element(builder.Element):
|
| 210 |
+
def __init__(self, name, namespace):
|
| 211 |
+
name = infosetFilter.coerceElement(name)
|
| 212 |
+
builder.Element.__init__(self, name, namespace=namespace)
|
| 213 |
+
self._attributes = Attributes(self)
|
| 214 |
+
|
| 215 |
+
def _setName(self, name):
|
| 216 |
+
self._name = infosetFilter.coerceElement(name)
|
| 217 |
+
self._element.tag = self._getETreeTag(
|
| 218 |
+
self._name, self._namespace)
|
| 219 |
+
|
| 220 |
+
def _getName(self):
|
| 221 |
+
return infosetFilter.fromXmlName(self._name)
|
| 222 |
+
|
| 223 |
+
name = property(_getName, _setName)
|
| 224 |
+
|
| 225 |
+
def _getAttributes(self):
|
| 226 |
+
return self._attributes
|
| 227 |
+
|
| 228 |
+
def _setAttributes(self, attributes):
|
| 229 |
+
self._attributes = Attributes(self, attributes)
|
| 230 |
+
|
| 231 |
+
attributes = property(_getAttributes, _setAttributes)
|
| 232 |
+
|
| 233 |
+
def insertText(self, data, insertBefore=None):
|
| 234 |
+
data = infosetFilter.coerceCharacters(data)
|
| 235 |
+
builder.Element.insertText(self, data, insertBefore)
|
| 236 |
+
|
| 237 |
+
def appendChild(self, child):
|
| 238 |
+
builder.Element.appendChild(self, child)
|
| 239 |
+
|
| 240 |
+
class Comment(builder.Comment):
|
| 241 |
+
def __init__(self, data):
|
| 242 |
+
data = infosetFilter.coerceComment(data)
|
| 243 |
+
builder.Comment.__init__(self, data)
|
| 244 |
+
|
| 245 |
+
def _setData(self, data):
|
| 246 |
+
data = infosetFilter.coerceComment(data)
|
| 247 |
+
self._element.text = data
|
| 248 |
+
|
| 249 |
+
def _getData(self):
|
| 250 |
+
return self._element.text
|
| 251 |
+
|
| 252 |
+
data = property(_getData, _setData)
|
| 253 |
+
|
| 254 |
+
self.elementClass = Element
|
| 255 |
+
self.commentClass = Comment
|
| 256 |
+
# self.fragmentClass = builder.DocumentFragment
|
| 257 |
+
base.TreeBuilder.__init__(self, namespaceHTMLElements)
|
| 258 |
+
|
| 259 |
+
def reset(self):
|
| 260 |
+
base.TreeBuilder.reset(self)
|
| 261 |
+
self.insertComment = self.insertCommentInitial
|
| 262 |
+
self.initial_comments = []
|
| 263 |
+
self.doctype = None
|
| 264 |
+
|
| 265 |
+
def testSerializer(self, element):
|
| 266 |
+
return testSerializer(element)
|
| 267 |
+
|
| 268 |
+
def getDocument(self):
|
| 269 |
+
if fullTree:
|
| 270 |
+
return self.document._elementTree
|
| 271 |
+
else:
|
| 272 |
+
return self.document._elementTree.getroot()
|
| 273 |
+
|
| 274 |
+
def getFragment(self):
|
| 275 |
+
fragment = []
|
| 276 |
+
element = self.openElements[0]._element
|
| 277 |
+
if element.text:
|
| 278 |
+
fragment.append(element.text)
|
| 279 |
+
fragment.extend(list(element))
|
| 280 |
+
if element.tail:
|
| 281 |
+
fragment.append(element.tail)
|
| 282 |
+
return fragment
|
| 283 |
+
|
| 284 |
+
def insertDoctype(self, token):
|
| 285 |
+
name = token["name"]
|
| 286 |
+
publicId = token["publicId"]
|
| 287 |
+
systemId = token["systemId"]
|
| 288 |
+
|
| 289 |
+
if not name:
|
| 290 |
+
warnings.warn("lxml cannot represent empty doctype", DataLossWarning)
|
| 291 |
+
self.doctype = None
|
| 292 |
+
else:
|
| 293 |
+
coercedName = self.infosetFilter.coerceElement(name)
|
| 294 |
+
if coercedName != name:
|
| 295 |
+
warnings.warn("lxml cannot represent non-xml doctype", DataLossWarning)
|
| 296 |
+
|
| 297 |
+
doctype = self.doctypeClass(coercedName, publicId, systemId)
|
| 298 |
+
self.doctype = doctype
|
| 299 |
+
|
| 300 |
+
def insertCommentInitial(self, data, parent=None):
|
| 301 |
+
assert parent is None or parent is self.document
|
| 302 |
+
assert self.document._elementTree is None
|
| 303 |
+
self.initial_comments.append(data)
|
| 304 |
+
|
| 305 |
+
def insertCommentMain(self, data, parent=None):
|
| 306 |
+
if (parent == self.document and
|
| 307 |
+
self.document._elementTree.getroot()[-1].tag == comment_type):
|
| 308 |
+
warnings.warn("lxml cannot represent adjacent comments beyond the root elements", DataLossWarning)
|
| 309 |
+
super(TreeBuilder, self).insertComment(data, parent)
|
| 310 |
+
|
| 311 |
+
def insertRoot(self, token):
|
| 312 |
+
# Because of the way libxml2 works, it doesn't seem to be possible to
|
| 313 |
+
# alter information like the doctype after the tree has been parsed.
|
| 314 |
+
# Therefore we need to use the built-in parser to create our initial
|
| 315 |
+
# tree, after which we can add elements like normal
|
| 316 |
+
docStr = ""
|
| 317 |
+
if self.doctype:
|
| 318 |
+
assert self.doctype.name
|
| 319 |
+
docStr += "<!DOCTYPE %s" % self.doctype.name
|
| 320 |
+
if (self.doctype.publicId is not None or
|
| 321 |
+
self.doctype.systemId is not None):
|
| 322 |
+
docStr += (' PUBLIC "%s" ' %
|
| 323 |
+
(self.infosetFilter.coercePubid(self.doctype.publicId or "")))
|
| 324 |
+
if self.doctype.systemId:
|
| 325 |
+
sysid = self.doctype.systemId
|
| 326 |
+
if sysid.find("'") >= 0 and sysid.find('"') >= 0:
|
| 327 |
+
warnings.warn("DOCTYPE system cannot contain single and double quotes", DataLossWarning)
|
| 328 |
+
sysid = sysid.replace("'", 'U00027')
|
| 329 |
+
if sysid.find("'") >= 0:
|
| 330 |
+
docStr += '"%s"' % sysid
|
| 331 |
+
else:
|
| 332 |
+
docStr += "'%s'" % sysid
|
| 333 |
+
else:
|
| 334 |
+
docStr += "''"
|
| 335 |
+
docStr += ">"
|
| 336 |
+
if self.doctype.name != token["name"]:
|
| 337 |
+
warnings.warn("lxml cannot represent doctype with a different name to the root element", DataLossWarning)
|
| 338 |
+
docStr += "<THIS_SHOULD_NEVER_APPEAR_PUBLICLY/>"
|
| 339 |
+
root = etree.fromstring(docStr)
|
| 340 |
+
|
| 341 |
+
# Append the initial comments:
|
| 342 |
+
for comment_token in self.initial_comments:
|
| 343 |
+
comment = self.commentClass(comment_token["data"])
|
| 344 |
+
root.addprevious(comment._element)
|
| 345 |
+
|
| 346 |
+
# Create the root document and add the ElementTree to it
|
| 347 |
+
self.document = self.documentClass()
|
| 348 |
+
self.document._elementTree = root.getroottree()
|
| 349 |
+
|
| 350 |
+
# Give the root element the right name
|
| 351 |
+
name = token["name"]
|
| 352 |
+
namespace = token.get("namespace", self.defaultNamespace)
|
| 353 |
+
if namespace is None:
|
| 354 |
+
etree_tag = name
|
| 355 |
+
else:
|
| 356 |
+
etree_tag = "{%s}%s" % (namespace, name)
|
| 357 |
+
root.tag = etree_tag
|
| 358 |
+
|
| 359 |
+
# Add the root element to the internal child/open data structures
|
| 360 |
+
root_element = self.elementClass(name, namespace)
|
| 361 |
+
root_element._element = root
|
| 362 |
+
self.document._childNodes.append(root_element)
|
| 363 |
+
self.openElements.append(root_element)
|
| 364 |
+
|
| 365 |
+
# Reset to the default insert comment function
|
| 366 |
+
self.insertComment = self.insertCommentMain
|
8210_A1P3-master/Lib/site-packages/html5lib/treewalkers/__init__.py
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""A collection of modules for iterating through different kinds of
|
| 2 |
+
tree, generating tokens identical to those produced by the tokenizer
|
| 3 |
+
module.
|
| 4 |
+
|
| 5 |
+
To create a tree walker for a new type of tree, you need to do
|
| 6 |
+
implement a tree walker object (called TreeWalker by convention) that
|
| 7 |
+
implements a 'serialize' method taking a tree as sole argument and
|
| 8 |
+
returning an iterator generating tokens.
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
from __future__ import absolute_import, division, unicode_literals
|
| 12 |
+
|
| 13 |
+
from .. import constants
|
| 14 |
+
from .._utils import default_etree
|
| 15 |
+
|
| 16 |
+
__all__ = ["getTreeWalker", "pprint"]
|
| 17 |
+
|
| 18 |
+
treeWalkerCache = {}
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def getTreeWalker(treeType, implementation=None, **kwargs):
|
| 22 |
+
"""Get a TreeWalker class for various types of tree with built-in support
|
| 23 |
+
|
| 24 |
+
:arg str treeType: the name of the tree type required (case-insensitive).
|
| 25 |
+
Supported values are:
|
| 26 |
+
|
| 27 |
+
* "dom": The xml.dom.minidom DOM implementation
|
| 28 |
+
* "etree": A generic walker for tree implementations exposing an
|
| 29 |
+
elementtree-like interface (known to work with ElementTree,
|
| 30 |
+
cElementTree and lxml.etree).
|
| 31 |
+
* "lxml": Optimized walker for lxml.etree
|
| 32 |
+
* "genshi": a Genshi stream
|
| 33 |
+
|
| 34 |
+
:arg implementation: A module implementing the tree type e.g.
|
| 35 |
+
xml.etree.ElementTree or cElementTree (Currently applies to the "etree"
|
| 36 |
+
tree type only).
|
| 37 |
+
|
| 38 |
+
:arg kwargs: keyword arguments passed to the etree walker--for other
|
| 39 |
+
walkers, this has no effect
|
| 40 |
+
|
| 41 |
+
:returns: a TreeWalker class
|
| 42 |
+
|
| 43 |
+
"""
|
| 44 |
+
|
| 45 |
+
treeType = treeType.lower()
|
| 46 |
+
if treeType not in treeWalkerCache:
|
| 47 |
+
if treeType == "dom":
|
| 48 |
+
from . import dom
|
| 49 |
+
treeWalkerCache[treeType] = dom.TreeWalker
|
| 50 |
+
elif treeType == "genshi":
|
| 51 |
+
from . import genshi
|
| 52 |
+
treeWalkerCache[treeType] = genshi.TreeWalker
|
| 53 |
+
elif treeType == "lxml":
|
| 54 |
+
from . import etree_lxml
|
| 55 |
+
treeWalkerCache[treeType] = etree_lxml.TreeWalker
|
| 56 |
+
elif treeType == "etree":
|
| 57 |
+
from . import etree
|
| 58 |
+
if implementation is None:
|
| 59 |
+
implementation = default_etree
|
| 60 |
+
# XXX: NEVER cache here, caching is done in the etree submodule
|
| 61 |
+
return etree.getETreeModule(implementation, **kwargs).TreeWalker
|
| 62 |
+
return treeWalkerCache.get(treeType)
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def concatenateCharacterTokens(tokens):
|
| 66 |
+
pendingCharacters = []
|
| 67 |
+
for token in tokens:
|
| 68 |
+
type = token["type"]
|
| 69 |
+
if type in ("Characters", "SpaceCharacters"):
|
| 70 |
+
pendingCharacters.append(token["data"])
|
| 71 |
+
else:
|
| 72 |
+
if pendingCharacters:
|
| 73 |
+
yield {"type": "Characters", "data": "".join(pendingCharacters)}
|
| 74 |
+
pendingCharacters = []
|
| 75 |
+
yield token
|
| 76 |
+
if pendingCharacters:
|
| 77 |
+
yield {"type": "Characters", "data": "".join(pendingCharacters)}
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def pprint(walker):
|
| 81 |
+
"""Pretty printer for tree walkers
|
| 82 |
+
|
| 83 |
+
Takes a TreeWalker instance and pretty prints the output of walking the tree.
|
| 84 |
+
|
| 85 |
+
:arg walker: a TreeWalker instance
|
| 86 |
+
|
| 87 |
+
"""
|
| 88 |
+
output = []
|
| 89 |
+
indent = 0
|
| 90 |
+
for token in concatenateCharacterTokens(walker):
|
| 91 |
+
type = token["type"]
|
| 92 |
+
if type in ("StartTag", "EmptyTag"):
|
| 93 |
+
# tag name
|
| 94 |
+
if token["namespace"] and token["namespace"] != constants.namespaces["html"]:
|
| 95 |
+
if token["namespace"] in constants.prefixes:
|
| 96 |
+
ns = constants.prefixes[token["namespace"]]
|
| 97 |
+
else:
|
| 98 |
+
ns = token["namespace"]
|
| 99 |
+
name = "%s %s" % (ns, token["name"])
|
| 100 |
+
else:
|
| 101 |
+
name = token["name"]
|
| 102 |
+
output.append("%s<%s>" % (" " * indent, name))
|
| 103 |
+
indent += 2
|
| 104 |
+
# attributes (sorted for consistent ordering)
|
| 105 |
+
attrs = token["data"]
|
| 106 |
+
for (namespace, localname), value in sorted(attrs.items()):
|
| 107 |
+
if namespace:
|
| 108 |
+
if namespace in constants.prefixes:
|
| 109 |
+
ns = constants.prefixes[namespace]
|
| 110 |
+
else:
|
| 111 |
+
ns = namespace
|
| 112 |
+
name = "%s %s" % (ns, localname)
|
| 113 |
+
else:
|
| 114 |
+
name = localname
|
| 115 |
+
output.append("%s%s=\"%s\"" % (" " * indent, name, value))
|
| 116 |
+
# self-closing
|
| 117 |
+
if type == "EmptyTag":
|
| 118 |
+
indent -= 2
|
| 119 |
+
|
| 120 |
+
elif type == "EndTag":
|
| 121 |
+
indent -= 2
|
| 122 |
+
|
| 123 |
+
elif type == "Comment":
|
| 124 |
+
output.append("%s<!-- %s -->" % (" " * indent, token["data"]))
|
| 125 |
+
|
| 126 |
+
elif type == "Doctype":
|
| 127 |
+
if token["name"]:
|
| 128 |
+
if token["publicId"]:
|
| 129 |
+
output.append("""%s<!DOCTYPE %s "%s" "%s">""" %
|
| 130 |
+
(" " * indent,
|
| 131 |
+
token["name"],
|
| 132 |
+
token["publicId"],
|
| 133 |
+
token["systemId"] if token["systemId"] else ""))
|
| 134 |
+
elif token["systemId"]:
|
| 135 |
+
output.append("""%s<!DOCTYPE %s "" "%s">""" %
|
| 136 |
+
(" " * indent,
|
| 137 |
+
token["name"],
|
| 138 |
+
token["systemId"]))
|
| 139 |
+
else:
|
| 140 |
+
output.append("%s<!DOCTYPE %s>" % (" " * indent,
|
| 141 |
+
token["name"]))
|
| 142 |
+
else:
|
| 143 |
+
output.append("%s<!DOCTYPE >" % (" " * indent,))
|
| 144 |
+
|
| 145 |
+
elif type == "Characters":
|
| 146 |
+
output.append("%s\"%s\"" % (" " * indent, token["data"]))
|
| 147 |
+
|
| 148 |
+
elif type == "SpaceCharacters":
|
| 149 |
+
assert False, "concatenateCharacterTokens should have got rid of all Space tokens"
|
| 150 |
+
|
| 151 |
+
else:
|
| 152 |
+
raise ValueError("Unknown token type, %s" % type)
|
| 153 |
+
|
| 154 |
+
return "\n".join(output)
|
8210_A1P3-master/Lib/site-packages/html5lib/treewalkers/base.py
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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ants import namespaces, voidElements, spaceCharacters
|
| 5 |
+
|
| 6 |
+
__all__ = ["DOCUMENT", "DOCTYPE", "TEXT", "ELEMENT", "COMMENT", "ENTITY", "UNKNOWN",
|
| 7 |
+
"TreeWalker", "NonRecursiveTreeWalker"]
|
| 8 |
+
|
| 9 |
+
DOCUMENT = Node.DOCUMENT_NODE
|
| 10 |
+
DOCTYPE = Node.DOCUMENT_TYPE_NODE
|
| 11 |
+
TEXT = Node.TEXT_NODE
|
| 12 |
+
ELEMENT = Node.ELEMENT_NODE
|
| 13 |
+
COMMENT = Node.COMMENT_NODE
|
| 14 |
+
ENTITY = Node.ENTITY_NODE
|
| 15 |
+
UNKNOWN = "<#UNKNOWN#>"
|
| 16 |
+
|
| 17 |
+
spaceCharacters = "".join(spaceCharacters)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class TreeWalker(object):
|
| 21 |
+
"""Walks a tree yielding tokens
|
| 22 |
+
|
| 23 |
+
Tokens are dicts that all have a ``type`` field specifying the type of the
|
| 24 |
+
token.
|
| 25 |
+
|
| 26 |
+
"""
|
| 27 |
+
def __init__(self, tree):
|
| 28 |
+
"""Creates a TreeWalker
|
| 29 |
+
|
| 30 |
+
:arg tree: the tree to walk
|
| 31 |
+
|
| 32 |
+
"""
|
| 33 |
+
self.tree = tree
|
| 34 |
+
|
| 35 |
+
def __iter__(self):
|
| 36 |
+
raise NotImplementedError
|
| 37 |
+
|
| 38 |
+
def error(self, msg):
|
| 39 |
+
"""Generates an error token with the given message
|
| 40 |
+
|
| 41 |
+
:arg msg: the error message
|
| 42 |
+
|
| 43 |
+
:returns: SerializeError token
|
| 44 |
+
|
| 45 |
+
"""
|
| 46 |
+
return {"type": "SerializeError", "data": msg}
|
| 47 |
+
|
| 48 |
+
def emptyTag(self, namespace, name, attrs, hasChildren=False):
|
| 49 |
+
"""Generates an EmptyTag token
|
| 50 |
+
|
| 51 |
+
:arg namespace: the namespace of the token--can be ``None``
|
| 52 |
+
|
| 53 |
+
:arg name: the name of the element
|
| 54 |
+
|
| 55 |
+
:arg attrs: the attributes of the element as a dict
|
| 56 |
+
|
| 57 |
+
:arg hasChildren: whether or not to yield a SerializationError because
|
| 58 |
+
this tag shouldn't have children
|
| 59 |
+
|
| 60 |
+
:returns: EmptyTag token
|
| 61 |
+
|
| 62 |
+
"""
|
| 63 |
+
yield {"type": "EmptyTag", "name": name,
|
| 64 |
+
"namespace": namespace,
|
| 65 |
+
"data": attrs}
|
| 66 |
+
if hasChildren:
|
| 67 |
+
yield self.error("Void element has children")
|
| 68 |
+
|
| 69 |
+
def startTag(self, namespace, name, attrs):
|
| 70 |
+
"""Generates a StartTag token
|
| 71 |
+
|
| 72 |
+
:arg namespace: the namespace of the token--can be ``None``
|
| 73 |
+
|
| 74 |
+
:arg name: the name of the element
|
| 75 |
+
|
| 76 |
+
:arg attrs: the attributes of the element as a dict
|
| 77 |
+
|
| 78 |
+
:returns: StartTag token
|
| 79 |
+
|
| 80 |
+
"""
|
| 81 |
+
return {"type": "StartTag",
|
| 82 |
+
"name": name,
|
| 83 |
+
"namespace": namespace,
|
| 84 |
+
"data": attrs}
|
| 85 |
+
|
| 86 |
+
def endTag(self, namespace, name):
|
| 87 |
+
"""Generates an EndTag token
|
| 88 |
+
|
| 89 |
+
:arg namespace: the namespace of the token--can be ``None``
|
| 90 |
+
|
| 91 |
+
:arg name: the name of the element
|
| 92 |
+
|
| 93 |
+
:returns: EndTag token
|
| 94 |
+
|
| 95 |
+
"""
|
| 96 |
+
return {"type": "EndTag",
|
| 97 |
+
"name": name,
|
| 98 |
+
"namespace": namespace}
|
| 99 |
+
|
| 100 |
+
def text(self, data):
|
| 101 |
+
"""Generates SpaceCharacters and Characters tokens
|
| 102 |
+
|
| 103 |
+
Depending on what's in the data, this generates one or more
|
| 104 |
+
``SpaceCharacters`` and ``Characters`` tokens.
|
| 105 |
+
|
| 106 |
+
For example:
|
| 107 |
+
|
| 108 |
+
>>> from html5lib.treewalkers.base import TreeWalker
|
| 109 |
+
>>> # Give it an empty tree just so it instantiates
|
| 110 |
+
>>> walker = TreeWalker([])
|
| 111 |
+
>>> list(walker.text(''))
|
| 112 |
+
[]
|
| 113 |
+
>>> list(walker.text(' '))
|
| 114 |
+
[{u'data': ' ', u'type': u'SpaceCharacters'}]
|
| 115 |
+
>>> list(walker.text(' abc ')) # doctest: +NORMALIZE_WHITESPACE
|
| 116 |
+
[{u'data': ' ', u'type': u'SpaceCharacters'},
|
| 117 |
+
{u'data': u'abc', u'type': u'Characters'},
|
| 118 |
+
{u'data': u' ', u'type': u'SpaceCharacters'}]
|
| 119 |
+
|
| 120 |
+
:arg data: the text data
|
| 121 |
+
|
| 122 |
+
:returns: one or more ``SpaceCharacters`` and ``Characters`` tokens
|
| 123 |
+
|
| 124 |
+
"""
|
| 125 |
+
data = data
|
| 126 |
+
middle = data.lstrip(spaceCharacters)
|
| 127 |
+
left = data[:len(data) - len(middle)]
|
| 128 |
+
if left:
|
| 129 |
+
yield {"type": "SpaceCharacters", "data": left}
|
| 130 |
+
data = middle
|
| 131 |
+
middle = data.rstrip(spaceCharacters)
|
| 132 |
+
right = data[len(middle):]
|
| 133 |
+
if middle:
|
| 134 |
+
yield {"type": "Characters", "data": middle}
|
| 135 |
+
if right:
|
| 136 |
+
yield {"type": "SpaceCharacters", "data": right}
|
| 137 |
+
|
| 138 |
+
def comment(self, data):
|
| 139 |
+
"""Generates a Comment token
|
| 140 |
+
|
| 141 |
+
:arg data: the comment
|
| 142 |
+
|
| 143 |
+
:returns: Comment token
|
| 144 |
+
|
| 145 |
+
"""
|
| 146 |
+
return {"type": "Comment", "data": data}
|
| 147 |
+
|
| 148 |
+
def doctype(self, name, publicId=None, systemId=None):
|
| 149 |
+
"""Generates a Doctype token
|
| 150 |
+
|
| 151 |
+
:arg name:
|
| 152 |
+
|
| 153 |
+
:arg publicId:
|
| 154 |
+
|
| 155 |
+
:arg systemId:
|
| 156 |
+
|
| 157 |
+
:returns: the Doctype token
|
| 158 |
+
|
| 159 |
+
"""
|
| 160 |
+
return {"type": "Doctype",
|
| 161 |
+
"name": name,
|
| 162 |
+
"publicId": publicId,
|
| 163 |
+
"systemId": systemId}
|
| 164 |
+
|
| 165 |
+
def entity(self, name):
|
| 166 |
+
"""Generates an Entity token
|
| 167 |
+
|
| 168 |
+
:arg name: the entity name
|
| 169 |
+
|
| 170 |
+
:returns: an Entity token
|
| 171 |
+
|
| 172 |
+
"""
|
| 173 |
+
return {"type": "Entity", "name": name}
|
| 174 |
+
|
| 175 |
+
def unknown(self, nodeType):
|
| 176 |
+
"""Handles unknown node types"""
|
| 177 |
+
return self.error("Unknown node type: " + nodeType)
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
class NonRecursiveTreeWalker(TreeWalker):
|
| 181 |
+
def getNodeDetails(self, node):
|
| 182 |
+
raise NotImplementedError
|
| 183 |
+
|
| 184 |
+
def getFirstChild(self, node):
|
| 185 |
+
raise NotImplementedError
|
| 186 |
+
|
| 187 |
+
def getNextSibling(self, node):
|
| 188 |
+
raise NotImplementedError
|
| 189 |
+
|
| 190 |
+
def getParentNode(self, node):
|
| 191 |
+
raise NotImplementedError
|
| 192 |
+
|
| 193 |
+
def __iter__(self):
|
| 194 |
+
currentNode = self.tree
|
| 195 |
+
while currentNode is not None:
|
| 196 |
+
details = self.getNodeDetails(currentNode)
|
| 197 |
+
type, details = details[0], details[1:]
|
| 198 |
+
hasChildren = False
|
| 199 |
+
|
| 200 |
+
if type == DOCTYPE:
|
| 201 |
+
yield self.doctype(*details)
|
| 202 |
+
|
| 203 |
+
elif type == TEXT:
|
| 204 |
+
for token in self.text(*details):
|
| 205 |
+
yield token
|
| 206 |
+
|
| 207 |
+
elif type == ELEMENT:
|
| 208 |
+
namespace, name, attributes, hasChildren = details
|
| 209 |
+
if (not namespace or namespace == namespaces["html"]) and name in voidElements:
|
| 210 |
+
for token in self.emptyTag(namespace, name, attributes,
|
| 211 |
+
hasChildren):
|
| 212 |
+
yield token
|
| 213 |
+
hasChildren = False
|
| 214 |
+
else:
|
| 215 |
+
yield self.startTag(namespace, name, attributes)
|
| 216 |
+
|
| 217 |
+
elif type == COMMENT:
|
| 218 |
+
yield self.comment(details[0])
|
| 219 |
+
|
| 220 |
+
elif type == ENTITY:
|
| 221 |
+
yield self.entity(details[0])
|
| 222 |
+
|
| 223 |
+
elif type == DOCUMENT:
|
| 224 |
+
hasChildren = True
|
| 225 |
+
|
| 226 |
+
else:
|
| 227 |
+
yield self.unknown(details[0])
|
| 228 |
+
|
| 229 |
+
if hasChildren:
|
| 230 |
+
firstChild = self.getFirstChild(currentNode)
|
| 231 |
+
else:
|
| 232 |
+
firstChild = None
|
| 233 |
+
|
| 234 |
+
if firstChild is not None:
|
| 235 |
+
currentNode = firstChild
|
| 236 |
+
else:
|
| 237 |
+
while currentNode is not None:
|
| 238 |
+
details = self.getNodeDetails(currentNode)
|
| 239 |
+
type, details = details[0], details[1:]
|
| 240 |
+
if type == ELEMENT:
|
| 241 |
+
namespace, name, attributes, hasChildren = details
|
| 242 |
+
if (namespace and namespace != namespaces["html"]) or name not in voidElements:
|
| 243 |
+
yield self.endTag(namespace, name)
|
| 244 |
+
if self.tree is currentNode:
|
| 245 |
+
currentNode = None
|
| 246 |
+
break
|
| 247 |
+
nextSibling = self.getNextSibling(currentNode)
|
| 248 |
+
if nextSibling is not None:
|
| 249 |
+
currentNode = nextSibling
|
| 250 |
+
break
|
| 251 |
+
else:
|
| 252 |
+
currentNode = self.getParentNode(currentNode)
|
8210_A1P3-master/Lib/site-packages/html5lib/treewalkers/dom.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import absolute_import, division, unicode_literals
|
| 2 |
+
|
| 3 |
+
from xml.dom import Node
|
| 4 |
+
|
| 5 |
+
from . import base
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class TreeWalker(base.NonRecursiveTreeWalker):
|
| 9 |
+
def getNodeDetails(self, node):
|
| 10 |
+
if node.nodeType == Node.DOCUMENT_TYPE_NODE:
|
| 11 |
+
return base.DOCTYPE, node.name, node.publicId, node.systemId
|
| 12 |
+
|
| 13 |
+
elif node.nodeType in (Node.TEXT_NODE, Node.CDATA_SECTION_NODE):
|
| 14 |
+
return base.TEXT, node.nodeValue
|
| 15 |
+
|
| 16 |
+
elif node.nodeType == Node.ELEMENT_NODE:
|
| 17 |
+
attrs = {}
|
| 18 |
+
for attr in list(node.attributes.keys()):
|
| 19 |
+
attr = node.getAttributeNode(attr)
|
| 20 |
+
if attr.namespaceURI:
|
| 21 |
+
attrs[(attr.namespaceURI, attr.localName)] = attr.value
|
| 22 |
+
else:
|
| 23 |
+
attrs[(None, attr.name)] = attr.value
|
| 24 |
+
return (base.ELEMENT, node.namespaceURI, node.nodeName,
|
| 25 |
+
attrs, node.hasChildNodes())
|
| 26 |
+
|
| 27 |
+
elif node.nodeType == Node.COMMENT_NODE:
|
| 28 |
+
return base.COMMENT, node.nodeValue
|
| 29 |
+
|
| 30 |
+
elif node.nodeType in (Node.DOCUMENT_NODE, Node.DOCUMENT_FRAGMENT_NODE):
|
| 31 |
+
return (base.DOCUMENT,)
|
| 32 |
+
|
| 33 |
+
else:
|
| 34 |
+
return base.UNKNOWN, node.nodeType
|
| 35 |
+
|
| 36 |
+
def getFirstChild(self, node):
|
| 37 |
+
return node.firstChild
|
| 38 |
+
|
| 39 |
+
def getNextSibling(self, node):
|
| 40 |
+
return node.nextSibling
|
| 41 |
+
|
| 42 |
+
def getParentNode(self, node):
|
| 43 |
+
return node.parentNode
|
8210_A1P3-master/Lib/site-packages/html5lib/treewalkers/etree.py
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import absolute_import, division, unicode_literals
|
| 2 |
+
|
| 3 |
+
from collections import OrderedDict
|
| 4 |
+
import re
|
| 5 |
+
|
| 6 |
+
from six import string_types
|
| 7 |
+
|
| 8 |
+
from . import base
|
| 9 |
+
from .._utils import moduleFactoryFactory
|
| 10 |
+
|
| 11 |
+
tag_regexp = re.compile("{([^}]*)}(.*)")
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def getETreeBuilder(ElementTreeImplementation):
|
| 15 |
+
ElementTree = ElementTreeImplementation
|
| 16 |
+
ElementTreeCommentType = ElementTree.Comment("asd").tag
|
| 17 |
+
|
| 18 |
+
class TreeWalker(base.NonRecursiveTreeWalker): # pylint:disable=unused-variable
|
| 19 |
+
"""Given the particular ElementTree representation, this implementation,
|
| 20 |
+
to avoid using recursion, returns "nodes" as tuples with the following
|
| 21 |
+
content:
|
| 22 |
+
|
| 23 |
+
1. The current element
|
| 24 |
+
|
| 25 |
+
2. The index of the element relative to its parent
|
| 26 |
+
|
| 27 |
+
3. A stack of ancestor elements
|
| 28 |
+
|
| 29 |
+
4. A flag "text", "tail" or None to indicate if the current node is a
|
| 30 |
+
text node; either the text or tail of the current element (1)
|
| 31 |
+
"""
|
| 32 |
+
def getNodeDetails(self, node):
|
| 33 |
+
if isinstance(node, tuple): # It might be the root Element
|
| 34 |
+
elt, _, _, flag = node
|
| 35 |
+
if flag in ("text", "tail"):
|
| 36 |
+
return base.TEXT, getattr(elt, flag)
|
| 37 |
+
else:
|
| 38 |
+
node = elt
|
| 39 |
+
|
| 40 |
+
if not(hasattr(node, "tag")):
|
| 41 |
+
node = node.getroot()
|
| 42 |
+
|
| 43 |
+
if node.tag in ("DOCUMENT_ROOT", "DOCUMENT_FRAGMENT"):
|
| 44 |
+
return (base.DOCUMENT,)
|
| 45 |
+
|
| 46 |
+
elif node.tag == "<!DOCTYPE>":
|
| 47 |
+
return (base.DOCTYPE, node.text,
|
| 48 |
+
node.get("publicId"), node.get("systemId"))
|
| 49 |
+
|
| 50 |
+
elif node.tag == ElementTreeCommentType:
|
| 51 |
+
return base.COMMENT, node.text
|
| 52 |
+
|
| 53 |
+
else:
|
| 54 |
+
assert isinstance(node.tag, string_types), type(node.tag)
|
| 55 |
+
# This is assumed to be an ordinary element
|
| 56 |
+
match = tag_regexp.match(node.tag)
|
| 57 |
+
if match:
|
| 58 |
+
namespace, tag = match.groups()
|
| 59 |
+
else:
|
| 60 |
+
namespace = None
|
| 61 |
+
tag = node.tag
|
| 62 |
+
attrs = OrderedDict()
|
| 63 |
+
for name, value in list(node.attrib.items()):
|
| 64 |
+
match = tag_regexp.match(name)
|
| 65 |
+
if match:
|
| 66 |
+
attrs[(match.group(1), match.group(2))] = value
|
| 67 |
+
else:
|
| 68 |
+
attrs[(None, name)] = value
|
| 69 |
+
return (base.ELEMENT, namespace, tag,
|
| 70 |
+
attrs, len(node) or node.text)
|
| 71 |
+
|
| 72 |
+
def getFirstChild(self, node):
|
| 73 |
+
if isinstance(node, tuple):
|
| 74 |
+
element, key, parents, flag = node
|
| 75 |
+
else:
|
| 76 |
+
element, key, parents, flag = node, None, [], None
|
| 77 |
+
|
| 78 |
+
if flag in ("text", "tail"):
|
| 79 |
+
return None
|
| 80 |
+
else:
|
| 81 |
+
if element.text:
|
| 82 |
+
return element, key, parents, "text"
|
| 83 |
+
elif len(element):
|
| 84 |
+
parents.append(element)
|
| 85 |
+
return element[0], 0, parents, None
|
| 86 |
+
else:
|
| 87 |
+
return None
|
| 88 |
+
|
| 89 |
+
def getNextSibling(self, node):
|
| 90 |
+
if isinstance(node, tuple):
|
| 91 |
+
element, key, parents, flag = node
|
| 92 |
+
else:
|
| 93 |
+
return None
|
| 94 |
+
|
| 95 |
+
if flag == "text":
|
| 96 |
+
if len(element):
|
| 97 |
+
parents.append(element)
|
| 98 |
+
return element[0], 0, parents, None
|
| 99 |
+
else:
|
| 100 |
+
return None
|
| 101 |
+
else:
|
| 102 |
+
if element.tail and flag != "tail":
|
| 103 |
+
return element, key, parents, "tail"
|
| 104 |
+
elif key < len(parents[-1]) - 1:
|
| 105 |
+
return parents[-1][key + 1], key + 1, parents, None
|
| 106 |
+
else:
|
| 107 |
+
return None
|
| 108 |
+
|
| 109 |
+
def getParentNode(self, node):
|
| 110 |
+
if isinstance(node, tuple):
|
| 111 |
+
element, key, parents, flag = node
|
| 112 |
+
else:
|
| 113 |
+
return None
|
| 114 |
+
|
| 115 |
+
if flag == "text":
|
| 116 |
+
if not parents:
|
| 117 |
+
return element
|
| 118 |
+
else:
|
| 119 |
+
return element, key, parents, None
|
| 120 |
+
else:
|
| 121 |
+
parent = parents.pop()
|
| 122 |
+
if not parents:
|
| 123 |
+
return parent
|
| 124 |
+
else:
|
| 125 |
+
assert list(parents[-1]).count(parent) == 1
|
| 126 |
+
return parent, list(parents[-1]).index(parent), parents, None
|
| 127 |
+
|
| 128 |
+
return locals()
|
| 129 |
+
|
| 130 |
+
getETreeModule = moduleFactoryFactory(getETreeBuilder)
|
8210_A1P3-master/Lib/site-packages/html5lib/treewalkers/etree_lxml.py
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import absolute_import, division, unicode_literals
|
| 2 |
+
from six import text_type
|
| 3 |
+
|
| 4 |
+
from lxml import etree
|
| 5 |
+
from ..treebuilders.etree import tag_regexp
|
| 6 |
+
|
| 7 |
+
from . import base
|
| 8 |
+
|
| 9 |
+
from .. import _ihatexml
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def ensure_str(s):
|
| 13 |
+
if s is None:
|
| 14 |
+
return None
|
| 15 |
+
elif isinstance(s, text_type):
|
| 16 |
+
return s
|
| 17 |
+
else:
|
| 18 |
+
return s.decode("ascii", "strict")
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class Root(object):
|
| 22 |
+
def __init__(self, et):
|
| 23 |
+
self.elementtree = et
|
| 24 |
+
self.children = []
|
| 25 |
+
|
| 26 |
+
try:
|
| 27 |
+
if et.docinfo.internalDTD:
|
| 28 |
+
self.children.append(Doctype(self,
|
| 29 |
+
ensure_str(et.docinfo.root_name),
|
| 30 |
+
ensure_str(et.docinfo.public_id),
|
| 31 |
+
ensure_str(et.docinfo.system_url)))
|
| 32 |
+
except AttributeError:
|
| 33 |
+
pass
|
| 34 |
+
|
| 35 |
+
try:
|
| 36 |
+
node = et.getroot()
|
| 37 |
+
except AttributeError:
|
| 38 |
+
node = et
|
| 39 |
+
|
| 40 |
+
while node.getprevious() is not None:
|
| 41 |
+
node = node.getprevious()
|
| 42 |
+
while node is not None:
|
| 43 |
+
self.children.append(node)
|
| 44 |
+
node = node.getnext()
|
| 45 |
+
|
| 46 |
+
self.text = None
|
| 47 |
+
self.tail = None
|
| 48 |
+
|
| 49 |
+
def __getitem__(self, key):
|
| 50 |
+
return self.children[key]
|
| 51 |
+
|
| 52 |
+
def getnext(self):
|
| 53 |
+
return None
|
| 54 |
+
|
| 55 |
+
def __len__(self):
|
| 56 |
+
return 1
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
class Doctype(object):
|
| 60 |
+
def __init__(self, root_node, name, public_id, system_id):
|
| 61 |
+
self.root_node = root_node
|
| 62 |
+
self.name = name
|
| 63 |
+
self.public_id = public_id
|
| 64 |
+
self.system_id = system_id
|
| 65 |
+
|
| 66 |
+
self.text = None
|
| 67 |
+
self.tail = None
|
| 68 |
+
|
| 69 |
+
def getnext(self):
|
| 70 |
+
return self.root_node.children[1]
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
class FragmentRoot(Root):
|
| 74 |
+
def __init__(self, children):
|
| 75 |
+
self.children = [FragmentWrapper(self, child) for child in children]
|
| 76 |
+
self.text = self.tail = None
|
| 77 |
+
|
| 78 |
+
def getnext(self):
|
| 79 |
+
return None
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
class FragmentWrapper(object):
|
| 83 |
+
def __init__(self, fragment_root, obj):
|
| 84 |
+
self.root_node = fragment_root
|
| 85 |
+
self.obj = obj
|
| 86 |
+
if hasattr(self.obj, 'text'):
|
| 87 |
+
self.text = ensure_str(self.obj.text)
|
| 88 |
+
else:
|
| 89 |
+
self.text = None
|
| 90 |
+
if hasattr(self.obj, 'tail'):
|
| 91 |
+
self.tail = ensure_str(self.obj.tail)
|
| 92 |
+
else:
|
| 93 |
+
self.tail = None
|
| 94 |
+
|
| 95 |
+
def __getattr__(self, name):
|
| 96 |
+
return getattr(self.obj, name)
|
| 97 |
+
|
| 98 |
+
def getnext(self):
|
| 99 |
+
siblings = self.root_node.children
|
| 100 |
+
idx = siblings.index(self)
|
| 101 |
+
if idx < len(siblings) - 1:
|
| 102 |
+
return siblings[idx + 1]
|
| 103 |
+
else:
|
| 104 |
+
return None
|
| 105 |
+
|
| 106 |
+
def __getitem__(self, key):
|
| 107 |
+
return self.obj[key]
|
| 108 |
+
|
| 109 |
+
def __bool__(self):
|
| 110 |
+
return bool(self.obj)
|
| 111 |
+
|
| 112 |
+
def getparent(self):
|
| 113 |
+
return None
|
| 114 |
+
|
| 115 |
+
def __str__(self):
|
| 116 |
+
return str(self.obj)
|
| 117 |
+
|
| 118 |
+
def __unicode__(self):
|
| 119 |
+
return str(self.obj)
|
| 120 |
+
|
| 121 |
+
def __len__(self):
|
| 122 |
+
return len(self.obj)
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
class TreeWalker(base.NonRecursiveTreeWalker):
|
| 126 |
+
def __init__(self, tree):
|
| 127 |
+
# pylint:disable=redefined-variable-type
|
| 128 |
+
if isinstance(tree, list):
|
| 129 |
+
self.fragmentChildren = set(tree)
|
| 130 |
+
tree = FragmentRoot(tree)
|
| 131 |
+
else:
|
| 132 |
+
self.fragmentChildren = set()
|
| 133 |
+
tree = Root(tree)
|
| 134 |
+
base.NonRecursiveTreeWalker.__init__(self, tree)
|
| 135 |
+
self.filter = _ihatexml.InfosetFilter()
|
| 136 |
+
|
| 137 |
+
def getNodeDetails(self, node):
|
| 138 |
+
if isinstance(node, tuple): # Text node
|
| 139 |
+
node, key = node
|
| 140 |
+
assert key in ("text", "tail"), "Text nodes are text or tail, found %s" % key
|
| 141 |
+
return base.TEXT, ensure_str(getattr(node, key))
|
| 142 |
+
|
| 143 |
+
elif isinstance(node, Root):
|
| 144 |
+
return (base.DOCUMENT,)
|
| 145 |
+
|
| 146 |
+
elif isinstance(node, Doctype):
|
| 147 |
+
return base.DOCTYPE, node.name, node.public_id, node.system_id
|
| 148 |
+
|
| 149 |
+
elif isinstance(node, FragmentWrapper) and not hasattr(node, "tag"):
|
| 150 |
+
return base.TEXT, ensure_str(node.obj)
|
| 151 |
+
|
| 152 |
+
elif node.tag == etree.Comment:
|
| 153 |
+
return base.COMMENT, ensure_str(node.text)
|
| 154 |
+
|
| 155 |
+
elif node.tag == etree.Entity:
|
| 156 |
+
return base.ENTITY, ensure_str(node.text)[1:-1] # strip &;
|
| 157 |
+
|
| 158 |
+
else:
|
| 159 |
+
# This is assumed to be an ordinary element
|
| 160 |
+
match = tag_regexp.match(ensure_str(node.tag))
|
| 161 |
+
if match:
|
| 162 |
+
namespace, tag = match.groups()
|
| 163 |
+
else:
|
| 164 |
+
namespace = None
|
| 165 |
+
tag = ensure_str(node.tag)
|
| 166 |
+
attrs = {}
|
| 167 |
+
for name, value in list(node.attrib.items()):
|
| 168 |
+
name = ensure_str(name)
|
| 169 |
+
value = ensure_str(value)
|
| 170 |
+
match = tag_regexp.match(name)
|
| 171 |
+
if match:
|
| 172 |
+
attrs[(match.group(1), match.group(2))] = value
|
| 173 |
+
else:
|
| 174 |
+
attrs[(None, name)] = value
|
| 175 |
+
return (base.ELEMENT, namespace, self.filter.fromXmlName(tag),
|
| 176 |
+
attrs, len(node) > 0 or node.text)
|
| 177 |
+
|
| 178 |
+
def getFirstChild(self, node):
|
| 179 |
+
assert not isinstance(node, tuple), "Text nodes have no children"
|
| 180 |
+
|
| 181 |
+
assert len(node) or node.text, "Node has no children"
|
| 182 |
+
if node.text:
|
| 183 |
+
return (node, "text")
|
| 184 |
+
else:
|
| 185 |
+
return node[0]
|
| 186 |
+
|
| 187 |
+
def getNextSibling(self, node):
|
| 188 |
+
if isinstance(node, tuple): # Text node
|
| 189 |
+
node, key = node
|
| 190 |
+
assert key in ("text", "tail"), "Text nodes are text or tail, found %s" % key
|
| 191 |
+
if key == "text":
|
| 192 |
+
# XXX: we cannot use a "bool(node) and node[0] or None" construct here
|
| 193 |
+
# because node[0] might evaluate to False if it has no child element
|
| 194 |
+
if len(node):
|
| 195 |
+
return node[0]
|
| 196 |
+
else:
|
| 197 |
+
return None
|
| 198 |
+
else: # tail
|
| 199 |
+
return node.getnext()
|
| 200 |
+
|
| 201 |
+
return (node, "tail") if node.tail else node.getnext()
|
| 202 |
+
|
| 203 |
+
def getParentNode(self, node):
|
| 204 |
+
if isinstance(node, tuple): # Text node
|
| 205 |
+
node, key = node
|
| 206 |
+
assert key in ("text", "tail"), "Text nodes are text or tail, found %s" % key
|
| 207 |
+
if key == "text":
|
| 208 |
+
return node
|
| 209 |
+
# else: fallback to "normal" processing
|
| 210 |
+
elif node in self.fragmentChildren:
|
| 211 |
+
return None
|
| 212 |
+
|
| 213 |
+
return node.getparent()
|
8210_A1P3-master/Lib/site-packages/html5lib/treewalkers/genshi.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import absolute_import, division, unicode_literals
|
| 2 |
+
|
| 3 |
+
from genshi.core import QName
|
| 4 |
+
from genshi.core import START, END, XML_NAMESPACE, DOCTYPE, TEXT
|
| 5 |
+
from genshi.core import START_NS, END_NS, START_CDATA, END_CDATA, PI, COMMENT
|
| 6 |
+
|
| 7 |
+
from . import base
|
| 8 |
+
|
| 9 |
+
from ..constants import voidElements, namespaces
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class TreeWalker(base.TreeWalker):
|
| 13 |
+
def __iter__(self):
|
| 14 |
+
# Buffer the events so we can pass in the following one
|
| 15 |
+
previous = None
|
| 16 |
+
for event in self.tree:
|
| 17 |
+
if previous is not None:
|
| 18 |
+
for token in self.tokens(previous, event):
|
| 19 |
+
yield token
|
| 20 |
+
previous = event
|
| 21 |
+
|
| 22 |
+
# Don't forget the final event!
|
| 23 |
+
if previous is not None:
|
| 24 |
+
for token in self.tokens(previous, None):
|
| 25 |
+
yield token
|
| 26 |
+
|
| 27 |
+
def tokens(self, event, next):
|
| 28 |
+
kind, data, _ = event
|
| 29 |
+
if kind == START:
|
| 30 |
+
tag, attribs = data
|
| 31 |
+
name = tag.localname
|
| 32 |
+
namespace = tag.namespace
|
| 33 |
+
converted_attribs = {}
|
| 34 |
+
for k, v in attribs:
|
| 35 |
+
if isinstance(k, QName):
|
| 36 |
+
converted_attribs[(k.namespace, k.localname)] = v
|
| 37 |
+
else:
|
| 38 |
+
converted_attribs[(None, k)] = v
|
| 39 |
+
|
| 40 |
+
if namespace == namespaces["html"] and name in voidElements:
|
| 41 |
+
for token in self.emptyTag(namespace, name, converted_attribs,
|
| 42 |
+
not next or next[0] != END or
|
| 43 |
+
next[1] != tag):
|
| 44 |
+
yield token
|
| 45 |
+
else:
|
| 46 |
+
yield self.startTag(namespace, name, converted_attribs)
|
| 47 |
+
|
| 48 |
+
elif kind == END:
|
| 49 |
+
name = data.localname
|
| 50 |
+
namespace = data.namespace
|
| 51 |
+
if namespace != namespaces["html"] or name not in voidElements:
|
| 52 |
+
yield self.endTag(namespace, name)
|
| 53 |
+
|
| 54 |
+
elif kind == COMMENT:
|
| 55 |
+
yield self.comment(data)
|
| 56 |
+
|
| 57 |
+
elif kind == TEXT:
|
| 58 |
+
for token in self.text(data):
|
| 59 |
+
yield token
|
| 60 |
+
|
| 61 |
+
elif kind == DOCTYPE:
|
| 62 |
+
yield self.doctype(*data)
|
| 63 |
+
|
| 64 |
+
elif kind in (XML_NAMESPACE, DOCTYPE, START_NS, END_NS,
|
| 65 |
+
START_CDATA, END_CDATA, PI):
|
| 66 |
+
pass
|
| 67 |
+
|
| 68 |
+
else:
|
| 69 |
+
yield self.unknown(kind)
|
8210_A1P3-master/Lib/site-packages/mathfilters/templatetags/mathfilters.py
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
from __future__ import print_function, division, absolute_import, unicode_literals
|
| 3 |
+
|
| 4 |
+
import logging
|
| 5 |
+
try:
|
| 6 |
+
from cdecimal import Decimal
|
| 7 |
+
except ImportError:
|
| 8 |
+
from decimal import Decimal
|
| 9 |
+
|
| 10 |
+
from django.template import Library
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
register = Library()
|
| 14 |
+
logger = logging.getLogger(__name__)
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def valid_numeric(arg):
|
| 18 |
+
if isinstance(arg, (int, float, Decimal)):
|
| 19 |
+
return arg
|
| 20 |
+
try:
|
| 21 |
+
return int(arg)
|
| 22 |
+
except ValueError:
|
| 23 |
+
return float(arg)
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def handle_float_decimal_combinations(value, arg, operation):
|
| 27 |
+
if isinstance(value, float) and isinstance(arg, Decimal):
|
| 28 |
+
logger.warning('Unsafe operation: {0!r} {1} {2!r}.'.format(value, operation, arg))
|
| 29 |
+
value = Decimal(str(value))
|
| 30 |
+
if isinstance(value, Decimal) and isinstance(arg, float):
|
| 31 |
+
logger.warning('Unsafe operation: {0!r} {1} {2!r}.'.format(value, operation, arg))
|
| 32 |
+
arg = Decimal(str(arg))
|
| 33 |
+
return value, arg
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
@register.filter
|
| 37 |
+
def sub(value, arg):
|
| 38 |
+
"""Subtract the arg from the value."""
|
| 39 |
+
try:
|
| 40 |
+
nvalue, narg = handle_float_decimal_combinations(
|
| 41 |
+
valid_numeric(value), valid_numeric(arg), '-')
|
| 42 |
+
return nvalue - narg
|
| 43 |
+
except (ValueError, TypeError):
|
| 44 |
+
try:
|
| 45 |
+
return value - arg
|
| 46 |
+
except Exception:
|
| 47 |
+
return ''
|
| 48 |
+
sub.is_safe = False
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
@register.filter
|
| 52 |
+
def mul(value, arg):
|
| 53 |
+
"""Multiply the arg with the value."""
|
| 54 |
+
try:
|
| 55 |
+
nvalue, narg = handle_float_decimal_combinations(
|
| 56 |
+
valid_numeric(value), valid_numeric(arg), '*')
|
| 57 |
+
return nvalue * narg
|
| 58 |
+
except (ValueError, TypeError):
|
| 59 |
+
try:
|
| 60 |
+
return value * arg
|
| 61 |
+
except Exception:
|
| 62 |
+
return ''
|
| 63 |
+
mul.is_safe = False
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
@register.filter
|
| 67 |
+
def div(value, arg):
|
| 68 |
+
"""Divide the arg by the value."""
|
| 69 |
+
try:
|
| 70 |
+
nvalue, narg = handle_float_decimal_combinations(
|
| 71 |
+
valid_numeric(value), valid_numeric(arg), '/')
|
| 72 |
+
return nvalue / narg
|
| 73 |
+
except (ValueError, TypeError):
|
| 74 |
+
try:
|
| 75 |
+
return value / arg
|
| 76 |
+
except Exception:
|
| 77 |
+
return ''
|
| 78 |
+
div.is_safe = False
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
@register.filter
|
| 82 |
+
def intdiv(value, arg):
|
| 83 |
+
"""Divide the arg by the value. Use integer (floor) division."""
|
| 84 |
+
try:
|
| 85 |
+
nvalue, narg = handle_float_decimal_combinations(
|
| 86 |
+
valid_numeric(value), valid_numeric(arg), '//')
|
| 87 |
+
return nvalue // narg
|
| 88 |
+
except (ValueError, TypeError):
|
| 89 |
+
try:
|
| 90 |
+
return value // arg
|
| 91 |
+
except Exception:
|
| 92 |
+
return ''
|
| 93 |
+
intdiv.is_safe = False
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
@register.filter(name='abs')
|
| 97 |
+
def absolute(value):
|
| 98 |
+
"""Return the absolute value."""
|
| 99 |
+
try:
|
| 100 |
+
return abs(valid_numeric(value))
|
| 101 |
+
except (ValueError, TypeError):
|
| 102 |
+
try:
|
| 103 |
+
return abs(value)
|
| 104 |
+
except Exception:
|
| 105 |
+
return ''
|
| 106 |
+
absolute.is_safe = False
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
@register.filter
|
| 110 |
+
def mod(value, arg):
|
| 111 |
+
"""Return the modulo value."""
|
| 112 |
+
try:
|
| 113 |
+
nvalue, narg = handle_float_decimal_combinations(
|
| 114 |
+
valid_numeric(value), valid_numeric(arg), '%')
|
| 115 |
+
return nvalue % narg
|
| 116 |
+
except (ValueError, TypeError):
|
| 117 |
+
try:
|
| 118 |
+
return value % arg
|
| 119 |
+
except Exception:
|
| 120 |
+
return ''
|
| 121 |
+
mod.is_safe = False
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
@register.filter(name='addition')
|
| 125 |
+
def addition(value, arg):
|
| 126 |
+
"""Float-friendly replacement for Django's built-in `add` filter."""
|
| 127 |
+
try:
|
| 128 |
+
nvalue, narg = handle_float_decimal_combinations(
|
| 129 |
+
valid_numeric(value), valid_numeric(arg), '+')
|
| 130 |
+
return nvalue + narg
|
| 131 |
+
except (ValueError, TypeError):
|
| 132 |
+
try:
|
| 133 |
+
return value + arg
|
| 134 |
+
except Exception:
|
| 135 |
+
return ''
|
| 136 |
+
addition.is_safe = False
|
8210_A1P3-master/Lib/site-packages/mathfilters/tests.py
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
from __future__ import print_function, division, absolute_import, unicode_literals
|
| 3 |
+
|
| 4 |
+
import unittest
|
| 5 |
+
import logging
|
| 6 |
+
try:
|
| 7 |
+
from cdecimal import Decimal
|
| 8 |
+
except ImportError:
|
| 9 |
+
from decimal import Decimal
|
| 10 |
+
|
| 11 |
+
from templatetags import mathfilters
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
logging.basicConfig(level=logging.ERROR)
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
class NumericConverterTest(unittest.TestCase):
|
| 18 |
+
|
| 19 |
+
def test_string(self):
|
| 20 |
+
self.assertEqual(13, mathfilters.valid_numeric('13'))
|
| 21 |
+
self.assertEqual(-13, mathfilters.valid_numeric('-13'))
|
| 22 |
+
self.assertEqual(13.3, mathfilters.valid_numeric('13.3'))
|
| 23 |
+
self.assertEqual(-13.3, mathfilters.valid_numeric('-13.3'))
|
| 24 |
+
|
| 25 |
+
def test_int(self):
|
| 26 |
+
self.assertEqual(13, mathfilters.valid_numeric(13))
|
| 27 |
+
self.assertEqual(-13, mathfilters.valid_numeric(-13))
|
| 28 |
+
|
| 29 |
+
def test_float(self):
|
| 30 |
+
self.assertEqual(13.3, mathfilters.valid_numeric(13.3))
|
| 31 |
+
self.assertEqual(-13.3, mathfilters.valid_numeric(-13.3))
|
| 32 |
+
|
| 33 |
+
def test_decimal(self):
|
| 34 |
+
self.assertEqual(Decimal('2.3'), mathfilters.valid_numeric(Decimal('2.3')))
|
| 35 |
+
self.assertEqual(Decimal('-2.3'), mathfilters.valid_numeric(Decimal('-2.3')))
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
class DecimalFloatHandlerTest(unittest.TestCase):
|
| 39 |
+
|
| 40 |
+
def test_int_float(self):
|
| 41 |
+
a, b = mathfilters.handle_float_decimal_combinations(1, 2.0, '+')
|
| 42 |
+
self.assertTrue(isinstance(a, int), 'Type is {0}'.format(type(a)))
|
| 43 |
+
self.assertTrue(isinstance(b, float), 'Type is {0}'.format(type(b)))
|
| 44 |
+
|
| 45 |
+
def test_float_float(self):
|
| 46 |
+
a, b = mathfilters.handle_float_decimal_combinations(1.0, 2.0, '+')
|
| 47 |
+
self.assertTrue(isinstance(a, float), 'Type is {0}'.format(type(a)))
|
| 48 |
+
self.assertTrue(isinstance(b, float), 'Type is {0}'.format(type(b)))
|
| 49 |
+
|
| 50 |
+
def test_float_decimal(self):
|
| 51 |
+
a, b = mathfilters.handle_float_decimal_combinations(1.0, Decimal('2.0'), '+')
|
| 52 |
+
self.assertTrue(isinstance(a, Decimal), 'Type is {0}'.format(type(a)))
|
| 53 |
+
self.assertTrue(isinstance(b, Decimal), 'Type is {0}'.format(type(b)))
|
| 54 |
+
|
| 55 |
+
def test_decimal_float(self):
|
| 56 |
+
a, b = mathfilters.handle_float_decimal_combinations(Decimal('2.0'), 1.0, '+')
|
| 57 |
+
self.assertTrue(isinstance(a, Decimal), 'Type is {0}'.format(type(a)))
|
| 58 |
+
self.assertTrue(isinstance(b, Decimal), 'Type is {0}'.format(type(b)))
|
| 59 |
+
|
| 60 |
+
def test_decimal_int(self):
|
| 61 |
+
a, b = mathfilters.handle_float_decimal_combinations(Decimal('2.0'), 1, '+')
|
| 62 |
+
self.assertTrue(isinstance(a, Decimal), 'Type is {0}'.format(type(a)))
|
| 63 |
+
self.assertTrue(isinstance(b, int), 'Type is {0}'.format(type(b)))
|
| 64 |
+
|
| 65 |
+
def test_decimal_decimal(self):
|
| 66 |
+
a, b = mathfilters.handle_float_decimal_combinations(Decimal('2.0'), Decimal('1.0'), '+')
|
| 67 |
+
self.assertTrue(isinstance(a, Decimal), 'Type is {0}'.format(type(a)))
|
| 68 |
+
self.assertTrue(isinstance(b, Decimal), 'Type is {0}'.format(type(b)))
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
class SubtractionTest(unittest.TestCase):
|
| 72 |
+
|
| 73 |
+
def test_positive(self):
|
| 74 |
+
self.assertEqual(3, mathfilters.sub('7', '4'))
|
| 75 |
+
|
| 76 |
+
def test_negative_result(self):
|
| 77 |
+
self.assertEqual(-20, mathfilters.sub('13', '33'))
|
| 78 |
+
|
| 79 |
+
def test_negative_minuend(self):
|
| 80 |
+
self.assertEqual(-42, mathfilters.sub('-23', '19'))
|
| 81 |
+
|
| 82 |
+
def test_negative_subtrahend(self):
|
| 83 |
+
self.assertEqual(6, mathfilters.sub('5', '-1'))
|
| 84 |
+
|
| 85 |
+
def test_float(self):
|
| 86 |
+
self.assertEqual(1.5, mathfilters.sub('-0.5', '-2'))
|
| 87 |
+
|
| 88 |
+
def test_decimal_decimal(self):
|
| 89 |
+
val1 = Decimal('9.9')
|
| 90 |
+
val2 = Decimal('6.6')
|
| 91 |
+
self.assertEqual(Decimal('3.3'), mathfilters.sub(val1, val2))
|
| 92 |
+
|
| 93 |
+
def test_decimal_int(self):
|
| 94 |
+
val1 = Decimal('9.999')
|
| 95 |
+
val2 = 9
|
| 96 |
+
self.assertEqual(Decimal('0.999'), mathfilters.sub(val1, val2))
|
| 97 |
+
|
| 98 |
+
def test_float_decimal(self):
|
| 99 |
+
"""Regression test for issue #3."""
|
| 100 |
+
result = mathfilters.sub('201.7', Decimal('3.1'))
|
| 101 |
+
self.assertTrue(198 < result < 199, repr(result))
|
| 102 |
+
|
| 103 |
+
def test_decimal_float(self):
|
| 104 |
+
"""Regression test for issue #3."""
|
| 105 |
+
result = mathfilters.sub(Decimal('201.7'), '3.1')
|
| 106 |
+
self.assertTrue(198 < result < 199, repr(result))
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
class MultiplicationTest(unittest.TestCase):
|
| 110 |
+
|
| 111 |
+
def test_positive(self):
|
| 112 |
+
self.assertEqual(12, mathfilters.mul('3', '4'))
|
| 113 |
+
|
| 114 |
+
def test_negative1(self):
|
| 115 |
+
self.assertEqual(-10, mathfilters.mul('2', '-5'))
|
| 116 |
+
|
| 117 |
+
def test_negative2(self):
|
| 118 |
+
self.assertEqual(-10, mathfilters.mul('-2', '5'))
|
| 119 |
+
|
| 120 |
+
def test_negative3(self):
|
| 121 |
+
self.assertEqual(10, mathfilters.mul('-2', '-5'))
|
| 122 |
+
|
| 123 |
+
def test_float(self):
|
| 124 |
+
self.assertEqual(4.2, mathfilters.mul('2.1', '2'))
|
| 125 |
+
|
| 126 |
+
def test_decimal_decimal(self):
|
| 127 |
+
val1 = Decimal('3.3')
|
| 128 |
+
val2 = Decimal('3')
|
| 129 |
+
self.assertEqual(Decimal('9.9'), mathfilters.mul(val1, val2))
|
| 130 |
+
|
| 131 |
+
def test_decimal_int(self):
|
| 132 |
+
val1 = Decimal('3.3')
|
| 133 |
+
val2 = 3
|
| 134 |
+
self.assertEqual(Decimal('9.9'), mathfilters.mul(val1, val2))
|
| 135 |
+
|
| 136 |
+
def test_float_decimal(self):
|
| 137 |
+
"""Regression test for issue #3."""
|
| 138 |
+
result = mathfilters.mul('2.2', Decimal('3.1'))
|
| 139 |
+
self.assertTrue(6 < result < 7, repr(result))
|
| 140 |
+
|
| 141 |
+
def test_decimal_float(self):
|
| 142 |
+
"""Regression test for issue #3."""
|
| 143 |
+
result = mathfilters.mul(Decimal('2.2'), '3.1')
|
| 144 |
+
self.assertTrue(6 < result < 7, repr(result))
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
class DivisionTest(unittest.TestCase):
|
| 148 |
+
|
| 149 |
+
def test_positive(self):
|
| 150 |
+
self.assertEqual(3, mathfilters.div('12', '4'))
|
| 151 |
+
|
| 152 |
+
def test_negative1(self):
|
| 153 |
+
self.assertEqual(-2, mathfilters.div('10', '-5'))
|
| 154 |
+
|
| 155 |
+
def test_negative2(self):
|
| 156 |
+
self.assertEqual(-2, mathfilters.div('-10', '5'))
|
| 157 |
+
|
| 158 |
+
def test_negative3(self):
|
| 159 |
+
self.assertEqual(2, mathfilters.div('-10', '-5'))
|
| 160 |
+
|
| 161 |
+
def test_float1(self):
|
| 162 |
+
self.assertEqual(8.5, mathfilters.div('27.2', '3.2'))
|
| 163 |
+
|
| 164 |
+
def test_decimal_decimal(self):
|
| 165 |
+
val1 = Decimal('9.9')
|
| 166 |
+
val2 = Decimal('3.3')
|
| 167 |
+
self.assertEqual(Decimal('3'), mathfilters.div(val1, val2))
|
| 168 |
+
|
| 169 |
+
def test_decimal_int(self):
|
| 170 |
+
val1 = Decimal('9.9')
|
| 171 |
+
val2 = 3
|
| 172 |
+
self.assertEqual(Decimal('3.3'), mathfilters.div(val1, val2))
|
| 173 |
+
|
| 174 |
+
def test_float_decimal(self):
|
| 175 |
+
"""Regression test for issue #3."""
|
| 176 |
+
result = mathfilters.div('201.7', Decimal('3.1'))
|
| 177 |
+
self.assertTrue(65 < result < 66, repr(result))
|
| 178 |
+
|
| 179 |
+
def test_decimal_float(self):
|
| 180 |
+
"""Regression test for issue #3."""
|
| 181 |
+
result = mathfilters.div(Decimal('201.7'), '3.1')
|
| 182 |
+
self.assertTrue(65 < result < 66, repr(result))
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
class IntegerDivisionTest(unittest.TestCase):
|
| 186 |
+
|
| 187 |
+
def test_positive(self):
|
| 188 |
+
self.assertEqual(3, mathfilters.intdiv('12', '4'))
|
| 189 |
+
|
| 190 |
+
def test_negative1(self):
|
| 191 |
+
self.assertEqual(-2, mathfilters.intdiv('10', '-5'))
|
| 192 |
+
|
| 193 |
+
def test_negative2(self):
|
| 194 |
+
self.assertEqual(-2, mathfilters.intdiv('-10', '5'))
|
| 195 |
+
|
| 196 |
+
def test_negative3(self):
|
| 197 |
+
self.assertEqual(2, mathfilters.intdiv('-10', '-5'))
|
| 198 |
+
|
| 199 |
+
def test_float1(self):
|
| 200 |
+
result = mathfilters.intdiv('7', '2')
|
| 201 |
+
self.assertTrue(isinstance(result, int))
|
| 202 |
+
self.assertEqual(3, result)
|
| 203 |
+
|
| 204 |
+
def test_float2(self):
|
| 205 |
+
result = mathfilters.intdiv('27.2', '3.2')
|
| 206 |
+
self.assertTrue(isinstance(result, float))
|
| 207 |
+
self.assertEqual(8.0, result)
|
| 208 |
+
|
| 209 |
+
def test_decimal_decimal(self):
|
| 210 |
+
val1 = Decimal('7.0')
|
| 211 |
+
val2 = Decimal('2.0')
|
| 212 |
+
self.assertEqual(Decimal('3'), mathfilters.intdiv(val1, val2))
|
| 213 |
+
|
| 214 |
+
def test_decimal_int(self):
|
| 215 |
+
val1 = Decimal('9.9')
|
| 216 |
+
val2 = 3
|
| 217 |
+
self.assertEqual(Decimal('3'), mathfilters.intdiv(val1, val2))
|
| 218 |
+
|
| 219 |
+
def test_float_decimal(self):
|
| 220 |
+
"""Regression test for issue #3."""
|
| 221 |
+
result = mathfilters.intdiv('201.7', Decimal('3.1'))
|
| 222 |
+
self.assertEqual(Decimal('65'), result)
|
| 223 |
+
|
| 224 |
+
def test_decimal_float(self):
|
| 225 |
+
"""Regression test for issue #3."""
|
| 226 |
+
result = mathfilters.intdiv(Decimal('201.7'), '3.1')
|
| 227 |
+
self.assertEqual(Decimal('65'), result)
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
class AbsoluteTest(unittest.TestCase):
|
| 231 |
+
|
| 232 |
+
def test_positive(self):
|
| 233 |
+
self.assertEqual(21, mathfilters.absolute('21'))
|
| 234 |
+
|
| 235 |
+
def test_negative(self):
|
| 236 |
+
self.assertEqual(21, mathfilters.absolute('-21'))
|
| 237 |
+
|
| 238 |
+
def test_positive_float(self):
|
| 239 |
+
self.assertEqual(2.3, mathfilters.absolute('2.3'))
|
| 240 |
+
|
| 241 |
+
def test_negative_float(self):
|
| 242 |
+
self.assertEqual(2.3, mathfilters.absolute('-2.3'))
|
| 243 |
+
|
| 244 |
+
def test_positive_decimal(self):
|
| 245 |
+
self.assertEqual(Decimal('9.99'), mathfilters.absolute(Decimal('9.99')))
|
| 246 |
+
|
| 247 |
+
def test_negative_decimal(self):
|
| 248 |
+
self.assertEqual(Decimal('9.99'), mathfilters.absolute(Decimal('-9.99')))
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
class ModuloTest(unittest.TestCase):
|
| 252 |
+
|
| 253 |
+
def test_positive(self):
|
| 254 |
+
self.assertEqual(2, mathfilters.mod('12', '5'))
|
| 255 |
+
|
| 256 |
+
def test_negative(self):
|
| 257 |
+
self.assertEqual(-3, mathfilters.mod('12', '-5'))
|
| 258 |
+
|
| 259 |
+
def test_float(self):
|
| 260 |
+
self.assertEqual(3.0, mathfilters.mod('27.5', '3.5'))
|
| 261 |
+
|
| 262 |
+
def test_float_decimal(self):
|
| 263 |
+
"""Regression test for issue #3."""
|
| 264 |
+
result = mathfilters.mod('7.8', Decimal('2.2'))
|
| 265 |
+
self.assertTrue(1 < result < 2, repr(result))
|
| 266 |
+
|
| 267 |
+
def test_decimal_float(self):
|
| 268 |
+
"""Regression test for issue #3."""
|
| 269 |
+
result = mathfilters.mod(Decimal('7.8'), '2.2')
|
| 270 |
+
self.assertTrue(1 < result < 2, repr(result))
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
class AdditionTest(unittest.TestCase):
|
| 274 |
+
|
| 275 |
+
def test_positive(self):
|
| 276 |
+
self.assertEqual(11, mathfilters.addition('7', '4'))
|
| 277 |
+
|
| 278 |
+
def test_negative_negative(self):
|
| 279 |
+
self.assertEqual(-4, mathfilters.addition('-1', '-3'))
|
| 280 |
+
|
| 281 |
+
def test_negative_positive(self):
|
| 282 |
+
self.assertEqual(6, mathfilters.addition('-3', '9'))
|
| 283 |
+
|
| 284 |
+
def test_positive_negative(self):
|
| 285 |
+
self.assertEqual(4, mathfilters.addition('5', '-1'))
|
| 286 |
+
|
| 287 |
+
def test_float_int(self):
|
| 288 |
+
self.assertEqual(2.5, mathfilters.addition('0.5', '2'))
|
| 289 |
+
|
| 290 |
+
def test_decimal_decimal(self):
|
| 291 |
+
val1 = Decimal('7.3')
|
| 292 |
+
val2 = Decimal('2.7')
|
| 293 |
+
self.assertEqual(Decimal('10'), mathfilters.addition(val1, val2))
|
| 294 |
+
|
| 295 |
+
def test_decimal_int(self):
|
| 296 |
+
val1 = Decimal('1.9')
|
| 297 |
+
val2 = 4
|
| 298 |
+
self.assertEqual(Decimal('5.9'), mathfilters.addition(val1, val2))
|
| 299 |
+
|
| 300 |
+
def test_float_decimal(self):
|
| 301 |
+
result = mathfilters.addition('3.7', Decimal('11.1'))
|
| 302 |
+
self.assertEqual(Decimal('14.8'), result)
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
if __name__ == '__main__':
|
| 306 |
+
unittest.main()
|
8210_A1P3-master/Lib/site-packages/pdfrw-0.4.dist-info/DESCRIPTION.rst
ADDED
|
@@ -0,0 +1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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
==================
|
| 2 |
+
pdfrw 0.4
|
| 3 |
+
==================
|
| 4 |
+
|
| 5 |
+
:Author: Patrick Maupin
|
| 6 |
+
|
| 7 |
+
.. contents::
|
| 8 |
+
:backlinks: none
|
| 9 |
+
|
| 10 |
+
.. sectnum::
|
| 11 |
+
|
| 12 |
+
Introduction
|
| 13 |
+
============
|
| 14 |
+
|
| 15 |
+
**pdfrw** is a Python library and utility that reads and writes PDF files:
|
| 16 |
+
|
| 17 |
+
* Version 0.4 is tested and works on Python 2.6, 2.7, 3.3, 3.4, 3.5, and 3.6
|
| 18 |
+
* Operations include subsetting, merging, rotating, modifying metadata, etc.
|
| 19 |
+
* The fastest pure Python PDF parser available
|
| 20 |
+
* Has been used for years by a printer in pre-press production
|
| 21 |
+
* Can be used with rst2pdf to faithfully reproduce vector images
|
| 22 |
+
* Can be used either standalone, or in conjunction with `reportlab`__
|
| 23 |
+
to reuse existing PDFs in new ones
|
| 24 |
+
* Permissively licensed
|
| 25 |
+
|
| 26 |
+
__ http://www.reportlab.org/
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
pdfrw will faithfully reproduce vector formats without
|
| 30 |
+
rasterization, so the rst2pdf package has used pdfrw
|
| 31 |
+
for PDF and SVG images by default since March 2010.
|
| 32 |
+
|
| 33 |
+
pdfrw can also be used in conjunction with reportlab, in order
|
| 34 |
+
to re-use portions of existing PDFs in new PDFs created with
|
| 35 |
+
reportlab.
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
Examples
|
| 39 |
+
=========
|
| 40 |
+
|
| 41 |
+
The library comes with several examples that show operation both with
|
| 42 |
+
and without reportlab.
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
All examples
|
| 46 |
+
------------------
|
| 47 |
+
|
| 48 |
+
The examples directory has a few scripts which use the library.
|
| 49 |
+
Note that if these examples do not work with your PDF, you should
|
| 50 |
+
try to use pdftk to uncompress and/or unencrypt them first.
|
| 51 |
+
|
| 52 |
+
* `4up.py`__ will shrink pages down and place 4 of them on
|
| 53 |
+
each output page.
|
| 54 |
+
* `alter.py`__ shows an example of modifying metadata, without
|
| 55 |
+
altering the structure of the PDF.
|
| 56 |
+
* `booklet.py`__ shows an example of creating a 2-up output
|
| 57 |
+
suitable for printing and folding (e.g on tabloid size paper).
|
| 58 |
+
* `cat.py`__ shows an example of concatenating multiple PDFs together.
|
| 59 |
+
* `extract.py`__ will extract images and Form XObjects (embedded pages)
|
| 60 |
+
from existing PDFs to make them easier to use and refer to from
|
| 61 |
+
new PDFs (e.g. with reportlab or rst2pdf).
|
| 62 |
+
* `poster.py`__ increases the size of a PDF so it can be printed
|
| 63 |
+
as a poster.
|
| 64 |
+
* `print_two.py`__ Allows creation of 8.5 X 5.5" booklets by slicing
|
| 65 |
+
8.5 X 11" paper apart after printing.
|
| 66 |
+
* `rotate.py`__ Rotates all or selected pages in a PDF.
|
| 67 |
+
* `subset.py`__ Creates a new PDF with only a subset of pages from the
|
| 68 |
+
original.
|
| 69 |
+
* `unspread.py`__ Takes a 2-up PDF, and splits out pages.
|
| 70 |
+
* `watermark.py`__ Adds a watermark PDF image over or under all the pages
|
| 71 |
+
of a PDF.
|
| 72 |
+
* `rl1/4up.py`__ Another 4up example, using reportlab canvas for output.
|
| 73 |
+
* `rl1/booklet.py`__ Another booklet example, using reportlab canvas for
|
| 74 |
+
output.
|
| 75 |
+
* `rl1/subset.py`__ Another subsetting example, using reportlab canvas for
|
| 76 |
+
output.
|
| 77 |
+
* `rl1/platypus_pdf_template.py`__ Another watermarking example, using
|
| 78 |
+
reportlab canvas and generated output for the document. Contributed
|
| 79 |
+
by user asannes.
|
| 80 |
+
* `rl2`__ Experimental code for parsing graphics. Needs work.
|
| 81 |
+
* `subset_booklets.py`__ shows an example of creating a full printable pdf
|
| 82 |
+
version in a more professional and pratical way ( take a look at
|
| 83 |
+
http://www.wikihow.com/Bind-a-Book )
|
| 84 |
+
|
| 85 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/4up.py
|
| 86 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/alter.py
|
| 87 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/booklet.py
|
| 88 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/cat.py
|
| 89 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/extract.py
|
| 90 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/poster.py
|
| 91 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/print_two.py
|
| 92 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/rotate.py
|
| 93 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/subset.py
|
| 94 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/unspread.py
|
| 95 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/watermark.py
|
| 96 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/rl1/4up.py
|
| 97 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/rl1/booklet.py
|
| 98 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/rl1/subset.py
|
| 99 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/rl1/platypus_pdf_template.py
|
| 100 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/rl2/
|
| 101 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/subset_booklets.py
|
| 102 |
+
|
| 103 |
+
Notes on selected examples
|
| 104 |
+
------------------------------------
|
| 105 |
+
|
| 106 |
+
Reorganizing pages and placing them two-up
|
| 107 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 108 |
+
|
| 109 |
+
A printer with a fancy printer and/or a full-up copy of Acrobat can
|
| 110 |
+
easily turn your small PDF into a little booklet (for example, print 4
|
| 111 |
+
letter-sized pages on a single 11" x 17").
|
| 112 |
+
|
| 113 |
+
But that assumes several things, including that the personnel know how
|
| 114 |
+
to operate the hardware and software. `booklet.py`__ lets you turn your PDF
|
| 115 |
+
into a preformatted booklet, to give them fewer chances to mess it up.
|
| 116 |
+
|
| 117 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/booklet.py
|
| 118 |
+
|
| 119 |
+
Adding or modifying metadata
|
| 120 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 121 |
+
|
| 122 |
+
The `cat.py`__ example will accept multiple input files on the command
|
| 123 |
+
line, concatenate them and output them to output.pdf, after adding some
|
| 124 |
+
nonsensical metadata to the output PDF file.
|
| 125 |
+
|
| 126 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/cat.py
|
| 127 |
+
|
| 128 |
+
The `alter.py`__ example alters a single metadata item in a PDF,
|
| 129 |
+
and writes the result to a new PDF.
|
| 130 |
+
|
| 131 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/alter.py
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
One difference is that, since **cat** is creating a new PDF structure,
|
| 135 |
+
and **alter** is attempting to modify an existing PDF structure, the
|
| 136 |
+
PDF produced by alter (and also by watermark.py) *should* be
|
| 137 |
+
more faithful to the original (except for the desired changes).
|
| 138 |
+
|
| 139 |
+
For example, the alter.py navigation should be left intact, whereas with
|
| 140 |
+
cat.py it will be stripped.
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
Rotating and doubling
|
| 144 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 145 |
+
|
| 146 |
+
If you ever want to print something that is like a small booklet, but
|
| 147 |
+
needs to be spiral bound, you either have to do some fancy rearranging,
|
| 148 |
+
or just waste half your paper.
|
| 149 |
+
|
| 150 |
+
The `print_two.py`__ example program will, for example, make two side-by-side
|
| 151 |
+
copies each page of of your PDF on a each output sheet.
|
| 152 |
+
|
| 153 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/print_two.py
|
| 154 |
+
|
| 155 |
+
But, every other page is flipped, so that you can print double-sided and
|
| 156 |
+
the pages will line up properly and be pre-collated.
|
| 157 |
+
|
| 158 |
+
Graphics stream parsing proof of concept
|
| 159 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 160 |
+
|
| 161 |
+
The `copy.py`__ script shows a simple example of reading in a PDF, and
|
| 162 |
+
using the decodegraphics.py module to try to write the same information
|
| 163 |
+
out to a new PDF through a reportlab canvas. (If you know about reportlab,
|
| 164 |
+
you know that if you can faithfully render a PDF to a reportlab canvas, you
|
| 165 |
+
can do pretty much anything else with that PDF you want.) This kind of
|
| 166 |
+
low level manipulation should be done only if you really need to.
|
| 167 |
+
decodegraphics is really more than a proof of concept than anything
|
| 168 |
+
else. For most cases, just use the Form XObject capability, as shown in
|
| 169 |
+
the examples/rl1/booklet.py demo.
|
| 170 |
+
|
| 171 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/rl2/copy.py
|
| 172 |
+
|
| 173 |
+
pdfrw philosophy
|
| 174 |
+
==================
|
| 175 |
+
|
| 176 |
+
Core library
|
| 177 |
+
-------------
|
| 178 |
+
|
| 179 |
+
The philosophy of the library portion of pdfrw is to provide intuitive
|
| 180 |
+
functions to read, manipulate, and write PDF files. There should be
|
| 181 |
+
minimal leakage between abstraction layers, although getting useful
|
| 182 |
+
work done makes "pure" functionality separation difficult.
|
| 183 |
+
|
| 184 |
+
A key concept supported by the library is the use of Form XObjects,
|
| 185 |
+
which allow easy embedding of pieces of one PDF into another.
|
| 186 |
+
|
| 187 |
+
Addition of core support to the library is typically done carefully
|
| 188 |
+
and thoughtfully, so as not to clutter it up with too many special
|
| 189 |
+
cases.
|
| 190 |
+
|
| 191 |
+
There are a lot of incorrectly formatted PDFs floating around; support
|
| 192 |
+
for these is added in some cases. The decision is often based on what
|
| 193 |
+
acroread and okular do with the PDFs; if they can display them properly,
|
| 194 |
+
then eventually pdfrw should, too, if it is not too difficult or costly.
|
| 195 |
+
|
| 196 |
+
Contributions are welcome; one user has contributed some decompression
|
| 197 |
+
filters and the ability to process PDF 1.5 stream objects. Additional
|
| 198 |
+
functionality that would obviously be useful includes additional
|
| 199 |
+
decompression filters, the ability to process password-protected PDFs,
|
| 200 |
+
and the ability to output linearized PDFs.
|
| 201 |
+
|
| 202 |
+
Examples
|
| 203 |
+
--------
|
| 204 |
+
|
| 205 |
+
The philosophy of the examples is to provide small, easily-understood
|
| 206 |
+
examples that showcase pdfrw functionality.
|
| 207 |
+
|
| 208 |
+
|
| 209 |
+
PDF files and Python
|
| 210 |
+
======================
|
| 211 |
+
|
| 212 |
+
Introduction
|
| 213 |
+
------------
|
| 214 |
+
|
| 215 |
+
In general, PDF files conceptually map quite well to Python. The major
|
| 216 |
+
objects to think about are:
|
| 217 |
+
|
| 218 |
+
- **strings**. Most things are strings. These also often decompose
|
| 219 |
+
naturally into
|
| 220 |
+
- **lists of tokens**. Tokens can be combined to create higher-level
|
| 221 |
+
objects like
|
| 222 |
+
- **arrays** and
|
| 223 |
+
- **dictionaries** and
|
| 224 |
+
- **Contents streams** (which can be more streams of tokens)
|
| 225 |
+
|
| 226 |
+
Difficulties
|
| 227 |
+
------------
|
| 228 |
+
|
| 229 |
+
The apparent primary difficulty in mapping PDF files to Python is the
|
| 230 |
+
PDF file concept of "indirect objects." Indirect objects provide
|
| 231 |
+
the efficiency of allowing a single piece of data to be referred to
|
| 232 |
+
from more than one containing object, but probably more importantly,
|
| 233 |
+
indirect objects provide a way to get around the chicken and egg
|
| 234 |
+
problem of circular object references when mapping arbitrary data
|
| 235 |
+
structures to files. To flatten out a circular reference, an indirect
|
| 236 |
+
object is *referred to* instead of being *directly included* in another
|
| 237 |
+
object. PDF files have a global mechanism for locating indirect objects,
|
| 238 |
+
and they all have two reference numbers (a reference number and a
|
| 239 |
+
"generation" number, in case you wanted to append to the PDF file
|
| 240 |
+
rather than just rewriting the whole thing).
|
| 241 |
+
|
| 242 |
+
pdfrw automatically handles indirect references on reading in a PDF
|
| 243 |
+
file. When pdfrw encounters an indirect PDF file object, the
|
| 244 |
+
corresponding Python object it creates will have an 'indirect' attribute
|
| 245 |
+
with a value of True. When writing a PDF file, if you have created
|
| 246 |
+
arbitrary data, you just need to make sure that circular references are
|
| 247 |
+
broken up by putting an attribute named 'indirect' which evaluates to
|
| 248 |
+
True on at least one object in every cycle.
|
| 249 |
+
|
| 250 |
+
Another PDF file concept that doesn't quite map to regular Python is a
|
| 251 |
+
"stream". Streams are dictionaries which each have an associated
|
| 252 |
+
unformatted data block. pdfrw handles streams by placing a special
|
| 253 |
+
attribute on a subclassed dictionary.
|
| 254 |
+
|
| 255 |
+
Usage Model
|
| 256 |
+
-----------
|
| 257 |
+
|
| 258 |
+
The usage model for pdfrw treats most objects as strings (it takes their
|
| 259 |
+
string representation when writing them to a file). The two main
|
| 260 |
+
exceptions are the PdfArray object and the PdfDict object.
|
| 261 |
+
|
| 262 |
+
PdfArray is a subclass of list with two special features. First,
|
| 263 |
+
an 'indirect' attribute allows a PdfArray to be written out as
|
| 264 |
+
an indirect PDF object. Second, pdfrw reads files lazily, so
|
| 265 |
+
PdfArray knows about, and resolves references to other indirect
|
| 266 |
+
objects on an as-needed basis.
|
| 267 |
+
|
| 268 |
+
PdfDict is a subclass of dict that also has an indirect attribute
|
| 269 |
+
and lazy reference resolution as well. (And the subclassed
|
| 270 |
+
IndirectPdfDict has indirect automatically set True).
|
| 271 |
+
|
| 272 |
+
But PdfDict also has an optional associated stream. The stream object
|
| 273 |
+
defaults to None, but if you assign a stream to the dict, it will
|
| 274 |
+
automatically set the PDF /Length attribute for the dictionary.
|
| 275 |
+
|
| 276 |
+
Finally, since PdfDict instances are indexed by PdfName objects (which
|
| 277 |
+
always start with a /) and since most (all?) standard Adobe PdfName
|
| 278 |
+
objects use names formatted like "/CamelCase", it makes sense to allow
|
| 279 |
+
access to dictionary elements via object attribute accesses as well as
|
| 280 |
+
object index accesses. So usage of PdfDict objects is normally via
|
| 281 |
+
attribute access, although non-standard names (though still with a
|
| 282 |
+
leading slash) can be accessed via dictionary index lookup.
|
| 283 |
+
|
| 284 |
+
Reading PDFs
|
| 285 |
+
~~~~~~~~~~~~~~~
|
| 286 |
+
|
| 287 |
+
The PdfReader object is a subclass of PdfDict, which allows easy access
|
| 288 |
+
to an entire document::
|
| 289 |
+
|
| 290 |
+
>>> from pdfrw import PdfReader
|
| 291 |
+
>>> x = PdfReader('source.pdf')
|
| 292 |
+
>>> x.keys()
|
| 293 |
+
['/Info', '/Size', '/Root']
|
| 294 |
+
>>> x.Info
|
| 295 |
+
{'/Producer': '(cairo 1.8.6 (http://cairographics.org))',
|
| 296 |
+
'/Creator': '(cairo 1.8.6 (http://cairographics.org))'}
|
| 297 |
+
>>> x.Root.keys()
|
| 298 |
+
['/Type', '/Pages']
|
| 299 |
+
|
| 300 |
+
Info, Size, and Root are retrieved from the trailer of the PDF file.
|
| 301 |
+
|
| 302 |
+
In addition to the tree structure, pdfrw creates a special attribute
|
| 303 |
+
named *pages*, that is a list of all the pages in the document. pdfrw
|
| 304 |
+
creates the *pages* attribute as a simplification for the user, because
|
| 305 |
+
the PDF format allows arbitrarily complicated nested dictionaries to
|
| 306 |
+
describe the page order. Each entry in the *pages* list is the PdfDict
|
| 307 |
+
object for one of the pages in the file, in order.
|
| 308 |
+
|
| 309 |
+
::
|
| 310 |
+
|
| 311 |
+
>>> len(x.pages)
|
| 312 |
+
1
|
| 313 |
+
>>> x.pages[0]
|
| 314 |
+
{'/Parent': {'/Kids': [{...}], '/Type': '/Pages', '/Count': '1'},
|
| 315 |
+
'/Contents': {'/Length': '11260', '/Filter': None},
|
| 316 |
+
'/Resources': ... (Lots more stuff snipped)
|
| 317 |
+
>>> x.pages[0].Contents
|
| 318 |
+
{'/Length': '11260', '/Filter': None}
|
| 319 |
+
>>> x.pages[0].Contents.stream
|
| 320 |
+
'q\n1 1 1 rg /a0 gs\n0 0 0 RG 0.657436
|
| 321 |
+
w\n0 J\n0 j\n[] 0.0 d\n4 M q' ... (Lots more stuff snipped)
|
| 322 |
+
|
| 323 |
+
Writing PDFs
|
| 324 |
+
~~~~~~~~~~~~~~~
|
| 325 |
+
|
| 326 |
+
As you can see, it is quite easy to dig down into a PDF document. But
|
| 327 |
+
what about when it's time to write it out?
|
| 328 |
+
|
| 329 |
+
::
|
| 330 |
+
|
| 331 |
+
>>> from pdfrw import PdfWriter
|
| 332 |
+
>>> y = PdfWriter()
|
| 333 |
+
>>> y.addpage(x.pages[0])
|
| 334 |
+
>>> y.write('result.pdf')
|
| 335 |
+
|
| 336 |
+
That's all it takes to create a new PDF. You may still need to read the
|
| 337 |
+
`Adobe PDF reference manual`__ to figure out what needs to go *into*
|
| 338 |
+
the PDF, but at least you don't have to sweat actually building it
|
| 339 |
+
and getting the file offsets right.
|
| 340 |
+
|
| 341 |
+
__ http://www.adobe.com/devnet/acrobat/pdfs/pdf_reference_1-7.pdf
|
| 342 |
+
|
| 343 |
+
Manipulating PDFs in memory
|
| 344 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 345 |
+
|
| 346 |
+
For the most part, pdfrw tries to be agnostic about the contents of
|
| 347 |
+
PDF files, and support them as containers, but to do useful work,
|
| 348 |
+
something a little higher-level is required, so pdfrw works to
|
| 349 |
+
understand a bit about the contents of the containers. For example:
|
| 350 |
+
|
| 351 |
+
- PDF pages. pdfrw knows enough to find the pages in PDF files you read
|
| 352 |
+
in, and to write a set of pages back out to a new PDF file.
|
| 353 |
+
- Form XObjects. pdfrw can take any page or rectangle on a page, and
|
| 354 |
+
convert it to a Form XObject, suitable for use inside another PDF
|
| 355 |
+
file. It knows enough about these to perform scaling, rotation,
|
| 356 |
+
and positioning.
|
| 357 |
+
- reportlab objects. pdfrw can recursively create a set of reportlab
|
| 358 |
+
objects from its internal object format. This allows, for example,
|
| 359 |
+
Form XObjects to be used inside reportlab, so that you can reuse
|
| 360 |
+
content from an existing PDF file when building a new PDF with
|
| 361 |
+
reportlab.
|
| 362 |
+
|
| 363 |
+
There are several examples that demonstrate these features in
|
| 364 |
+
the example code directory.
|
| 365 |
+
|
| 366 |
+
Missing features
|
| 367 |
+
~~~~~~~~~~~~~~~~~~~~~~~
|
| 368 |
+
|
| 369 |
+
Even as a pure PDF container library, pdfrw comes up a bit short. It
|
| 370 |
+
does not currently support:
|
| 371 |
+
|
| 372 |
+
- Most compression/decompression filters
|
| 373 |
+
- encryption
|
| 374 |
+
|
| 375 |
+
`pdftk`__ is a wonderful command-line
|
| 376 |
+
tool that can convert your PDFs to remove encryption and compression.
|
| 377 |
+
However, in most cases, you can do a lot of useful work with PDFs
|
| 378 |
+
without actually removing compression, because only certain elements
|
| 379 |
+
inside PDFs are actually compressed.
|
| 380 |
+
|
| 381 |
+
__ https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/
|
| 382 |
+
|
| 383 |
+
Library internals
|
| 384 |
+
==================
|
| 385 |
+
|
| 386 |
+
Introduction
|
| 387 |
+
------------
|
| 388 |
+
|
| 389 |
+
**pdfrw** currently consists of 19 modules organized into a main
|
| 390 |
+
package and one sub-package.
|
| 391 |
+
|
| 392 |
+
The `__init.py__`__ module does the usual thing of importing a few
|
| 393 |
+
major attributes from some of the submodules, and the `errors.py`__
|
| 394 |
+
module supports logging and exception generation.
|
| 395 |
+
|
| 396 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/pdfrw/__init__.py
|
| 397 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/pdfrw/errors.py
|
| 398 |
+
|
| 399 |
+
|
| 400 |
+
PDF object model support
|
| 401 |
+
--------------------------
|
| 402 |
+
|
| 403 |
+
The `objects`__ sub-package contains one module for each of the
|
| 404 |
+
internal representations of the kinds of basic objects that exist
|
| 405 |
+
in a PDF file, with the `objects/__init__.py`__ module in that
|
| 406 |
+
package simply gathering them up and making them available to the
|
| 407 |
+
main pdfrw package.
|
| 408 |
+
|
| 409 |
+
One feature that all the PDF object classes have in common is the
|
| 410 |
+
inclusion of an 'indirect' attribute. If 'indirect' exists and evaluates
|
| 411 |
+
to True, then when the object is written out, it is written out as an
|
| 412 |
+
indirect object. That is to say, it is addressable in the PDF file, and
|
| 413 |
+
could be referenced by any number (including zero) of container objects.
|
| 414 |
+
This indirect object capability saves space in PDF files by allowing
|
| 415 |
+
objects such as fonts to be referenced from multiple pages, and also
|
| 416 |
+
allows PDF files to contain internal circular references. This latter
|
| 417 |
+
capability is used, for example, when each page object has a "parent"
|
| 418 |
+
object in its dictionary.
|
| 419 |
+
|
| 420 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/pdfrw/objects/
|
| 421 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/pdfrw/objects/__init__.py
|
| 422 |
+
|
| 423 |
+
Ordinary objects
|
| 424 |
+
~~~~~~~~~~~~~~~~
|
| 425 |
+
|
| 426 |
+
The `objects/pdfobject.py`__ module contains the PdfObject class, which is
|
| 427 |
+
a subclass of str, and is the catch-all object for any PDF file elements
|
| 428 |
+
that are not explicitly represented by other objects, as described below.
|
| 429 |
+
|
| 430 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/pdfrw/objects/pdfobject.py
|
| 431 |
+
|
| 432 |
+
Name objects
|
| 433 |
+
~~~~~~~~~~~~
|
| 434 |
+
|
| 435 |
+
The `objects/pdfname.py`__ module contains the PdfName singleton object,
|
| 436 |
+
which will convert a string into a PDF name by prepending a slash. It can
|
| 437 |
+
be used either by calling it or getting an attribute, e.g.::
|
| 438 |
+
|
| 439 |
+
PdfName.Rotate == PdfName('Rotate') == PdfObject('/Rotate')
|
| 440 |
+
|
| 441 |
+
In the example above, there is a slight difference between the objects
|
| 442 |
+
returned from PdfName, and the object returned from PdfObject. The
|
| 443 |
+
PdfName objects are actually objects of class "BasePdfName". This
|
| 444 |
+
is important, because only these may be used as keys in PdfDict objects.
|
| 445 |
+
|
| 446 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/pdfrw/objects/pdfname.py
|
| 447 |
+
|
| 448 |
+
String objects
|
| 449 |
+
~~~~~~~~~~~~~~
|
| 450 |
+
|
| 451 |
+
The `objects/pdfstring.py`__
|
| 452 |
+
module contains the PdfString class, which is a subclass of str that is
|
| 453 |
+
used to represent encoded strings in a PDF file. The class has encode
|
| 454 |
+
and decode methods for the strings.
|
| 455 |
+
|
| 456 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/pdfrw/objects/pdfstring.py
|
| 457 |
+
|
| 458 |
+
|
| 459 |
+
Array objects
|
| 460 |
+
~~~~~~~~~~~~~
|
| 461 |
+
|
| 462 |
+
The `objects/pdfarray.py`__
|
| 463 |
+
module contains the PdfArray class, which is a subclass of list that is
|
| 464 |
+
used to represent arrays in a PDF file. A regular list could be used
|
| 465 |
+
instead, but use of the PdfArray class allows for an indirect attribute
|
| 466 |
+
to be set, and also allows for proxying of unresolved indirect objects
|
| 467 |
+
(that haven't been read in yet) in a manner that is transparent to pdfrw
|
| 468 |
+
clients.
|
| 469 |
+
|
| 470 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/pdfrw/objects/pdfarray.py
|
| 471 |
+
|
| 472 |
+
Dict objects
|
| 473 |
+
~~~~~~~~~~~~
|
| 474 |
+
|
| 475 |
+
The `objects/pdfdict.py`__
|
| 476 |
+
module contains the PdfDict class, which is a subclass of dict that is
|
| 477 |
+
used to represent dictionaries in a PDF file. A regular dict could be
|
| 478 |
+
used instead, but the PdfDict class matches the requirements of PDF
|
| 479 |
+
files more closely:
|
| 480 |
+
|
| 481 |
+
* Transparent (from the library client's viewpoint) proxying
|
| 482 |
+
of unresolved indirect objects
|
| 483 |
+
* Return of None for non-existent keys (like dict.get)
|
| 484 |
+
* Mapping of attribute accesses to the dict itself
|
| 485 |
+
(pdfdict.Foo == pdfdict[NameObject('Foo')])
|
| 486 |
+
* Automatic management of following stream and /Length attributes
|
| 487 |
+
for content dictionaries
|
| 488 |
+
* Indirect attribute
|
| 489 |
+
* Other attributes may be set for private internal use of the
|
| 490 |
+
library and/or its clients.
|
| 491 |
+
* Support for searching parent dictionaries for PDF "inheritable"
|
| 492 |
+
attributes.
|
| 493 |
+
|
| 494 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/pdfrw/objects/pdfdict.py
|
| 495 |
+
|
| 496 |
+
If a PdfDict has an associated data stream in the PDF file, the stream
|
| 497 |
+
is accessed via the 'stream' (all lower-case) attribute. Setting the
|
| 498 |
+
stream attribute on the PdfDict will automatically set the /Length attribute
|
| 499 |
+
as well. If that is not what is desired (for example if the the stream
|
| 500 |
+
is compressed), then _stream (same name with an underscore) may be used
|
| 501 |
+
to associate the stream with the PdfDict without setting the length.
|
| 502 |
+
|
| 503 |
+
To set private attributes (that will not be written out to a new PDF
|
| 504 |
+
file) on a dictionary, use the 'private' attribute::
|
| 505 |
+
|
| 506 |
+
mydict.private.foo = 1
|
| 507 |
+
|
| 508 |
+
Once the attribute is set, it may be accessed directly as an attribute
|
| 509 |
+
of the dictionary::
|
| 510 |
+
|
| 511 |
+
foo = mydict.foo
|
| 512 |
+
|
| 513 |
+
Some attributes of PDF pages are "inheritable." That is, they may
|
| 514 |
+
belong to a parent dictionary (or a parent of a parent dictionary, etc.)
|
| 515 |
+
The "inheritable" attribute allows for easy discovery of these::
|
| 516 |
+
|
| 517 |
+
mediabox = mypage.inheritable.MediaBox
|
| 518 |
+
|
| 519 |
+
|
| 520 |
+
Proxy objects
|
| 521 |
+
~~~~~~~~~~~~~
|
| 522 |
+
|
| 523 |
+
The `objects/pdfindirect.py`__
|
| 524 |
+
module contains the PdfIndirect class, which is a non-transparent proxy
|
| 525 |
+
object for PDF objects that have not yet been read in and resolved from
|
| 526 |
+
a file. Although these are non-transparent inside the library, client code
|
| 527 |
+
should never see one of these -- they exist inside the PdfArray and PdfDict
|
| 528 |
+
container types, but are resolved before being returned to a client of
|
| 529 |
+
those types.
|
| 530 |
+
|
| 531 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/pdfrw/objects/pdfindirect.py
|
| 532 |
+
|
| 533 |
+
|
| 534 |
+
File reading, tokenization and parsing
|
| 535 |
+
--------------------------------------
|
| 536 |
+
|
| 537 |
+
`pdfreader.py`__
|
| 538 |
+
contains the PdfReader class, which can read a PDF file (or be passed a
|
| 539 |
+
file object or already read string) and parse it. It uses the PdfTokens
|
| 540 |
+
class in `tokens.py`__ for low-level tokenization.
|
| 541 |
+
|
| 542 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/pdfrw/pdfreader.py
|
| 543 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/pdfrw/tokens.py
|
| 544 |
+
|
| 545 |
+
|
| 546 |
+
The PdfReader class does not, in general, parse into containers (e.g.
|
| 547 |
+
inside the content streams). There is a proof of concept for doing that
|
| 548 |
+
inside the examples/rl2 subdirectory, but that is slow and not well-developed,
|
| 549 |
+
and not useful for most applications.
|
| 550 |
+
|
| 551 |
+
An instance of the PdfReader class is an instance of a PdfDict -- the
|
| 552 |
+
trailer dictionary of the PDF file, to be exact. It will have a private
|
| 553 |
+
attribute set on it that is named 'pages' that is a list containing all
|
| 554 |
+
the pages in the file.
|
| 555 |
+
|
| 556 |
+
When instantiating a PdfReader object, there are options available
|
| 557 |
+
for decompressing all the objects in the file. pdfrw does not currently
|
| 558 |
+
have very many options for decompression, so this is not all that useful,
|
| 559 |
+
except in the specific case of compressed object streams.
|
| 560 |
+
|
| 561 |
+
Also, there are no options for decryption yet. If you have PDF files
|
| 562 |
+
that are encrypted or heavily compressed, you may find that using another
|
| 563 |
+
program like pdftk on them can make them readable by pdfrw.
|
| 564 |
+
|
| 565 |
+
In general, the objects are read from the file lazily, but this is not
|
| 566 |
+
currently true with compressed object streams -- all of these are decompressed
|
| 567 |
+
and read in when the PdfReader is instantiated.
|
| 568 |
+
|
| 569 |
+
|
| 570 |
+
File output
|
| 571 |
+
-----------
|
| 572 |
+
|
| 573 |
+
`pdfwriter.py`__
|
| 574 |
+
contains the PdfWriter class, which can create and output a PDF file.
|
| 575 |
+
|
| 576 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/pdfrw/pdfwriter.py
|
| 577 |
+
|
| 578 |
+
There are a few options available when creating and using this class.
|
| 579 |
+
|
| 580 |
+
In the simplest case, an instance of PdfWriter is instantiated, and
|
| 581 |
+
then pages are added to it from one or more source files (or created
|
| 582 |
+
programmatically), and then the write method is called to dump the
|
| 583 |
+
results out to a file.
|
| 584 |
+
|
| 585 |
+
If you have a source PDF and do not want to disturb the structure
|
| 586 |
+
of it too badly, then you may pass its trailer directly to PdfWriter
|
| 587 |
+
rather than letting PdfWriter construct one for you. There is an
|
| 588 |
+
example of this (alter.py) in the examples directory.
|
| 589 |
+
|
| 590 |
+
|
| 591 |
+
Advanced features
|
| 592 |
+
-----------------
|
| 593 |
+
|
| 594 |
+
`buildxobj.py`__
|
| 595 |
+
contains functions to build Form XObjects out of pages or rectangles on
|
| 596 |
+
pages. These may be reused in new PDFs essentially as if they were images.
|
| 597 |
+
|
| 598 |
+
buildxobj is careful to cache any page used so that it only appears in
|
| 599 |
+
the output once.
|
| 600 |
+
|
| 601 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/pdfrw/buildxobj.py
|
| 602 |
+
|
| 603 |
+
|
| 604 |
+
`toreportlab.py`__
|
| 605 |
+
provides the makerl function, which will translate pdfrw objects into a
|
| 606 |
+
format which can be used with `reportlab <http://www.reportlab.org/>`__.
|
| 607 |
+
It is normally used in conjunction with buildxobj, to be able to reuse
|
| 608 |
+
parts of existing PDFs when using reportlab.
|
| 609 |
+
|
| 610 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/pdfrw/toreportlab.py
|
| 611 |
+
|
| 612 |
+
|
| 613 |
+
`pagemerge.py`__ builds on the foundation laid by buildxobj. It
|
| 614 |
+
contains classes to create a new page (or overlay an existing page)
|
| 615 |
+
using one or more rectangles from other pages. There are examples
|
| 616 |
+
showing its use for watermarking, scaling, 4-up output, splitting
|
| 617 |
+
each page in 2, etc.
|
| 618 |
+
|
| 619 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/pdfrw/pagemerge.py
|
| 620 |
+
|
| 621 |
+
`findobjs.py`__ contains code that can find specific kinds of objects
|
| 622 |
+
inside a PDF file. The extract.py example uses this module to create
|
| 623 |
+
a new PDF that places each image and Form XObject from a source PDF onto
|
| 624 |
+
its own page, e.g. for easy reuse with some of the other examples or
|
| 625 |
+
with reportlab.
|
| 626 |
+
|
| 627 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/pdfrw/findobjs.py
|
| 628 |
+
|
| 629 |
+
|
| 630 |
+
Miscellaneous
|
| 631 |
+
----------------
|
| 632 |
+
|
| 633 |
+
`compress.py`__ and `uncompress.py`__
|
| 634 |
+
contains compression and decompression functions. Very few filters are
|
| 635 |
+
currently supported, so an external tool like pdftk might be good if you
|
| 636 |
+
require the ability to decompress (or, for that matter, decrypt) PDF
|
| 637 |
+
files.
|
| 638 |
+
|
| 639 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/pdfrw/compress.py
|
| 640 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/pdfrw/uncompress.py
|
| 641 |
+
|
| 642 |
+
|
| 643 |
+
`py23_diffs.py`__ contains code to help manage the differences between
|
| 644 |
+
Python 2 and Python 3.
|
| 645 |
+
|
| 646 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/pdfrw/py23_diffs.py
|
| 647 |
+
|
| 648 |
+
Testing
|
| 649 |
+
===============
|
| 650 |
+
|
| 651 |
+
The tests associated with pdfrw require a large number of PDFs,
|
| 652 |
+
which are not distributed with the library.
|
| 653 |
+
|
| 654 |
+
To run the tests:
|
| 655 |
+
|
| 656 |
+
* Download or clone the full package from github.com/pmaupin/pdfrw
|
| 657 |
+
* cd into the tests directory, and then clone the package
|
| 658 |
+
github.com/pmaupin/static_pdfs into a subdirectory (also named
|
| 659 |
+
static_pdfs).
|
| 660 |
+
* Now the tests may be run from that directory using unittest, or
|
| 661 |
+
py.test, or nose.
|
| 662 |
+
* travisci is used at github, and runs the tests with py.test
|
| 663 |
+
|
| 664 |
+
Other libraries
|
| 665 |
+
=====================
|
| 666 |
+
|
| 667 |
+
Pure Python
|
| 668 |
+
-----------
|
| 669 |
+
|
| 670 |
+
- `reportlab <http://www.reportlab.org/>`__
|
| 671 |
+
|
| 672 |
+
reportlab is must-have software if you want to programmatically
|
| 673 |
+
generate arbitrary PDFs.
|
| 674 |
+
|
| 675 |
+
- `pyPdf <https://github.com/mstamy2/PyPDF2>`__
|
| 676 |
+
|
| 677 |
+
pyPdf is, in some ways, very full-featured. It can do decompression
|
| 678 |
+
and decryption and seems to know a lot about items inside at least
|
| 679 |
+
some kinds of PDF files. In comparison, pdfrw knows less about
|
| 680 |
+
specific PDF file features (such as metadata), but focuses on trying
|
| 681 |
+
to have a more Pythonic API for mapping the PDF file container
|
| 682 |
+
syntax to Python, and (IMO) has a simpler and better PDF file
|
| 683 |
+
parser. The Form XObject capability of pdfrw means that, in many
|
| 684 |
+
cases, it does not actually need to decompress objects -- they
|
| 685 |
+
can be left compressed.
|
| 686 |
+
|
| 687 |
+
- `pdftools <http://www.boddie.org.uk/david/Projects/Python/pdftools/index.html>`__
|
| 688 |
+
|
| 689 |
+
pdftools feels large and I fell asleep trying to figure out how it
|
| 690 |
+
all fit together, but many others have done useful things with it.
|
| 691 |
+
|
| 692 |
+
- `pagecatcher <http://www.reportlab.com/docs/pagecatcher-ds.pdf>`__
|
| 693 |
+
|
| 694 |
+
My understanding is that pagecatcher would have done exactly what I
|
| 695 |
+
wanted when I built pdfrw. But I was on a zero budget, so I've never
|
| 696 |
+
had the pleasure of experiencing pagecatcher. I do, however, use and
|
| 697 |
+
like `reportlab <http://www.reportlab.org/>`__ (open source, from
|
| 698 |
+
the people who make pagecatcher) so I'm sure pagecatcher is great,
|
| 699 |
+
better documented and much more full-featured than pdfrw.
|
| 700 |
+
|
| 701 |
+
- `pdfminer <http://www.unixuser.org/~euske/python/pdfminer/index.html>`__
|
| 702 |
+
|
| 703 |
+
This looks like a useful, actively-developed program. It is quite
|
| 704 |
+
large, but then, it is trying to actively comprehend a full PDF
|
| 705 |
+
document. From the website:
|
| 706 |
+
|
| 707 |
+
"PDFMiner is a suite of programs that help extracting and analyzing
|
| 708 |
+
text data of PDF documents. Unlike other PDF-related tools, it
|
| 709 |
+
allows to obtain the exact location of texts in a page, as well as
|
| 710 |
+
other extra information such as font information or ruled lines. It
|
| 711 |
+
includes a PDF converter that can transform PDF files into other
|
| 712 |
+
text formats (such as HTML). It has an extensible PDF parser that
|
| 713 |
+
can be used for other purposes instead of text analysis."
|
| 714 |
+
|
| 715 |
+
non-pure-Python libraries
|
| 716 |
+
-------------------------
|
| 717 |
+
|
| 718 |
+
- `pyPoppler <https://launchpad.net/poppler-python/>`__ can read PDF
|
| 719 |
+
files.
|
| 720 |
+
- `pycairo <http://www.cairographics.org/pycairo/>`__ can write PDF
|
| 721 |
+
files.
|
| 722 |
+
- `PyMuPDF <https://github.com/rk700/PyMuPDF>`_ high performance rendering
|
| 723 |
+
of PDF, (Open)XPS, CBZ and EPUB
|
| 724 |
+
|
| 725 |
+
Other tools
|
| 726 |
+
-----------
|
| 727 |
+
|
| 728 |
+
- `pdftk <https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/>`__ is a wonderful command
|
| 729 |
+
line tool for basic PDF manipulation. It complements pdfrw extremely
|
| 730 |
+
well, supporting many operations such as decryption and decompression
|
| 731 |
+
that pdfrw cannot do.
|
| 732 |
+
- `MuPDF <http://www.mupdf.com/>`_ is a free top performance PDF, (Open)XPS, CBZ and EPUB rendering library
|
| 733 |
+
that also comes with some command line tools. One of those, ``mutool``, has big overlaps with pdftk's -
|
| 734 |
+
except it is up to 10 times faster.
|
| 735 |
+
|
| 736 |
+
Release information
|
| 737 |
+
=======================
|
| 738 |
+
|
| 739 |
+
Revisions:
|
| 740 |
+
|
| 741 |
+
0.4 -- Released 18 September, 2017
|
| 742 |
+
|
| 743 |
+
- Python 3.6 added to test matrix
|
| 744 |
+
- Proper unicode support for text strings in PDFs added
|
| 745 |
+
- buildxobj fixes allow better support creating form XObjects
|
| 746 |
+
out of compressed pages in some cases
|
| 747 |
+
- Compression fixes for Python 3+
|
| 748 |
+
- New subset_booklets.py example
|
| 749 |
+
- Bug with non-compressed indices into compressed object streams fixed
|
| 750 |
+
- Bug with distinguishing compressed object stream first objects fixed
|
| 751 |
+
- Better error reporting added for some invalid PDFs (e.g. when reading
|
| 752 |
+
past the end of file)
|
| 753 |
+
- Better scrubbing of old bookmark information when writing PDFs, to
|
| 754 |
+
remove dangling references
|
| 755 |
+
- Refactoring of pdfwriter, including updating API, to allow future
|
| 756 |
+
enhancements for things like incremental writing
|
| 757 |
+
- Minor tokenizer speedup
|
| 758 |
+
- Some flate decompressor bugs fixed
|
| 759 |
+
- Compression and decompression tests added
|
| 760 |
+
- Tests for new unicode handling added
|
| 761 |
+
- PdfReader.readpages() recursion error (issue #92) fixed.
|
| 762 |
+
- Initial crypt filter support added
|
| 763 |
+
|
| 764 |
+
|
| 765 |
+
0.3 -- Released 19 October, 2016.
|
| 766 |
+
|
| 767 |
+
- Python 3.5 added to test matrix
|
| 768 |
+
- Better support under Python 3.x for in-memory PDF file-like objects
|
| 769 |
+
- Some pagemerge and Unicode patches added
|
| 770 |
+
- Changes to logging allow better coexistence with other packages
|
| 771 |
+
- Fix for "from pdfrw import \*"
|
| 772 |
+
- New fancy_watermark.py example shows off capabilities of pagemerge.py
|
| 773 |
+
- metadata.py example renamed to cat.py
|
| 774 |
+
|
| 775 |
+
|
| 776 |
+
0.2 -- Released 21 June, 2015. Supports Python 2.6, 2.7, 3.3, and 3.4.
|
| 777 |
+
|
| 778 |
+
- Several bugs have been fixed
|
| 779 |
+
- New regression test functionally tests core with dozens of
|
| 780 |
+
PDFs, and also tests examples.
|
| 781 |
+
- Core has been ported and tested on Python3 by round-tripping
|
| 782 |
+
several difficult files and observing binary matching results
|
| 783 |
+
across the different Python versions.
|
| 784 |
+
- Still only minimal support for compression and no support
|
| 785 |
+
for encryption or newer PDF features. (pdftk is useful
|
| 786 |
+
to put PDFs in a form that pdfrw can use.)
|
| 787 |
+
|
| 788 |
+
0.1 -- Released to PyPI in 2012. Supports Python 2.5 - 2.7
|
| 789 |
+
|
| 790 |
+
|
| 791 |
+
|
8210_A1P3-master/Lib/site-packages/pdfrw-0.4.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pip
|
8210_A1P3-master/Lib/site-packages/pdfrw-0.4.dist-info/METADATA
ADDED
|
@@ -0,0 +1,820 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.0
|
| 2 |
+
Name: pdfrw
|
| 3 |
+
Version: 0.4
|
| 4 |
+
Summary: PDF file reader/writer library
|
| 5 |
+
Home-page: https://github.com/pmaupin/pdfrw
|
| 6 |
+
Author: Patrick Maupin
|
| 7 |
+
Author-email: pmaupin@gmail.com
|
| 8 |
+
License: MIT
|
| 9 |
+
Keywords: pdf vector graphics PDF nup watermark split join merge
|
| 10 |
+
Platform: Independent
|
| 11 |
+
Classifier: Development Status :: 4 - Beta
|
| 12 |
+
Classifier: Intended Audience :: Developers
|
| 13 |
+
Classifier: License :: OSI Approved :: MIT License
|
| 14 |
+
Classifier: Operating System :: OS Independent
|
| 15 |
+
Classifier: Programming Language :: Python
|
| 16 |
+
Classifier: Programming Language :: Python :: 2
|
| 17 |
+
Classifier: Programming Language :: Python :: 2.6
|
| 18 |
+
Classifier: Programming Language :: Python :: 2.7
|
| 19 |
+
Classifier: Programming Language :: Python :: 3
|
| 20 |
+
Classifier: Programming Language :: Python :: 3.3
|
| 21 |
+
Classifier: Programming Language :: Python :: 3.4
|
| 22 |
+
Classifier: Programming Language :: Python :: 3.5
|
| 23 |
+
Classifier: Programming Language :: Python :: 3.6
|
| 24 |
+
Classifier: Topic :: Multimedia :: Graphics :: Graphics Conversion
|
| 25 |
+
Classifier: Topic :: Software Development :: Libraries
|
| 26 |
+
Classifier: Topic :: Text Processing
|
| 27 |
+
Classifier: Topic :: Printing
|
| 28 |
+
Classifier: Topic :: Utilities
|
| 29 |
+
|
| 30 |
+
==================
|
| 31 |
+
pdfrw 0.4
|
| 32 |
+
==================
|
| 33 |
+
|
| 34 |
+
:Author: Patrick Maupin
|
| 35 |
+
|
| 36 |
+
.. contents::
|
| 37 |
+
:backlinks: none
|
| 38 |
+
|
| 39 |
+
.. sectnum::
|
| 40 |
+
|
| 41 |
+
Introduction
|
| 42 |
+
============
|
| 43 |
+
|
| 44 |
+
**pdfrw** is a Python library and utility that reads and writes PDF files:
|
| 45 |
+
|
| 46 |
+
* Version 0.4 is tested and works on Python 2.6, 2.7, 3.3, 3.4, 3.5, and 3.6
|
| 47 |
+
* Operations include subsetting, merging, rotating, modifying metadata, etc.
|
| 48 |
+
* The fastest pure Python PDF parser available
|
| 49 |
+
* Has been used for years by a printer in pre-press production
|
| 50 |
+
* Can be used with rst2pdf to faithfully reproduce vector images
|
| 51 |
+
* Can be used either standalone, or in conjunction with `reportlab`__
|
| 52 |
+
to reuse existing PDFs in new ones
|
| 53 |
+
* Permissively licensed
|
| 54 |
+
|
| 55 |
+
__ http://www.reportlab.org/
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
pdfrw will faithfully reproduce vector formats without
|
| 59 |
+
rasterization, so the rst2pdf package has used pdfrw
|
| 60 |
+
for PDF and SVG images by default since March 2010.
|
| 61 |
+
|
| 62 |
+
pdfrw can also be used in conjunction with reportlab, in order
|
| 63 |
+
to re-use portions of existing PDFs in new PDFs created with
|
| 64 |
+
reportlab.
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
Examples
|
| 68 |
+
=========
|
| 69 |
+
|
| 70 |
+
The library comes with several examples that show operation both with
|
| 71 |
+
and without reportlab.
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
All examples
|
| 75 |
+
------------------
|
| 76 |
+
|
| 77 |
+
The examples directory has a few scripts which use the library.
|
| 78 |
+
Note that if these examples do not work with your PDF, you should
|
| 79 |
+
try to use pdftk to uncompress and/or unencrypt them first.
|
| 80 |
+
|
| 81 |
+
* `4up.py`__ will shrink pages down and place 4 of them on
|
| 82 |
+
each output page.
|
| 83 |
+
* `alter.py`__ shows an example of modifying metadata, without
|
| 84 |
+
altering the structure of the PDF.
|
| 85 |
+
* `booklet.py`__ shows an example of creating a 2-up output
|
| 86 |
+
suitable for printing and folding (e.g on tabloid size paper).
|
| 87 |
+
* `cat.py`__ shows an example of concatenating multiple PDFs together.
|
| 88 |
+
* `extract.py`__ will extract images and Form XObjects (embedded pages)
|
| 89 |
+
from existing PDFs to make them easier to use and refer to from
|
| 90 |
+
new PDFs (e.g. with reportlab or rst2pdf).
|
| 91 |
+
* `poster.py`__ increases the size of a PDF so it can be printed
|
| 92 |
+
as a poster.
|
| 93 |
+
* `print_two.py`__ Allows creation of 8.5 X 5.5" booklets by slicing
|
| 94 |
+
8.5 X 11" paper apart after printing.
|
| 95 |
+
* `rotate.py`__ Rotates all or selected pages in a PDF.
|
| 96 |
+
* `subset.py`__ Creates a new PDF with only a subset of pages from the
|
| 97 |
+
original.
|
| 98 |
+
* `unspread.py`__ Takes a 2-up PDF, and splits out pages.
|
| 99 |
+
* `watermark.py`__ Adds a watermark PDF image over or under all the pages
|
| 100 |
+
of a PDF.
|
| 101 |
+
* `rl1/4up.py`__ Another 4up example, using reportlab canvas for output.
|
| 102 |
+
* `rl1/booklet.py`__ Another booklet example, using reportlab canvas for
|
| 103 |
+
output.
|
| 104 |
+
* `rl1/subset.py`__ Another subsetting example, using reportlab canvas for
|
| 105 |
+
output.
|
| 106 |
+
* `rl1/platypus_pdf_template.py`__ Another watermarking example, using
|
| 107 |
+
reportlab canvas and generated output for the document. Contributed
|
| 108 |
+
by user asannes.
|
| 109 |
+
* `rl2`__ Experimental code for parsing graphics. Needs work.
|
| 110 |
+
* `subset_booklets.py`__ shows an example of creating a full printable pdf
|
| 111 |
+
version in a more professional and pratical way ( take a look at
|
| 112 |
+
http://www.wikihow.com/Bind-a-Book )
|
| 113 |
+
|
| 114 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/4up.py
|
| 115 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/alter.py
|
| 116 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/booklet.py
|
| 117 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/cat.py
|
| 118 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/extract.py
|
| 119 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/poster.py
|
| 120 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/print_two.py
|
| 121 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/rotate.py
|
| 122 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/subset.py
|
| 123 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/unspread.py
|
| 124 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/watermark.py
|
| 125 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/rl1/4up.py
|
| 126 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/rl1/booklet.py
|
| 127 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/rl1/subset.py
|
| 128 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/rl1/platypus_pdf_template.py
|
| 129 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/rl2/
|
| 130 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/subset_booklets.py
|
| 131 |
+
|
| 132 |
+
Notes on selected examples
|
| 133 |
+
------------------------------------
|
| 134 |
+
|
| 135 |
+
Reorganizing pages and placing them two-up
|
| 136 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 137 |
+
|
| 138 |
+
A printer with a fancy printer and/or a full-up copy of Acrobat can
|
| 139 |
+
easily turn your small PDF into a little booklet (for example, print 4
|
| 140 |
+
letter-sized pages on a single 11" x 17").
|
| 141 |
+
|
| 142 |
+
But that assumes several things, including that the personnel know how
|
| 143 |
+
to operate the hardware and software. `booklet.py`__ lets you turn your PDF
|
| 144 |
+
into a preformatted booklet, to give them fewer chances to mess it up.
|
| 145 |
+
|
| 146 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/booklet.py
|
| 147 |
+
|
| 148 |
+
Adding or modifying metadata
|
| 149 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 150 |
+
|
| 151 |
+
The `cat.py`__ example will accept multiple input files on the command
|
| 152 |
+
line, concatenate them and output them to output.pdf, after adding some
|
| 153 |
+
nonsensical metadata to the output PDF file.
|
| 154 |
+
|
| 155 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/cat.py
|
| 156 |
+
|
| 157 |
+
The `alter.py`__ example alters a single metadata item in a PDF,
|
| 158 |
+
and writes the result to a new PDF.
|
| 159 |
+
|
| 160 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/alter.py
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
One difference is that, since **cat** is creating a new PDF structure,
|
| 164 |
+
and **alter** is attempting to modify an existing PDF structure, the
|
| 165 |
+
PDF produced by alter (and also by watermark.py) *should* be
|
| 166 |
+
more faithful to the original (except for the desired changes).
|
| 167 |
+
|
| 168 |
+
For example, the alter.py navigation should be left intact, whereas with
|
| 169 |
+
cat.py it will be stripped.
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
Rotating and doubling
|
| 173 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 174 |
+
|
| 175 |
+
If you ever want to print something that is like a small booklet, but
|
| 176 |
+
needs to be spiral bound, you either have to do some fancy rearranging,
|
| 177 |
+
or just waste half your paper.
|
| 178 |
+
|
| 179 |
+
The `print_two.py`__ example program will, for example, make two side-by-side
|
| 180 |
+
copies each page of of your PDF on a each output sheet.
|
| 181 |
+
|
| 182 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/print_two.py
|
| 183 |
+
|
| 184 |
+
But, every other page is flipped, so that you can print double-sided and
|
| 185 |
+
the pages will line up properly and be pre-collated.
|
| 186 |
+
|
| 187 |
+
Graphics stream parsing proof of concept
|
| 188 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 189 |
+
|
| 190 |
+
The `copy.py`__ script shows a simple example of reading in a PDF, and
|
| 191 |
+
using the decodegraphics.py module to try to write the same information
|
| 192 |
+
out to a new PDF through a reportlab canvas. (If you know about reportlab,
|
| 193 |
+
you know that if you can faithfully render a PDF to a reportlab canvas, you
|
| 194 |
+
can do pretty much anything else with that PDF you want.) This kind of
|
| 195 |
+
low level manipulation should be done only if you really need to.
|
| 196 |
+
decodegraphics is really more than a proof of concept than anything
|
| 197 |
+
else. For most cases, just use the Form XObject capability, as shown in
|
| 198 |
+
the examples/rl1/booklet.py demo.
|
| 199 |
+
|
| 200 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/examples/rl2/copy.py
|
| 201 |
+
|
| 202 |
+
pdfrw philosophy
|
| 203 |
+
==================
|
| 204 |
+
|
| 205 |
+
Core library
|
| 206 |
+
-------------
|
| 207 |
+
|
| 208 |
+
The philosophy of the library portion of pdfrw is to provide intuitive
|
| 209 |
+
functions to read, manipulate, and write PDF files. There should be
|
| 210 |
+
minimal leakage between abstraction layers, although getting useful
|
| 211 |
+
work done makes "pure" functionality separation difficult.
|
| 212 |
+
|
| 213 |
+
A key concept supported by the library is the use of Form XObjects,
|
| 214 |
+
which allow easy embedding of pieces of one PDF into another.
|
| 215 |
+
|
| 216 |
+
Addition of core support to the library is typically done carefully
|
| 217 |
+
and thoughtfully, so as not to clutter it up with too many special
|
| 218 |
+
cases.
|
| 219 |
+
|
| 220 |
+
There are a lot of incorrectly formatted PDFs floating around; support
|
| 221 |
+
for these is added in some cases. The decision is often based on what
|
| 222 |
+
acroread and okular do with the PDFs; if they can display them properly,
|
| 223 |
+
then eventually pdfrw should, too, if it is not too difficult or costly.
|
| 224 |
+
|
| 225 |
+
Contributions are welcome; one user has contributed some decompression
|
| 226 |
+
filters and the ability to process PDF 1.5 stream objects. Additional
|
| 227 |
+
functionality that would obviously be useful includes additional
|
| 228 |
+
decompression filters, the ability to process password-protected PDFs,
|
| 229 |
+
and the ability to output linearized PDFs.
|
| 230 |
+
|
| 231 |
+
Examples
|
| 232 |
+
--------
|
| 233 |
+
|
| 234 |
+
The philosophy of the examples is to provide small, easily-understood
|
| 235 |
+
examples that showcase pdfrw functionality.
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
PDF files and Python
|
| 239 |
+
======================
|
| 240 |
+
|
| 241 |
+
Introduction
|
| 242 |
+
------------
|
| 243 |
+
|
| 244 |
+
In general, PDF files conceptually map quite well to Python. The major
|
| 245 |
+
objects to think about are:
|
| 246 |
+
|
| 247 |
+
- **strings**. Most things are strings. These also often decompose
|
| 248 |
+
naturally into
|
| 249 |
+
- **lists of tokens**. Tokens can be combined to create higher-level
|
| 250 |
+
objects like
|
| 251 |
+
- **arrays** and
|
| 252 |
+
- **dictionaries** and
|
| 253 |
+
- **Contents streams** (which can be more streams of tokens)
|
| 254 |
+
|
| 255 |
+
Difficulties
|
| 256 |
+
------------
|
| 257 |
+
|
| 258 |
+
The apparent primary difficulty in mapping PDF files to Python is the
|
| 259 |
+
PDF file concept of "indirect objects." Indirect objects provide
|
| 260 |
+
the efficiency of allowing a single piece of data to be referred to
|
| 261 |
+
from more than one containing object, but probably more importantly,
|
| 262 |
+
indirect objects provide a way to get around the chicken and egg
|
| 263 |
+
problem of circular object references when mapping arbitrary data
|
| 264 |
+
structures to files. To flatten out a circular reference, an indirect
|
| 265 |
+
object is *referred to* instead of being *directly included* in another
|
| 266 |
+
object. PDF files have a global mechanism for locating indirect objects,
|
| 267 |
+
and they all have two reference numbers (a reference number and a
|
| 268 |
+
"generation" number, in case you wanted to append to the PDF file
|
| 269 |
+
rather than just rewriting the whole thing).
|
| 270 |
+
|
| 271 |
+
pdfrw automatically handles indirect references on reading in a PDF
|
| 272 |
+
file. When pdfrw encounters an indirect PDF file object, the
|
| 273 |
+
corresponding Python object it creates will have an 'indirect' attribute
|
| 274 |
+
with a value of True. When writing a PDF file, if you have created
|
| 275 |
+
arbitrary data, you just need to make sure that circular references are
|
| 276 |
+
broken up by putting an attribute named 'indirect' which evaluates to
|
| 277 |
+
True on at least one object in every cycle.
|
| 278 |
+
|
| 279 |
+
Another PDF file concept that doesn't quite map to regular Python is a
|
| 280 |
+
"stream". Streams are dictionaries which each have an associated
|
| 281 |
+
unformatted data block. pdfrw handles streams by placing a special
|
| 282 |
+
attribute on a subclassed dictionary.
|
| 283 |
+
|
| 284 |
+
Usage Model
|
| 285 |
+
-----------
|
| 286 |
+
|
| 287 |
+
The usage model for pdfrw treats most objects as strings (it takes their
|
| 288 |
+
string representation when writing them to a file). The two main
|
| 289 |
+
exceptions are the PdfArray object and the PdfDict object.
|
| 290 |
+
|
| 291 |
+
PdfArray is a subclass of list with two special features. First,
|
| 292 |
+
an 'indirect' attribute allows a PdfArray to be written out as
|
| 293 |
+
an indirect PDF object. Second, pdfrw reads files lazily, so
|
| 294 |
+
PdfArray knows about, and resolves references to other indirect
|
| 295 |
+
objects on an as-needed basis.
|
| 296 |
+
|
| 297 |
+
PdfDict is a subclass of dict that also has an indirect attribute
|
| 298 |
+
and lazy reference resolution as well. (And the subclassed
|
| 299 |
+
IndirectPdfDict has indirect automatically set True).
|
| 300 |
+
|
| 301 |
+
But PdfDict also has an optional associated stream. The stream object
|
| 302 |
+
defaults to None, but if you assign a stream to the dict, it will
|
| 303 |
+
automatically set the PDF /Length attribute for the dictionary.
|
| 304 |
+
|
| 305 |
+
Finally, since PdfDict instances are indexed by PdfName objects (which
|
| 306 |
+
always start with a /) and since most (all?) standard Adobe PdfName
|
| 307 |
+
objects use names formatted like "/CamelCase", it makes sense to allow
|
| 308 |
+
access to dictionary elements via object attribute accesses as well as
|
| 309 |
+
object index accesses. So usage of PdfDict objects is normally via
|
| 310 |
+
attribute access, although non-standard names (though still with a
|
| 311 |
+
leading slash) can be accessed via dictionary index lookup.
|
| 312 |
+
|
| 313 |
+
Reading PDFs
|
| 314 |
+
~~~~~~~~~~~~~~~
|
| 315 |
+
|
| 316 |
+
The PdfReader object is a subclass of PdfDict, which allows easy access
|
| 317 |
+
to an entire document::
|
| 318 |
+
|
| 319 |
+
>>> from pdfrw import PdfReader
|
| 320 |
+
>>> x = PdfReader('source.pdf')
|
| 321 |
+
>>> x.keys()
|
| 322 |
+
['/Info', '/Size', '/Root']
|
| 323 |
+
>>> x.Info
|
| 324 |
+
{'/Producer': '(cairo 1.8.6 (http://cairographics.org))',
|
| 325 |
+
'/Creator': '(cairo 1.8.6 (http://cairographics.org))'}
|
| 326 |
+
>>> x.Root.keys()
|
| 327 |
+
['/Type', '/Pages']
|
| 328 |
+
|
| 329 |
+
Info, Size, and Root are retrieved from the trailer of the PDF file.
|
| 330 |
+
|
| 331 |
+
In addition to the tree structure, pdfrw creates a special attribute
|
| 332 |
+
named *pages*, that is a list of all the pages in the document. pdfrw
|
| 333 |
+
creates the *pages* attribute as a simplification for the user, because
|
| 334 |
+
the PDF format allows arbitrarily complicated nested dictionaries to
|
| 335 |
+
describe the page order. Each entry in the *pages* list is the PdfDict
|
| 336 |
+
object for one of the pages in the file, in order.
|
| 337 |
+
|
| 338 |
+
::
|
| 339 |
+
|
| 340 |
+
>>> len(x.pages)
|
| 341 |
+
1
|
| 342 |
+
>>> x.pages[0]
|
| 343 |
+
{'/Parent': {'/Kids': [{...}], '/Type': '/Pages', '/Count': '1'},
|
| 344 |
+
'/Contents': {'/Length': '11260', '/Filter': None},
|
| 345 |
+
'/Resources': ... (Lots more stuff snipped)
|
| 346 |
+
>>> x.pages[0].Contents
|
| 347 |
+
{'/Length': '11260', '/Filter': None}
|
| 348 |
+
>>> x.pages[0].Contents.stream
|
| 349 |
+
'q\n1 1 1 rg /a0 gs\n0 0 0 RG 0.657436
|
| 350 |
+
w\n0 J\n0 j\n[] 0.0 d\n4 M q' ... (Lots more stuff snipped)
|
| 351 |
+
|
| 352 |
+
Writing PDFs
|
| 353 |
+
~~~~~~~~~~~~~~~
|
| 354 |
+
|
| 355 |
+
As you can see, it is quite easy to dig down into a PDF document. But
|
| 356 |
+
what about when it's time to write it out?
|
| 357 |
+
|
| 358 |
+
::
|
| 359 |
+
|
| 360 |
+
>>> from pdfrw import PdfWriter
|
| 361 |
+
>>> y = PdfWriter()
|
| 362 |
+
>>> y.addpage(x.pages[0])
|
| 363 |
+
>>> y.write('result.pdf')
|
| 364 |
+
|
| 365 |
+
That's all it takes to create a new PDF. You may still need to read the
|
| 366 |
+
`Adobe PDF reference manual`__ to figure out what needs to go *into*
|
| 367 |
+
the PDF, but at least you don't have to sweat actually building it
|
| 368 |
+
and getting the file offsets right.
|
| 369 |
+
|
| 370 |
+
__ http://www.adobe.com/devnet/acrobat/pdfs/pdf_reference_1-7.pdf
|
| 371 |
+
|
| 372 |
+
Manipulating PDFs in memory
|
| 373 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 374 |
+
|
| 375 |
+
For the most part, pdfrw tries to be agnostic about the contents of
|
| 376 |
+
PDF files, and support them as containers, but to do useful work,
|
| 377 |
+
something a little higher-level is required, so pdfrw works to
|
| 378 |
+
understand a bit about the contents of the containers. For example:
|
| 379 |
+
|
| 380 |
+
- PDF pages. pdfrw knows enough to find the pages in PDF files you read
|
| 381 |
+
in, and to write a set of pages back out to a new PDF file.
|
| 382 |
+
- Form XObjects. pdfrw can take any page or rectangle on a page, and
|
| 383 |
+
convert it to a Form XObject, suitable for use inside another PDF
|
| 384 |
+
file. It knows enough about these to perform scaling, rotation,
|
| 385 |
+
and positioning.
|
| 386 |
+
- reportlab objects. pdfrw can recursively create a set of reportlab
|
| 387 |
+
objects from its internal object format. This allows, for example,
|
| 388 |
+
Form XObjects to be used inside reportlab, so that you can reuse
|
| 389 |
+
content from an existing PDF file when building a new PDF with
|
| 390 |
+
reportlab.
|
| 391 |
+
|
| 392 |
+
There are several examples that demonstrate these features in
|
| 393 |
+
the example code directory.
|
| 394 |
+
|
| 395 |
+
Missing features
|
| 396 |
+
~~~~~~~~~~~~~~~~~~~~~~~
|
| 397 |
+
|
| 398 |
+
Even as a pure PDF container library, pdfrw comes up a bit short. It
|
| 399 |
+
does not currently support:
|
| 400 |
+
|
| 401 |
+
- Most compression/decompression filters
|
| 402 |
+
- encryption
|
| 403 |
+
|
| 404 |
+
`pdftk`__ is a wonderful command-line
|
| 405 |
+
tool that can convert your PDFs to remove encryption and compression.
|
| 406 |
+
However, in most cases, you can do a lot of useful work with PDFs
|
| 407 |
+
without actually removing compression, because only certain elements
|
| 408 |
+
inside PDFs are actually compressed.
|
| 409 |
+
|
| 410 |
+
__ https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/
|
| 411 |
+
|
| 412 |
+
Library internals
|
| 413 |
+
==================
|
| 414 |
+
|
| 415 |
+
Introduction
|
| 416 |
+
------------
|
| 417 |
+
|
| 418 |
+
**pdfrw** currently consists of 19 modules organized into a main
|
| 419 |
+
package and one sub-package.
|
| 420 |
+
|
| 421 |
+
The `__init.py__`__ module does the usual thing of importing a few
|
| 422 |
+
major attributes from some of the submodules, and the `errors.py`__
|
| 423 |
+
module supports logging and exception generation.
|
| 424 |
+
|
| 425 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/pdfrw/__init__.py
|
| 426 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/pdfrw/errors.py
|
| 427 |
+
|
| 428 |
+
|
| 429 |
+
PDF object model support
|
| 430 |
+
--------------------------
|
| 431 |
+
|
| 432 |
+
The `objects`__ sub-package contains one module for each of the
|
| 433 |
+
internal representations of the kinds of basic objects that exist
|
| 434 |
+
in a PDF file, with the `objects/__init__.py`__ module in that
|
| 435 |
+
package simply gathering them up and making them available to the
|
| 436 |
+
main pdfrw package.
|
| 437 |
+
|
| 438 |
+
One feature that all the PDF object classes have in common is the
|
| 439 |
+
inclusion of an 'indirect' attribute. If 'indirect' exists and evaluates
|
| 440 |
+
to True, then when the object is written out, it is written out as an
|
| 441 |
+
indirect object. That is to say, it is addressable in the PDF file, and
|
| 442 |
+
could be referenced by any number (including zero) of container objects.
|
| 443 |
+
This indirect object capability saves space in PDF files by allowing
|
| 444 |
+
objects such as fonts to be referenced from multiple pages, and also
|
| 445 |
+
allows PDF files to contain internal circular references. This latter
|
| 446 |
+
capability is used, for example, when each page object has a "parent"
|
| 447 |
+
object in its dictionary.
|
| 448 |
+
|
| 449 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/pdfrw/objects/
|
| 450 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/pdfrw/objects/__init__.py
|
| 451 |
+
|
| 452 |
+
Ordinary objects
|
| 453 |
+
~~~~~~~~~~~~~~~~
|
| 454 |
+
|
| 455 |
+
The `objects/pdfobject.py`__ module contains the PdfObject class, which is
|
| 456 |
+
a subclass of str, and is the catch-all object for any PDF file elements
|
| 457 |
+
that are not explicitly represented by other objects, as described below.
|
| 458 |
+
|
| 459 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/pdfrw/objects/pdfobject.py
|
| 460 |
+
|
| 461 |
+
Name objects
|
| 462 |
+
~~~~~~~~~~~~
|
| 463 |
+
|
| 464 |
+
The `objects/pdfname.py`__ module contains the PdfName singleton object,
|
| 465 |
+
which will convert a string into a PDF name by prepending a slash. It can
|
| 466 |
+
be used either by calling it or getting an attribute, e.g.::
|
| 467 |
+
|
| 468 |
+
PdfName.Rotate == PdfName('Rotate') == PdfObject('/Rotate')
|
| 469 |
+
|
| 470 |
+
In the example above, there is a slight difference between the objects
|
| 471 |
+
returned from PdfName, and the object returned from PdfObject. The
|
| 472 |
+
PdfName objects are actually objects of class "BasePdfName". This
|
| 473 |
+
is important, because only these may be used as keys in PdfDict objects.
|
| 474 |
+
|
| 475 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/pdfrw/objects/pdfname.py
|
| 476 |
+
|
| 477 |
+
String objects
|
| 478 |
+
~~~~~~~~~~~~~~
|
| 479 |
+
|
| 480 |
+
The `objects/pdfstring.py`__
|
| 481 |
+
module contains the PdfString class, which is a subclass of str that is
|
| 482 |
+
used to represent encoded strings in a PDF file. The class has encode
|
| 483 |
+
and decode methods for the strings.
|
| 484 |
+
|
| 485 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/pdfrw/objects/pdfstring.py
|
| 486 |
+
|
| 487 |
+
|
| 488 |
+
Array objects
|
| 489 |
+
~~~~~~~~~~~~~
|
| 490 |
+
|
| 491 |
+
The `objects/pdfarray.py`__
|
| 492 |
+
module contains the PdfArray class, which is a subclass of list that is
|
| 493 |
+
used to represent arrays in a PDF file. A regular list could be used
|
| 494 |
+
instead, but use of the PdfArray class allows for an indirect attribute
|
| 495 |
+
to be set, and also allows for proxying of unresolved indirect objects
|
| 496 |
+
(that haven't been read in yet) in a manner that is transparent to pdfrw
|
| 497 |
+
clients.
|
| 498 |
+
|
| 499 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/pdfrw/objects/pdfarray.py
|
| 500 |
+
|
| 501 |
+
Dict objects
|
| 502 |
+
~~~~~~~~~~~~
|
| 503 |
+
|
| 504 |
+
The `objects/pdfdict.py`__
|
| 505 |
+
module contains the PdfDict class, which is a subclass of dict that is
|
| 506 |
+
used to represent dictionaries in a PDF file. A regular dict could be
|
| 507 |
+
used instead, but the PdfDict class matches the requirements of PDF
|
| 508 |
+
files more closely:
|
| 509 |
+
|
| 510 |
+
* Transparent (from the library client's viewpoint) proxying
|
| 511 |
+
of unresolved indirect objects
|
| 512 |
+
* Return of None for non-existent keys (like dict.get)
|
| 513 |
+
* Mapping of attribute accesses to the dict itself
|
| 514 |
+
(pdfdict.Foo == pdfdict[NameObject('Foo')])
|
| 515 |
+
* Automatic management of following stream and /Length attributes
|
| 516 |
+
for content dictionaries
|
| 517 |
+
* Indirect attribute
|
| 518 |
+
* Other attributes may be set for private internal use of the
|
| 519 |
+
library and/or its clients.
|
| 520 |
+
* Support for searching parent dictionaries for PDF "inheritable"
|
| 521 |
+
attributes.
|
| 522 |
+
|
| 523 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/pdfrw/objects/pdfdict.py
|
| 524 |
+
|
| 525 |
+
If a PdfDict has an associated data stream in the PDF file, the stream
|
| 526 |
+
is accessed via the 'stream' (all lower-case) attribute. Setting the
|
| 527 |
+
stream attribute on the PdfDict will automatically set the /Length attribute
|
| 528 |
+
as well. If that is not what is desired (for example if the the stream
|
| 529 |
+
is compressed), then _stream (same name with an underscore) may be used
|
| 530 |
+
to associate the stream with the PdfDict without setting the length.
|
| 531 |
+
|
| 532 |
+
To set private attributes (that will not be written out to a new PDF
|
| 533 |
+
file) on a dictionary, use the 'private' attribute::
|
| 534 |
+
|
| 535 |
+
mydict.private.foo = 1
|
| 536 |
+
|
| 537 |
+
Once the attribute is set, it may be accessed directly as an attribute
|
| 538 |
+
of the dictionary::
|
| 539 |
+
|
| 540 |
+
foo = mydict.foo
|
| 541 |
+
|
| 542 |
+
Some attributes of PDF pages are "inheritable." That is, they may
|
| 543 |
+
belong to a parent dictionary (or a parent of a parent dictionary, etc.)
|
| 544 |
+
The "inheritable" attribute allows for easy discovery of these::
|
| 545 |
+
|
| 546 |
+
mediabox = mypage.inheritable.MediaBox
|
| 547 |
+
|
| 548 |
+
|
| 549 |
+
Proxy objects
|
| 550 |
+
~~~~~~~~~~~~~
|
| 551 |
+
|
| 552 |
+
The `objects/pdfindirect.py`__
|
| 553 |
+
module contains the PdfIndirect class, which is a non-transparent proxy
|
| 554 |
+
object for PDF objects that have not yet been read in and resolved from
|
| 555 |
+
a file. Although these are non-transparent inside the library, client code
|
| 556 |
+
should never see one of these -- they exist inside the PdfArray and PdfDict
|
| 557 |
+
container types, but are resolved before being returned to a client of
|
| 558 |
+
those types.
|
| 559 |
+
|
| 560 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/pdfrw/objects/pdfindirect.py
|
| 561 |
+
|
| 562 |
+
|
| 563 |
+
File reading, tokenization and parsing
|
| 564 |
+
--------------------------------------
|
| 565 |
+
|
| 566 |
+
`pdfreader.py`__
|
| 567 |
+
contains the PdfReader class, which can read a PDF file (or be passed a
|
| 568 |
+
file object or already read string) and parse it. It uses the PdfTokens
|
| 569 |
+
class in `tokens.py`__ for low-level tokenization.
|
| 570 |
+
|
| 571 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/pdfrw/pdfreader.py
|
| 572 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/pdfrw/tokens.py
|
| 573 |
+
|
| 574 |
+
|
| 575 |
+
The PdfReader class does not, in general, parse into containers (e.g.
|
| 576 |
+
inside the content streams). There is a proof of concept for doing that
|
| 577 |
+
inside the examples/rl2 subdirectory, but that is slow and not well-developed,
|
| 578 |
+
and not useful for most applications.
|
| 579 |
+
|
| 580 |
+
An instance of the PdfReader class is an instance of a PdfDict -- the
|
| 581 |
+
trailer dictionary of the PDF file, to be exact. It will have a private
|
| 582 |
+
attribute set on it that is named 'pages' that is a list containing all
|
| 583 |
+
the pages in the file.
|
| 584 |
+
|
| 585 |
+
When instantiating a PdfReader object, there are options available
|
| 586 |
+
for decompressing all the objects in the file. pdfrw does not currently
|
| 587 |
+
have very many options for decompression, so this is not all that useful,
|
| 588 |
+
except in the specific case of compressed object streams.
|
| 589 |
+
|
| 590 |
+
Also, there are no options for decryption yet. If you have PDF files
|
| 591 |
+
that are encrypted or heavily compressed, you may find that using another
|
| 592 |
+
program like pdftk on them can make them readable by pdfrw.
|
| 593 |
+
|
| 594 |
+
In general, the objects are read from the file lazily, but this is not
|
| 595 |
+
currently true with compressed object streams -- all of these are decompressed
|
| 596 |
+
and read in when the PdfReader is instantiated.
|
| 597 |
+
|
| 598 |
+
|
| 599 |
+
File output
|
| 600 |
+
-----------
|
| 601 |
+
|
| 602 |
+
`pdfwriter.py`__
|
| 603 |
+
contains the PdfWriter class, which can create and output a PDF file.
|
| 604 |
+
|
| 605 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/pdfrw/pdfwriter.py
|
| 606 |
+
|
| 607 |
+
There are a few options available when creating and using this class.
|
| 608 |
+
|
| 609 |
+
In the simplest case, an instance of PdfWriter is instantiated, and
|
| 610 |
+
then pages are added to it from one or more source files (or created
|
| 611 |
+
programmatically), and then the write method is called to dump the
|
| 612 |
+
results out to a file.
|
| 613 |
+
|
| 614 |
+
If you have a source PDF and do not want to disturb the structure
|
| 615 |
+
of it too badly, then you may pass its trailer directly to PdfWriter
|
| 616 |
+
rather than letting PdfWriter construct one for you. There is an
|
| 617 |
+
example of this (alter.py) in the examples directory.
|
| 618 |
+
|
| 619 |
+
|
| 620 |
+
Advanced features
|
| 621 |
+
-----------------
|
| 622 |
+
|
| 623 |
+
`buildxobj.py`__
|
| 624 |
+
contains functions to build Form XObjects out of pages or rectangles on
|
| 625 |
+
pages. These may be reused in new PDFs essentially as if they were images.
|
| 626 |
+
|
| 627 |
+
buildxobj is careful to cache any page used so that it only appears in
|
| 628 |
+
the output once.
|
| 629 |
+
|
| 630 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/pdfrw/buildxobj.py
|
| 631 |
+
|
| 632 |
+
|
| 633 |
+
`toreportlab.py`__
|
| 634 |
+
provides the makerl function, which will translate pdfrw objects into a
|
| 635 |
+
format which can be used with `reportlab <http://www.reportlab.org/>`__.
|
| 636 |
+
It is normally used in conjunction with buildxobj, to be able to reuse
|
| 637 |
+
parts of existing PDFs when using reportlab.
|
| 638 |
+
|
| 639 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/pdfrw/toreportlab.py
|
| 640 |
+
|
| 641 |
+
|
| 642 |
+
`pagemerge.py`__ builds on the foundation laid by buildxobj. It
|
| 643 |
+
contains classes to create a new page (or overlay an existing page)
|
| 644 |
+
using one or more rectangles from other pages. There are examples
|
| 645 |
+
showing its use for watermarking, scaling, 4-up output, splitting
|
| 646 |
+
each page in 2, etc.
|
| 647 |
+
|
| 648 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/pdfrw/pagemerge.py
|
| 649 |
+
|
| 650 |
+
`findobjs.py`__ contains code that can find specific kinds of objects
|
| 651 |
+
inside a PDF file. The extract.py example uses this module to create
|
| 652 |
+
a new PDF that places each image and Form XObject from a source PDF onto
|
| 653 |
+
its own page, e.g. for easy reuse with some of the other examples or
|
| 654 |
+
with reportlab.
|
| 655 |
+
|
| 656 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/pdfrw/findobjs.py
|
| 657 |
+
|
| 658 |
+
|
| 659 |
+
Miscellaneous
|
| 660 |
+
----------------
|
| 661 |
+
|
| 662 |
+
`compress.py`__ and `uncompress.py`__
|
| 663 |
+
contains compression and decompression functions. Very few filters are
|
| 664 |
+
currently supported, so an external tool like pdftk might be good if you
|
| 665 |
+
require the ability to decompress (or, for that matter, decrypt) PDF
|
| 666 |
+
files.
|
| 667 |
+
|
| 668 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/pdfrw/compress.py
|
| 669 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/pdfrw/uncompress.py
|
| 670 |
+
|
| 671 |
+
|
| 672 |
+
`py23_diffs.py`__ contains code to help manage the differences between
|
| 673 |
+
Python 2 and Python 3.
|
| 674 |
+
|
| 675 |
+
__ https://github.com/pmaupin/pdfrw/tree/master/pdfrw/py23_diffs.py
|
| 676 |
+
|
| 677 |
+
Testing
|
| 678 |
+
===============
|
| 679 |
+
|
| 680 |
+
The tests associated with pdfrw require a large number of PDFs,
|
| 681 |
+
which are not distributed with the library.
|
| 682 |
+
|
| 683 |
+
To run the tests:
|
| 684 |
+
|
| 685 |
+
* Download or clone the full package from github.com/pmaupin/pdfrw
|
| 686 |
+
* cd into the tests directory, and then clone the package
|
| 687 |
+
github.com/pmaupin/static_pdfs into a subdirectory (also named
|
| 688 |
+
static_pdfs).
|
| 689 |
+
* Now the tests may be run from that directory using unittest, or
|
| 690 |
+
py.test, or nose.
|
| 691 |
+
* travisci is used at github, and runs the tests with py.test
|
| 692 |
+
|
| 693 |
+
Other libraries
|
| 694 |
+
=====================
|
| 695 |
+
|
| 696 |
+
Pure Python
|
| 697 |
+
-----------
|
| 698 |
+
|
| 699 |
+
- `reportlab <http://www.reportlab.org/>`__
|
| 700 |
+
|
| 701 |
+
reportlab is must-have software if you want to programmatically
|
| 702 |
+
generate arbitrary PDFs.
|
| 703 |
+
|
| 704 |
+
- `pyPdf <https://github.com/mstamy2/PyPDF2>`__
|
| 705 |
+
|
| 706 |
+
pyPdf is, in some ways, very full-featured. It can do decompression
|
| 707 |
+
and decryption and seems to know a lot about items inside at least
|
| 708 |
+
some kinds of PDF files. In comparison, pdfrw knows less about
|
| 709 |
+
specific PDF file features (such as metadata), but focuses on trying
|
| 710 |
+
to have a more Pythonic API for mapping the PDF file container
|
| 711 |
+
syntax to Python, and (IMO) has a simpler and better PDF file
|
| 712 |
+
parser. The Form XObject capability of pdfrw means that, in many
|
| 713 |
+
cases, it does not actually need to decompress objects -- they
|
| 714 |
+
can be left compressed.
|
| 715 |
+
|
| 716 |
+
- `pdftools <http://www.boddie.org.uk/david/Projects/Python/pdftools/index.html>`__
|
| 717 |
+
|
| 718 |
+
pdftools feels large and I fell asleep trying to figure out how it
|
| 719 |
+
all fit together, but many others have done useful things with it.
|
| 720 |
+
|
| 721 |
+
- `pagecatcher <http://www.reportlab.com/docs/pagecatcher-ds.pdf>`__
|
| 722 |
+
|
| 723 |
+
My understanding is that pagecatcher would have done exactly what I
|
| 724 |
+
wanted when I built pdfrw. But I was on a zero budget, so I've never
|
| 725 |
+
had the pleasure of experiencing pagecatcher. I do, however, use and
|
| 726 |
+
like `reportlab <http://www.reportlab.org/>`__ (open source, from
|
| 727 |
+
the people who make pagecatcher) so I'm sure pagecatcher is great,
|
| 728 |
+
better documented and much more full-featured than pdfrw.
|
| 729 |
+
|
| 730 |
+
- `pdfminer <http://www.unixuser.org/~euske/python/pdfminer/index.html>`__
|
| 731 |
+
|
| 732 |
+
This looks like a useful, actively-developed program. It is quite
|
| 733 |
+
large, but then, it is trying to actively comprehend a full PDF
|
| 734 |
+
document. From the website:
|
| 735 |
+
|
| 736 |
+
"PDFMiner is a suite of programs that help extracting and analyzing
|
| 737 |
+
text data of PDF documents. Unlike other PDF-related tools, it
|
| 738 |
+
allows to obtain the exact location of texts in a page, as well as
|
| 739 |
+
other extra information such as font information or ruled lines. It
|
| 740 |
+
includes a PDF converter that can transform PDF files into other
|
| 741 |
+
text formats (such as HTML). It has an extensible PDF parser that
|
| 742 |
+
can be used for other purposes instead of text analysis."
|
| 743 |
+
|
| 744 |
+
non-pure-Python libraries
|
| 745 |
+
-------------------------
|
| 746 |
+
|
| 747 |
+
- `pyPoppler <https://launchpad.net/poppler-python/>`__ can read PDF
|
| 748 |
+
files.
|
| 749 |
+
- `pycairo <http://www.cairographics.org/pycairo/>`__ can write PDF
|
| 750 |
+
files.
|
| 751 |
+
- `PyMuPDF <https://github.com/rk700/PyMuPDF>`_ high performance rendering
|
| 752 |
+
of PDF, (Open)XPS, CBZ and EPUB
|
| 753 |
+
|
| 754 |
+
Other tools
|
| 755 |
+
-----------
|
| 756 |
+
|
| 757 |
+
- `pdftk <https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/>`__ is a wonderful command
|
| 758 |
+
line tool for basic PDF manipulation. It complements pdfrw extremely
|
| 759 |
+
well, supporting many operations such as decryption and decompression
|
| 760 |
+
that pdfrw cannot do.
|
| 761 |
+
- `MuPDF <http://www.mupdf.com/>`_ is a free top performance PDF, (Open)XPS, CBZ and EPUB rendering library
|
| 762 |
+
that also comes with some command line tools. One of those, ``mutool``, has big overlaps with pdftk's -
|
| 763 |
+
except it is up to 10 times faster.
|
| 764 |
+
|
| 765 |
+
Release information
|
| 766 |
+
=======================
|
| 767 |
+
|
| 768 |
+
Revisions:
|
| 769 |
+
|
| 770 |
+
0.4 -- Released 18 September, 2017
|
| 771 |
+
|
| 772 |
+
- Python 3.6 added to test matrix
|
| 773 |
+
- Proper unicode support for text strings in PDFs added
|
| 774 |
+
- buildxobj fixes allow better support creating form XObjects
|
| 775 |
+
out of compressed pages in some cases
|
| 776 |
+
- Compression fixes for Python 3+
|
| 777 |
+
- New subset_booklets.py example
|
| 778 |
+
- Bug with non-compressed indices into compressed object streams fixed
|
| 779 |
+
- Bug with distinguishing compressed object stream first objects fixed
|
| 780 |
+
- Better error reporting added for some invalid PDFs (e.g. when reading
|
| 781 |
+
past the end of file)
|
| 782 |
+
- Better scrubbing of old bookmark information when writing PDFs, to
|
| 783 |
+
remove dangling references
|
| 784 |
+
- Refactoring of pdfwriter, including updating API, to allow future
|
| 785 |
+
enhancements for things like incremental writing
|
| 786 |
+
- Minor tokenizer speedup
|
| 787 |
+
- Some flate decompressor bugs fixed
|
| 788 |
+
- Compression and decompression tests added
|
| 789 |
+
- Tests for new unicode handling added
|
| 790 |
+
- PdfReader.readpages() recursion error (issue #92) fixed.
|
| 791 |
+
- Initial crypt filter support added
|
| 792 |
+
|
| 793 |
+
|
| 794 |
+
0.3 -- Released 19 October, 2016.
|
| 795 |
+
|
| 796 |
+
- Python 3.5 added to test matrix
|
| 797 |
+
- Better support under Python 3.x for in-memory PDF file-like objects
|
| 798 |
+
- Some pagemerge and Unicode patches added
|
| 799 |
+
- Changes to logging allow better coexistence with other packages
|
| 800 |
+
- Fix for "from pdfrw import \*"
|
| 801 |
+
- New fancy_watermark.py example shows off capabilities of pagemerge.py
|
| 802 |
+
- metadata.py example renamed to cat.py
|
| 803 |
+
|
| 804 |
+
|
| 805 |
+
0.2 -- Released 21 June, 2015. Supports Python 2.6, 2.7, 3.3, and 3.4.
|
| 806 |
+
|
| 807 |
+
- Several bugs have been fixed
|
| 808 |
+
- New regression test functionally tests core with dozens of
|
| 809 |
+
PDFs, and also tests examples.
|
| 810 |
+
- Core has been ported and tested on Python3 by round-tripping
|
| 811 |
+
several difficult files and observing binary matching results
|
| 812 |
+
across the different Python versions.
|
| 813 |
+
- Still only minimal support for compression and no support
|
| 814 |
+
for encryption or newer PDF features. (pdftk is useful
|
| 815 |
+
to put PDFs in a form that pdfrw can use.)
|
| 816 |
+
|
| 817 |
+
0.1 -- Released to PyPI in 2012. Supports Python 2.5 - 2.7
|
| 818 |
+
|
| 819 |
+
|
| 820 |
+
|
8210_A1P3-master/Lib/site-packages/pdfrw-0.4.dist-info/RECORD
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pdfrw/__init__.py,sha256=9FFH1bTZ-G4v8TmoQs02P-mKMJanmVfXraHvCP4uG-M,714
|
| 2 |
+
pdfrw/buildxobj.py,sha256=NkBDhvnPUpqB21J5277wRwvtEag4G9uHNVoWu17ffxA,12391
|
| 3 |
+
pdfrw/compress.py,sha256=J7IN1E_sBcB8fPDPgPVK3xY7NPcJVx6WH26VMSdYrwo,844
|
| 4 |
+
pdfrw/crypt.py,sha256=4UzGRCBy95WSP0lBHJUcZ8FCggqRVyGTwqFOiYlA8lA,4711
|
| 5 |
+
pdfrw/errors.py,sha256=OQagKuUxAn5GS2Vz8EUFIy5dxIm6YGLSdI0dUcHroPg,855
|
| 6 |
+
pdfrw/findobjs.py,sha256=9jC-331zD_89YyiS2sTYVthISsfKBBeukBMTis_wPQY,4640
|
| 7 |
+
pdfrw/pagemerge.py,sha256=Evoc-aONIeRi76tai6JNnmZITkCHErdfxiXRyGRpKhg,8646
|
| 8 |
+
pdfrw/pdfreader.py,sha256=Ccij2Jxk_iQROy4IXNKV_UsYusD2-sHj9HQM5pCQ0p8,25990
|
| 9 |
+
pdfrw/pdfwriter.py,sha256=cjH0KuOE4hArNtj6JARdcQnMOLUJU87dpTIbTSU8Bgk,13055
|
| 10 |
+
pdfrw/py23_diffs.py,sha256=tOaBrjYLDXSvZU-MdgXy-WHGMDQzldCC0ZPjad9hPyE,943
|
| 11 |
+
pdfrw/tokens.py,sha256=SqytfCrJVHTtYa4Y719rzTNz9Wub--yhHlGoqszG1xo,8644
|
| 12 |
+
pdfrw/toreportlab.py,sha256=IOIMQS35kb-FgzALXWGSpzVwb9YwnPiw2drY-2e_qg0,4385
|
| 13 |
+
pdfrw/uncompress.py,sha256=BmOWOUXo4LfZ2NuYMemQ7AIKdzjSi4ymP_lIQvlgHDQ,4633
|
| 14 |
+
pdfrw/objects/__init__.py,sha256=Jfco1zYOrLgXuus_tQcwWexyKQzMHIi_SUjjEMrfdqE,654
|
| 15 |
+
pdfrw/objects/pdfarray.py,sha256=hM9qJ3l-gXh3YfRABjYwzTmljMuLteOWouvuiUjFld8,2012
|
| 16 |
+
pdfrw/objects/pdfdict.py,sha256=fEiBEHSOJyGVYyVu7YMtZt5gxSltldAA_En7QegLRkQ,8363
|
| 17 |
+
pdfrw/objects/pdfindirect.py,sha256=RqiWtpLbeYmftG-Tv5-_qKACNd40FbhA1Ib1VyGdjQo,718
|
| 18 |
+
pdfrw/objects/pdfname.py,sha256=Er8nIlBhC4jcBmOf7EtMwlTZAmGUIndvwHiKkWdsMVQ,2562
|
| 19 |
+
pdfrw/objects/pdfobject.py,sha256=6HjsPbsxMhavG4erlj_8jz5ld4Y_AM2gjHCLz91mmsk,385
|
| 20 |
+
pdfrw/objects/pdfstring.py,sha256=5PEsC062JVR6kVO1O5akSfXccUZs3tUIeksEuv_ShZY,23234
|
| 21 |
+
pdfrw-0.4.dist-info/DESCRIPTION.rst,sha256=myfQQ0e2rAxQkHRL5yztGPSW87yDjJT5XHlnEKBlPos,31267
|
| 22 |
+
pdfrw-0.4.dist-info/METADATA,sha256=A_h68f6ZD-SbO7ci8mpjwAlDscQVo3MnQ2LW1hOuQbE,32398
|
| 23 |
+
pdfrw-0.4.dist-info/RECORD,,
|
| 24 |
+
pdfrw-0.4.dist-info/WHEEL,sha256=o2k-Qa-RMNIJmUdIc7KU6VWR_ErNRbWNlxDIpl7lm34,110
|
| 25 |
+
pdfrw-0.4.dist-info/metadata.json,sha256=IUe9p4Xlv5gDj0XjYJcT5-C5cbQtW2AafJIZ4yg0C_E,1226
|
| 26 |
+
pdfrw-0.4.dist-info/top_level.txt,sha256=X9Jw2_LyhwZSsHQB03ht4DtoM2c_bJJaw441ODoPNdo,6
|
| 27 |
+
pdfrw-0.4.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
| 28 |
+
pdfrw-0.4.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
| 29 |
+
pdfrw/objects/__pycache__/pdfarray.cpython-37.pyc,,
|
| 30 |
+
pdfrw/objects/__pycache__/pdfdict.cpython-37.pyc,,
|
| 31 |
+
pdfrw/objects/__pycache__/pdfindirect.cpython-37.pyc,,
|
| 32 |
+
pdfrw/objects/__pycache__/pdfname.cpython-37.pyc,,
|
| 33 |
+
pdfrw/objects/__pycache__/pdfobject.cpython-37.pyc,,
|
| 34 |
+
pdfrw/objects/__pycache__/pdfstring.cpython-37.pyc,,
|
| 35 |
+
pdfrw/objects/__pycache__/__init__.cpython-37.pyc,,
|
| 36 |
+
pdfrw/__pycache__/buildxobj.cpython-37.pyc,,
|
| 37 |
+
pdfrw/__pycache__/compress.cpython-37.pyc,,
|
| 38 |
+
pdfrw/__pycache__/crypt.cpython-37.pyc,,
|
| 39 |
+
pdfrw/__pycache__/errors.cpython-37.pyc,,
|
| 40 |
+
pdfrw/__pycache__/findobjs.cpython-37.pyc,,
|
| 41 |
+
pdfrw/__pycache__/pagemerge.cpython-37.pyc,,
|
| 42 |
+
pdfrw/__pycache__/pdfreader.cpython-37.pyc,,
|
| 43 |
+
pdfrw/__pycache__/pdfwriter.cpython-37.pyc,,
|
| 44 |
+
pdfrw/__pycache__/py23_diffs.cpython-37.pyc,,
|
| 45 |
+
pdfrw/__pycache__/tokens.cpython-37.pyc,,
|
| 46 |
+
pdfrw/__pycache__/toreportlab.cpython-37.pyc,,
|
| 47 |
+
pdfrw/__pycache__/uncompress.cpython-37.pyc,,
|
| 48 |
+
pdfrw/__pycache__/__init__.cpython-37.pyc,,
|
8210_A1P3-master/Lib/site-packages/pdfrw-0.4.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: bdist_wheel (0.29.0)
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py2-none-any
|
| 5 |
+
Tag: py3-none-any
|
| 6 |
+
|
8210_A1P3-master/Lib/site-packages/pdfrw-0.4.dist-info/metadata.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"classifiers": ["Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Topic :: Multimedia :: Graphics :: Graphics Conversion", "Topic :: Software Development :: Libraries", "Topic :: Text Processing", "Topic :: Printing", "Topic :: Utilities"], "extensions": {"python.details": {"contacts": [{"email": "pmaupin@gmail.com", "name": "Patrick Maupin", "role": "author"}], "document_names": {"description": "DESCRIPTION.rst"}, "project_urls": {"Home": "https://github.com/pmaupin/pdfrw"}}}, "generator": "bdist_wheel (0.29.0)", "keywords": ["pdf", "vector", "graphics", "PDF", "nup", "watermark", "split", "join", "merge"], "license": "MIT", "metadata_version": "2.0", "name": "pdfrw", "platform": "Independent", "summary": "PDF file reader/writer library", "version": "0.4"}
|