__init__.py000064400000006516147205641420006672 0ustar00"""A collection of modules for building different kinds of tree from HTML documents. To create a treebuilder for a new type of tree, you need to do implement several things: 1) A set of classes for various types of elements: Document, Doctype, Comment, Element. These must implement the interface of _base.treebuilders.Node (although comment nodes have a different signature for their constructor, see treebuilders.etree.Comment) Textual content may also be implemented as another node type, or not, as your tree implementation requires. 2) A treebuilder object (called TreeBuilder by convention) that inherits from treebuilders._base.TreeBuilder. This has 4 required attributes: documentClass - the class to use for the bottommost node of a document elementClass - the class to use for HTML Elements commentClass - the class to use for comments doctypeClass - the class to use for doctypes It also has one required method: getDocument - Returns the root node of the complete document tree 3) If you wish to run the unit tests, you must also create a testSerializer method on your treebuilder which accepts a node and returns a string containing Node and its children serialized according to the format used in the unittests """ from __future__ import absolute_import, division, unicode_literals from .._utils import default_etree treeBuilderCache = {} def getTreeBuilder(treeType, implementation=None, **kwargs): """Get a TreeBuilder class for various types of tree with built-in support treeType - the name of the tree type required (case-insensitive). Supported values are: "dom" - A generic builder for DOM implementations, defaulting to a xml.dom.minidom based implementation. "etree" - A generic builder for tree implementations exposing an ElementTree-like interface, defaulting to xml.etree.cElementTree if available and xml.etree.ElementTree if not. "lxml" - A etree-based builder for lxml.etree, handling limitations of lxml's implementation. implementation - (Currently applies to the "etree" and "dom" tree types). A module implementing the tree type e.g. xml.etree.ElementTree or xml.etree.cElementTree.""" treeType = treeType.lower() if treeType not in treeBuilderCache: if treeType == "dom": from . import dom # Come up with a sane default (pref. from the stdlib) if implementation is None: from xml.dom import minidom implementation = minidom # NEVER cache here, caching is done in the dom submodule return dom.getDomModule(implementation, **kwargs).TreeBuilder elif treeType == "lxml": from . import etree_lxml treeBuilderCache[treeType] = etree_lxml.TreeBuilder elif treeType == "etree": from . import etree if implementation is None: implementation = default_etree # NEVER cache here, caching is done in the etree submodule return etree.getETreeModule(implementation, **kwargs).TreeBuilder else: raise ValueError("""Unrecognised treebuilder "%s" """ % treeType) return treeBuilderCache.get(treeType) __init__.pyc000064400000006466147205641420007041 0ustar00 abc@`sHdZddlmZmZmZddlmZiZddZ dS(uA collection of modules for building different kinds of tree from HTML documents. To create a treebuilder for a new type of tree, you need to do implement several things: 1) A set of classes for various types of elements: Document, Doctype, Comment, Element. These must implement the interface of _base.treebuilders.Node (although comment nodes have a different signature for their constructor, see treebuilders.etree.Comment) Textual content may also be implemented as another node type, or not, as your tree implementation requires. 2) A treebuilder object (called TreeBuilder by convention) that inherits from treebuilders._base.TreeBuilder. This has 4 required attributes: documentClass - the class to use for the bottommost node of a document elementClass - the class to use for HTML Elements commentClass - the class to use for comments doctypeClass - the class to use for doctypes It also has one required method: getDocument - Returns the root node of the complete document tree 3) If you wish to run the unit tests, you must also create a testSerializer method on your treebuilder which accepts a node and returns a string containing Node and its children serialized according to the format used in the unittests i(tabsolute_importtdivisiontunicode_literalsi(t default_etreecK`s|j}|tkr|dkrlddlm}|d krYddlm}|}n|j||jS|dkrddlm }|jt|s__init__.pyo000064400000006466147205641420007055 0ustar00 abc@`sHdZddlmZmZmZddlmZiZddZ dS(uA collection of modules for building different kinds of tree from HTML documents. To create a treebuilder for a new type of tree, you need to do implement several things: 1) A set of classes for various types of elements: Document, Doctype, Comment, Element. These must implement the interface of _base.treebuilders.Node (although comment nodes have a different signature for their constructor, see treebuilders.etree.Comment) Textual content may also be implemented as another node type, or not, as your tree implementation requires. 2) A treebuilder object (called TreeBuilder by convention) that inherits from treebuilders._base.TreeBuilder. This has 4 required attributes: documentClass - the class to use for the bottommost node of a document elementClass - the class to use for HTML Elements commentClass - the class to use for comments doctypeClass - the class to use for doctypes It also has one required method: getDocument - Returns the root node of the complete document tree 3) If you wish to run the unit tests, you must also create a testSerializer method on your treebuilder which accepts a node and returns a string containing Node and its children serialized according to the format used in the unittests i(tabsolute_importtdivisiontunicode_literalsi(t default_etreecK`s|j}|tkr|dkrlddlm}|d krYddlm}|}n|j||jS|dkrddlm }|jt|sbase.py000064400000033166147205641420006046 0ustar00from __future__ import absolute_import, division, unicode_literals from pip._vendor.six import text_type from ..constants import scopingElements, tableInsertModeElements, namespaces # The scope markers are inserted when entering object elements, # marquees, table cells, and table captions, and are used to prevent formatting # from "leaking" into tables, object elements, and marquees. Marker = None listElementsMap = { None: (frozenset(scopingElements), False), "button": (frozenset(scopingElements | set([(namespaces["html"], "button")])), False), "list": (frozenset(scopingElements | set([(namespaces["html"], "ol"), (namespaces["html"], "ul")])), False), "table": (frozenset([(namespaces["html"], "html"), (namespaces["html"], "table")]), False), "select": (frozenset([(namespaces["html"], "optgroup"), (namespaces["html"], "option")]), True) } class Node(object): def __init__(self, name): """Node representing an item in the tree. name - The tag name associated with the node parent - The parent of the current node (or None for the document node) value - The value of the current node (applies to text nodes and comments attributes - a dict holding name, value pairs for attributes of the node childNodes - a list of child nodes of the current node. This must include all elements but not necessarily other node types _flags - A list of miscellaneous flags that can be set on the node """ self.name = name self.parent = None self.value = None self.attributes = {} self.childNodes = [] self._flags = [] def __str__(self): attributesStr = " ".join(["%s=\"%s\"" % (name, value) for name, value in self.attributes.items()]) if attributesStr: return "<%s %s>" % (self.name, attributesStr) else: return "<%s>" % (self.name) def __repr__(self): return "<%s>" % (self.name) def appendChild(self, node): """Insert node as a child of the current node """ raise NotImplementedError def insertText(self, data, insertBefore=None): """Insert data as text in the current node, positioned before the start of node insertBefore or to the end of the node's text. """ raise NotImplementedError def insertBefore(self, node, refNode): """Insert node as a child of the current node, before refNode in the list of child nodes. Raises ValueError if refNode is not a child of the current node""" raise NotImplementedError def removeChild(self, node): """Remove node from the children of the current node """ raise NotImplementedError def reparentChildren(self, newParent): """Move all the children of the current node to newParent. This is needed so that trees that don't store text as nodes move the text in the correct way """ # XXX - should this method be made more general? for child in self.childNodes: newParent.appendChild(child) self.childNodes = [] def cloneNode(self): """Return a shallow copy of the current node i.e. a node with the same name and attributes but with no parent or child nodes """ raise NotImplementedError def hasContent(self): """Return true if the node has children or text, false otherwise """ raise NotImplementedError class ActiveFormattingElements(list): def append(self, node): equalCount = 0 if node != Marker: for element in self[::-1]: if element == Marker: break if self.nodesEqual(element, node): equalCount += 1 if equalCount == 3: self.remove(element) break list.append(self, node) def nodesEqual(self, node1, node2): if not node1.nameTuple == node2.nameTuple: return False if not node1.attributes == node2.attributes: return False return True class TreeBuilder(object): """Base treebuilder implementation documentClass - the class to use for the bottommost node of a document elementClass - the class to use for HTML Elements commentClass - the class to use for comments doctypeClass - the class to use for doctypes """ # pylint:disable=not-callable # Document class documentClass = None # The class to use for creating a node elementClass = None # The class to use for creating comments commentClass = None # The class to use for creating doctypes doctypeClass = None # Fragment class fragmentClass = None def __init__(self, namespaceHTMLElements): if namespaceHTMLElements: self.defaultNamespace = "http://www.w3.org/1999/xhtml" else: self.defaultNamespace = None self.reset() def reset(self): self.openElements = [] self.activeFormattingElements = ActiveFormattingElements() # XXX - rename these to headElement, formElement self.headPointer = None self.formPointer = None self.insertFromTable = False self.document = self.documentClass() def elementInScope(self, target, variant=None): # If we pass a node in we match that. if we pass a string # match any node with that name exactNode = hasattr(target, "nameTuple") if not exactNode: if isinstance(target, text_type): target = (namespaces["html"], target) assert isinstance(target, tuple) listElements, invert = listElementsMap[variant] for node in reversed(self.openElements): if exactNode and node == target: return True elif not exactNode and node.nameTuple == target: return True elif (invert ^ (node.nameTuple in listElements)): return False assert False # We should never reach this point def reconstructActiveFormattingElements(self): # Within this algorithm the order of steps described in the # specification is not quite the same as the order of steps in the # code. It should still do the same though. # Step 1: stop the algorithm when there's nothing to do. if not self.activeFormattingElements: return # Step 2 and step 3: we start with the last element. So i is -1. i = len(self.activeFormattingElements) - 1 entry = self.activeFormattingElements[i] if entry == Marker or entry in self.openElements: return # Step 6 while entry != Marker and entry not in self.openElements: if i == 0: # This will be reset to 0 below i = -1 break i -= 1 # Step 5: let entry be one earlier in the list. entry = self.activeFormattingElements[i] while True: # Step 7 i += 1 # Step 8 entry = self.activeFormattingElements[i] clone = entry.cloneNode() # Mainly to get a new copy of the attributes # Step 9 element = self.insertElement({"type": "StartTag", "name": clone.name, "namespace": clone.namespace, "data": clone.attributes}) # Step 10 self.activeFormattingElements[i] = element # Step 11 if element == self.activeFormattingElements[-1]: break def clearActiveFormattingElements(self): entry = self.activeFormattingElements.pop() while self.activeFormattingElements and entry != Marker: entry = self.activeFormattingElements.pop() def elementInActiveFormattingElements(self, name): """Check if an element exists between the end of the active formatting elements and the last marker. If it does, return it, else return false""" for item in self.activeFormattingElements[::-1]: # Check for Marker first because if it's a Marker it doesn't have a # name attribute. if item == Marker: break elif item.name == name: return item return False def insertRoot(self, token): element = self.createElement(token) self.openElements.append(element) self.document.appendChild(element) def insertDoctype(self, token): name = token["name"] publicId = token["publicId"] systemId = token["systemId"] doctype = self.doctypeClass(name, publicId, systemId) self.document.appendChild(doctype) def insertComment(self, token, parent=None): if parent is None: parent = self.openElements[-1] parent.appendChild(self.commentClass(token["data"])) def createElement(self, token): """Create an element but don't insert it anywhere""" name = token["name"] namespace = token.get("namespace", self.defaultNamespace) element = self.elementClass(name, namespace) element.attributes = token["data"] return element def _getInsertFromTable(self): return self._insertFromTable def _setInsertFromTable(self, value): """Switch the function used to insert an element from the normal one to the misnested table one and back again""" self._insertFromTable = value if value: self.insertElement = self.insertElementTable else: self.insertElement = self.insertElementNormal insertFromTable = property(_getInsertFromTable, _setInsertFromTable) def insertElementNormal(self, token): name = token["name"] assert isinstance(name, text_type), "Element %s not unicode" % name namespace = token.get("namespace", self.defaultNamespace) element = self.elementClass(name, namespace) element.attributes = token["data"] self.openElements[-1].appendChild(element) self.openElements.append(element) return element def insertElementTable(self, token): """Create an element and insert it into the tree""" element = self.createElement(token) if self.openElements[-1].name not in tableInsertModeElements: return self.insertElementNormal(token) else: # We should be in the InTable mode. This means we want to do # special magic element rearranging parent, insertBefore = self.getTableMisnestedNodePosition() if insertBefore is None: parent.appendChild(element) else: parent.insertBefore(element, insertBefore) self.openElements.append(element) return element def insertText(self, data, parent=None): """Insert text data.""" if parent is None: parent = self.openElements[-1] if (not self.insertFromTable or (self.insertFromTable and self.openElements[-1].name not in tableInsertModeElements)): parent.insertText(data) else: # We should be in the InTable mode. This means we want to do # special magic element rearranging parent, insertBefore = self.getTableMisnestedNodePosition() parent.insertText(data, insertBefore) def getTableMisnestedNodePosition(self): """Get the foster parent element, and sibling to insert before (or None) when inserting a misnested table node""" # The foster parent element is the one which comes before the most # recently opened table element # XXX - this is really inelegant lastTable = None fosterParent = None insertBefore = None for elm in self.openElements[::-1]: if elm.name == "table": lastTable = elm break if lastTable: # XXX - we should really check that this parent is actually a # node here if lastTable.parent: fosterParent = lastTable.parent insertBefore = lastTable else: fosterParent = self.openElements[ self.openElements.index(lastTable) - 1] else: fosterParent = self.openElements[0] return fosterParent, insertBefore def generateImpliedEndTags(self, exclude=None): name = self.openElements[-1].name # XXX td, th and tr are not actually needed if (name in frozenset(("dd", "dt", "li", "option", "optgroup", "p", "rp", "rt")) and name != exclude): self.openElements.pop() # XXX This is not entirely what the specification says. We should # investigate it more closely. self.generateImpliedEndTags(exclude) def getDocument(self): "Return the final tree" return self.document def getFragment(self): "Return the final fragment" # assert self.innerHTML fragment = self.fragmentClass() self.openElements[0].reparentChildren(fragment) return fragment def testSerializer(self, node): """Serialize the subtree of node in the format required by unit tests node - the node from which to start serializing""" raise NotImplementedError base.pyc000064400000033704147205641420006207 0ustar00 abc@`shddlmZmZmZddlmZddlmZmZm Z dZ ie ee fd6e eee ddfgBe fd6e eee ddfe ddfgBe fd 6e e ddfe dd fge fd 6e e dd fe dd fgefd 6ZdefdYZdefdYZdefdYZdS(i(tabsolute_importtdivisiontunicode_literals(t text_typei(tscopingElementsttableInsertModeElementst namespacesuhtmlubuttonuoluululistutableuoptgroupuoptionuselecttNodecB`seeZdZdZdZdZd dZdZdZ dZ dZ d Z RS( cC`s:||_d|_d|_i|_g|_g|_dS(u6Node representing an item in the tree. name - The tag name associated with the node parent - The parent of the current node (or None for the document node) value - The value of the current node (applies to text nodes and comments attributes - a dict holding name, value pairs for attributes of the node childNodes - a list of child nodes of the current node. This must include all elements but not necessarily other node types _flags - A list of miscellaneous flags that can be set on the node N(tnametNonetparenttvaluet attributest childNodest_flags(tselfR((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyt__init__s     cC`sadjg|jjD]\}}d||f^q}|rRd|j|fSd|jSdS(Nu u%s="%s"u<%s %s>u<%s>(tjoinR titemsR(RRR t attributesStr((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyt__str__*s  2cC`s d|jS(Nu<%s>(R(R((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyt__repr__3scC`s tdS(u3Insert node as a child of the current node N(tNotImplementedError(Rtnode((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyt appendChild6scC`s tdS(uInsert data as text in the current node, positioned before the start of node insertBefore or to the end of the node's text. N(R(Rtdatat insertBefore((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyt insertText;scC`s tdS(uInsert node as a child of the current node, before refNode in the list of child nodes. Raises ValueError if refNode is not a child of the current nodeN(R(RRtrefNode((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyRAscC`s tdS(u:Remove node from the children of the current node N(R(RR((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyt removeChildGscC`s.x|jD]}|j|q Wg|_dS(uMove all the children of the current node to newParent. This is needed so that trees that don't store text as nodes move the text in the correct way N(R R(Rt newParenttchild((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pytreparentChildrenLscC`s tdS(uReturn a shallow copy of the current node i.e. a node with the same name and attributes but with no parent or child nodes N(R(R((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyt cloneNodeVscC`s tdS(uFReturn true if the node has children or text, false otherwise N(R(R((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyt hasContent\sN( t__name__t __module__RRRRR RRRR R!R"(((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyRs       tActiveFormattingElementscB`seZdZdZRS(cC`sd}|tkrxj|dddD]R}|tkr<Pn|j||r[|d7}n|dkr&|j|Pq&q&Wntj||dS(Niiii(tMarkert nodesEqualtremovetlisttappend(RRt equalCounttelement((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyR*cs      cC`s0|j|jkstS|j|jks,tStS(N(t nameTupletFalseR tTrue(Rtnode1tnode2((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyR'ps (R#R$R*R'(((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyR%bs t TreeBuildercB`seZdZdZdZdZdZdZdZ dZ ddZ dZ dZ dZdZdZdd Zd Zd Zd ZeeeZd ZdZddZdZddZdZdZdZRS(uBase treebuilder implementation documentClass - the class to use for the bottommost node of a document elementClass - the class to use for HTML Elements commentClass - the class to use for comments doctypeClass - the class to use for doctypes cC`s)|rd|_n d|_|jdS(Nuhttp://www.w3.org/1999/xhtml(tdefaultNamespaceR treset(RtnamespaceHTMLElements((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyRs  cC`sCg|_t|_d|_d|_t|_|j|_ dS(N( t openElementsR%tactiveFormattingElementsR t headPointert formPointerR.tinsertFromTablet documentClasstdocument(R((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyR4s      cC`st|d}|sOt|tr7td|f}nt|tsOtnt|\}}x^t|jD]M}|r||krt S| r|j |krt S||j |kArot SqoWt stdS(Nu nameTupleuhtml( thasattrt isinstanceRRttupletAssertionErrortlistElementsMaptreversedR6R/R-R.(Rttargettvariantt exactNodet listElementstinvertR((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pytelementInScopescC`s'|js dSt|jd}|j|}|tksH||jkrLdSxL|tkr||jkr|dkrd}Pn|d8}|j|}qOWxtr"|d7}|j|}|j}|jidd6|jd6|jd6|j d6}||j|<||jdkrPqqWdS( NiiiuStartTagutypeunameu namespaceudata( R7tlenR&R6R/R!t insertElementRt namespaceR (RtitentrytcloneR,((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyt#reconstructActiveFormattingElementss.           cC`s>|jj}x(|jr9|tkr9|jj}qWdS(N(R7tpopR&(RRM((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pytclearActiveFormattingElementsscC`sHxA|jdddD])}|tkr-Pq|j|kr|SqWtS(uCheck if an element exists between the end of the active formatting elements and the last marker. If it does, return it, else return falseNi(R7R&RR.(RRtitem((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyt!elementInActiveFormattingElementss  cC`s3|j|}|jj||jj|dS(N(t createElementR6R*R<R(RttokenR,((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyt insertRootscC`sG|d}|d}|d}|j|||}|jj|dS(NunameupublicIdusystemId(t doctypeClassR<R(RRURtpublicIdtsystemIdtdoctype((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyt insertDoctypes    cC`s:|dkr|jd}n|j|j|ddS(Niudata(R R6Rt commentClass(RRUR ((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyt insertComment s cC`sB|d}|jd|j}|j||}|d|_|S(u.Create an element but don't insert it anywhereunameu namespaceudata(tgetR3t elementClassR (RRURRKR,((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyRTs   cC`s|jS(N(t_insertFromTable(R((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyt_getInsertFromTablescC`s.||_|r|j|_n |j|_dS(usSwitch the function used to insert an element from the normal one to the misnested table one and back againN(R`tinsertElementTableRJtinsertElementNormal(RR ((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyt_setInsertFromTables cC`s|d}t|ts)td||jd|j}|j||}|d|_|jdj||jj ||S(NunameuElement %s not unicodeu namespaceudatai( R>RR@R^R3R_R R6RR*(RRURRKR,((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyRc$s  cC`s|j|}|jdjtkr2|j|S|j\}}|dkr`|j|n|j|||jj ||S(u-Create an element and insert it into the treeiN( RTR6RRRctgetTableMisnestedNodePositionR RRR*(RRUR,R R((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyRb.s  cC`s{|dkr|jd}n|j sE|jrU|jdjtkrU|j|n"|j\}}|j||dS(uInsert text data.iN(R R6R:RRRRe(RRR R((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyR>s   cC`sd}d}d}x7|jdddD]}|jdkr)|}Pq)q)W|r|jrm|j}|}q|j|jj|d}n |jd}||fS(usGet the foster parent element, and sibling to insert before (or None) when inserting a misnested table nodeNiutableii(R R6RR tindex(Rt lastTablet fosterParentRtelm((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyReMs    c C`sO|jdj}|td krK||krK|jj|j|ndS( Niuddudtuliuoptionuoptgroupupurpurt(uddudtuliuoptionuoptgroupupurpurt(R6Rt frozensetRPtgenerateImpliedEndTags(RtexcludeR((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyRkgs   cC`s|jS(uReturn the final tree(R<(R((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyt getDocumentqscC`s$|j}|jdj||S(uReturn the final fragmenti(t fragmentClassR6R (Rtfragment((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyt getFragmentus cC`s tdS(uzSerialize the subtree of node in the format required by unit tests node - the node from which to start serializingN(R(RR((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyttestSerializer|sN(R#R$t__doc__R R;R_R\RWRnRR4RHRORQRSRVR[R]RTRaRdtpropertyR:RcRbRReRkRmRpRq(((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyR2zs6   .             N(t __future__RRRtpip._vendor.sixRt constantsRRRR R&RjR.tsetR/RAtobjectRR)R%R2(((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyts*! Kbase.pyo000064400000033473147205641420006226 0ustar00 abc@`shddlmZmZmZddlmZddlmZmZm Z dZ ie ee fd6e eee ddfgBe fd6e eee ddfe ddfgBe fd 6e e ddfe dd fge fd 6e e dd fe dd fgefd 6ZdefdYZdefdYZdefdYZdS(i(tabsolute_importtdivisiontunicode_literals(t text_typei(tscopingElementsttableInsertModeElementst namespacesuhtmlubuttonuoluululistutableuoptgroupuoptionuselecttNodecB`seeZdZdZdZdZd dZdZdZ dZ dZ d Z RS( cC`s:||_d|_d|_i|_g|_g|_dS(u6Node representing an item in the tree. name - The tag name associated with the node parent - The parent of the current node (or None for the document node) value - The value of the current node (applies to text nodes and comments attributes - a dict holding name, value pairs for attributes of the node childNodes - a list of child nodes of the current node. This must include all elements but not necessarily other node types _flags - A list of miscellaneous flags that can be set on the node N(tnametNonetparenttvaluet attributest childNodest_flags(tselfR((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyt__init__s     cC`sadjg|jjD]\}}d||f^q}|rRd|j|fSd|jSdS(Nu u%s="%s"u<%s %s>u<%s>(tjoinR titemsR(RRR t attributesStr((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyt__str__*s  2cC`s d|jS(Nu<%s>(R(R((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyt__repr__3scC`s tdS(u3Insert node as a child of the current node N(tNotImplementedError(Rtnode((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyt appendChild6scC`s tdS(uInsert data as text in the current node, positioned before the start of node insertBefore or to the end of the node's text. N(R(Rtdatat insertBefore((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyt insertText;scC`s tdS(uInsert node as a child of the current node, before refNode in the list of child nodes. Raises ValueError if refNode is not a child of the current nodeN(R(RRtrefNode((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyRAscC`s tdS(u:Remove node from the children of the current node N(R(RR((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyt removeChildGscC`s.x|jD]}|j|q Wg|_dS(uMove all the children of the current node to newParent. This is needed so that trees that don't store text as nodes move the text in the correct way N(R R(Rt newParenttchild((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pytreparentChildrenLscC`s tdS(uReturn a shallow copy of the current node i.e. a node with the same name and attributes but with no parent or child nodes N(R(R((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyt cloneNodeVscC`s tdS(uFReturn true if the node has children or text, false otherwise N(R(R((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyt hasContent\sN( t__name__t __module__RRRRR RRRR R!R"(((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyRs       tActiveFormattingElementscB`seZdZdZRS(cC`sd}|tkrxj|dddD]R}|tkr<Pn|j||r[|d7}n|dkr&|j|Pq&q&Wntj||dS(Niiii(tMarkert nodesEqualtremovetlisttappend(RRt equalCounttelement((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyR*cs      cC`s0|j|jkstS|j|jks,tStS(N(t nameTupletFalseR tTrue(Rtnode1tnode2((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyR'ps (R#R$R*R'(((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyR%bs t TreeBuildercB`seZdZdZdZdZdZdZdZ dZ ddZ dZ dZ dZdZdZdd Zd Zd Zd ZeeeZd ZdZddZdZddZdZdZdZRS(uBase treebuilder implementation documentClass - the class to use for the bottommost node of a document elementClass - the class to use for HTML Elements commentClass - the class to use for comments doctypeClass - the class to use for doctypes cC`s)|rd|_n d|_|jdS(Nuhttp://www.w3.org/1999/xhtml(tdefaultNamespaceR treset(RtnamespaceHTMLElements((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyRs  cC`sCg|_t|_d|_d|_t|_|j|_ dS(N( t openElementsR%tactiveFormattingElementsR t headPointert formPointerR.tinsertFromTablet documentClasstdocument(R((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyR4s      cC`st|d}|s:t|tr:td|f}q:nt|\}}x^t|jD]M}|rv||krvtS| r|j|krtS||j|kArZt SqZWdS(Nu nameTupleuhtml( thasattrt isinstanceRRtlistElementsMaptreversedR6R/R-R.(Rttargettvariantt exactNodet listElementstinvertR((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pytelementInScopescC`s'|js dSt|jd}|j|}|tksH||jkrLdSxL|tkr||jkr|dkrd}Pn|d8}|j|}qOWxtr"|d7}|j|}|j}|jidd6|jd6|jd6|j d6}||j|<||jdkrPqqWdS( NiiiuStartTagutypeunameu namespaceudata( R7tlenR&R6R/R!t insertElementRt namespaceR (RtitentrytcloneR,((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyt#reconstructActiveFormattingElementss.           cC`s>|jj}x(|jr9|tkr9|jj}qWdS(N(R7tpopR&(RRK((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pytclearActiveFormattingElementsscC`sHxA|jdddD])}|tkr-Pq|j|kr|SqWtS(uCheck if an element exists between the end of the active formatting elements and the last marker. If it does, return it, else return falseNi(R7R&RR.(RRtitem((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyt!elementInActiveFormattingElementss  cC`s3|j|}|jj||jj|dS(N(t createElementR6R*R<R(RttokenR,((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyt insertRootscC`sG|d}|d}|d}|j|||}|jj|dS(NunameupublicIdusystemId(t doctypeClassR<R(RRSRtpublicIdtsystemIdtdoctype((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyt insertDoctypes    cC`s:|dkr|jd}n|j|j|ddS(Niudata(R R6Rt commentClass(RRSR ((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyt insertComment s cC`sB|d}|jd|j}|j||}|d|_|S(u.Create an element but don't insert it anywhereunameu namespaceudata(tgetR3t elementClassR (RRSRRIR,((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyRRs   cC`s|jS(N(t_insertFromTable(R((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyt_getInsertFromTablescC`s.||_|r|j|_n |j|_dS(usSwitch the function used to insert an element from the normal one to the misnested table one and back againN(R^tinsertElementTableRHtinsertElementNormal(RR ((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyt_setInsertFromTables cC`sf|d}|jd|j}|j||}|d|_|jdj||jj||S(Nunameu namespaceudatai(R\R3R]R R6RR*(RRSRRIR,((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyRa$s  cC`s|j|}|jdjtkr2|j|S|j\}}|dkr`|j|n|j|||jj ||S(u-Create an element and insert it into the treeiN( RRR6RRRatgetTableMisnestedNodePositionR RRR*(RRSR,R R((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyR`.s  cC`s{|dkr|jd}n|j sE|jrU|jdjtkrU|j|n"|j\}}|j||dS(uInsert text data.iN(R R6R:RRRRc(RRR R((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyR>s   cC`sd}d}d}x7|jdddD]}|jdkr)|}Pq)q)W|r|jrm|j}|}q|j|jj|d}n |jd}||fS(usGet the foster parent element, and sibling to insert before (or None) when inserting a misnested table nodeNiutableii(R R6RR tindex(Rt lastTablet fosterParentRtelm((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyRcMs    c C`sO|jdj}|td krK||krK|jj|j|ndS( Niuddudtuliuoptionuoptgroupupurpurt(uddudtuliuoptionuoptgroupupurpurt(R6Rt frozensetRNtgenerateImpliedEndTags(RtexcludeR((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyRigs   cC`s|jS(uReturn the final tree(R<(R((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyt getDocumentqscC`s$|j}|jdj||S(uReturn the final fragmenti(t fragmentClassR6R (Rtfragment((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyt getFragmentus cC`s tdS(uzSerialize the subtree of node in the format required by unit tests node - the node from which to start serializingN(R(RR((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyttestSerializer|sN(R#R$t__doc__R R;R]RZRURlRR4RFRMRORQRTRYR[RRR_RbtpropertyR:RaR`RRcRiRkRnRo(((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyR2zs6   .             N(t __future__RRRtpip._vendor.sixRt constantsRRRR R&RhR.tsetR/R?tobjectRR)R%R2(((sJ/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/base.pyts*! Kdom.py000064400000021203147205641420005700 0ustar00from __future__ import absolute_import, division, unicode_literals from collections import MutableMapping from xml.dom import minidom, Node import weakref from . import base from .. import constants from ..constants import namespaces from .._utils import moduleFactoryFactory def getDomBuilder(DomImplementation): Dom = DomImplementation class AttrList(MutableMapping): def __init__(self, element): self.element = element def __iter__(self): return iter(self.element.attributes.keys()) def __setitem__(self, name, value): if isinstance(name, tuple): raise NotImplementedError else: attr = self.element.ownerDocument.createAttribute(name) attr.value = value self.element.attributes[name] = attr def __len__(self): return len(self.element.attributes) def items(self): return list(self.element.attributes.items()) def values(self): return list(self.element.attributes.values()) def __getitem__(self, name): if isinstance(name, tuple): raise NotImplementedError else: return self.element.attributes[name].value def __delitem__(self, name): if isinstance(name, tuple): raise NotImplementedError else: del self.element.attributes[name] class NodeBuilder(base.Node): def __init__(self, element): base.Node.__init__(self, element.nodeName) self.element = element namespace = property(lambda self: hasattr(self.element, "namespaceURI") and self.element.namespaceURI or None) def appendChild(self, node): node.parent = self self.element.appendChild(node.element) def insertText(self, data, insertBefore=None): text = self.element.ownerDocument.createTextNode(data) if insertBefore: self.element.insertBefore(text, insertBefore.element) else: self.element.appendChild(text) def insertBefore(self, node, refNode): self.element.insertBefore(node.element, refNode.element) node.parent = self def removeChild(self, node): if node.element.parentNode == self.element: self.element.removeChild(node.element) node.parent = None def reparentChildren(self, newParent): while self.element.hasChildNodes(): child = self.element.firstChild self.element.removeChild(child) newParent.element.appendChild(child) self.childNodes = [] def getAttributes(self): return AttrList(self.element) def setAttributes(self, attributes): if attributes: for name, value in list(attributes.items()): if isinstance(name, tuple): if name[0] is not None: qualifiedName = (name[0] + ":" + name[1]) else: qualifiedName = name[1] self.element.setAttributeNS(name[2], qualifiedName, value) else: self.element.setAttribute( name, value) attributes = property(getAttributes, setAttributes) def cloneNode(self): return NodeBuilder(self.element.cloneNode(False)) def hasContent(self): return self.element.hasChildNodes() def getNameTuple(self): if self.namespace is None: return namespaces["html"], self.name else: return self.namespace, self.name nameTuple = property(getNameTuple) class TreeBuilder(base.TreeBuilder): # pylint:disable=unused-variable def documentClass(self): self.dom = Dom.getDOMImplementation().createDocument(None, None, None) return weakref.proxy(self) def insertDoctype(self, token): name = token["name"] publicId = token["publicId"] systemId = token["systemId"] domimpl = Dom.getDOMImplementation() doctype = domimpl.createDocumentType(name, publicId, systemId) self.document.appendChild(NodeBuilder(doctype)) if Dom == minidom: doctype.ownerDocument = self.dom def elementClass(self, name, namespace=None): if namespace is None and self.defaultNamespace is None: node = self.dom.createElement(name) else: node = self.dom.createElementNS(namespace, name) return NodeBuilder(node) def commentClass(self, data): return NodeBuilder(self.dom.createComment(data)) def fragmentClass(self): return NodeBuilder(self.dom.createDocumentFragment()) def appendChild(self, node): self.dom.appendChild(node.element) def testSerializer(self, element): return testSerializer(element) def getDocument(self): return self.dom def getFragment(self): return base.TreeBuilder.getFragment(self).element def insertText(self, data, parent=None): data = data if parent != self: base.TreeBuilder.insertText(self, data, parent) else: # HACK: allow text nodes as children of the document node if hasattr(self.dom, '_child_node_types'): # pylint:disable=protected-access if Node.TEXT_NODE not in self.dom._child_node_types: self.dom._child_node_types = list(self.dom._child_node_types) self.dom._child_node_types.append(Node.TEXT_NODE) self.dom.appendChild(self.dom.createTextNode(data)) implementation = DomImplementation name = None def testSerializer(element): element.normalize() rv = [] def serializeElement(element, indent=0): if element.nodeType == Node.DOCUMENT_TYPE_NODE: if element.name: if element.publicId or element.systemId: publicId = element.publicId or "" systemId = element.systemId or "" rv.append("""|%s""" % (' ' * indent, element.name, publicId, systemId)) else: rv.append("|%s" % (' ' * indent, element.name)) else: rv.append("|%s" % (' ' * indent,)) elif element.nodeType == Node.DOCUMENT_NODE: rv.append("#document") elif element.nodeType == Node.DOCUMENT_FRAGMENT_NODE: rv.append("#document-fragment") elif element.nodeType == Node.COMMENT_NODE: rv.append("|%s" % (' ' * indent, element.nodeValue)) elif element.nodeType == Node.TEXT_NODE: rv.append("|%s\"%s\"" % (' ' * indent, element.nodeValue)) else: if (hasattr(element, "namespaceURI") and element.namespaceURI is not None): name = "%s %s" % (constants.prefixes[element.namespaceURI], element.nodeName) else: name = element.nodeName rv.append("|%s<%s>" % (' ' * indent, name)) if element.hasAttributes(): attributes = [] for i in range(len(element.attributes)): attr = element.attributes.item(i) name = attr.nodeName value = attr.value ns = attr.namespaceURI if ns: name = "%s %s" % (constants.prefixes[ns], attr.localName) else: name = attr.nodeName attributes.append((name, value)) for name, value in sorted(attributes): rv.append('|%s%s="%s"' % (' ' * (indent + 2), name, value)) indent += 2 for child in element.childNodes: serializeElement(child, indent) serializeElement(element, 0) return "\n".join(rv) return locals() # The actual means to get a module! getDomModule = moduleFactoryFactory(getDomBuilder) dom.pyc000064400000026615147205641420006057 0ustar00 abc@`sddlmZmZmZddlmZddlmZmZddl Z ddl m Z ddl m Z dd l m Z dd lmZd ZeeZdS( i(tabsolute_importtdivisiontunicode_literals(tMutableMapping(tminidomtNodeNi(tbasei(t constants(t namespaces(tmoduleFactoryFactoryc`svdtfdYdtjffdYdtjffdY}dtS(NtAttrListcB`sPeZdZdZdZdZdZdZdZdZ RS(cS`s ||_dS(N(telement(tselfR ((sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyt__init__scS`st|jjjS(N(titerR t attributestkeys(R ((sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyt__iter__scS`sJt|trtn.|jjj|}||_||jj|:scS`s ||_|jj|jdS(N(tparentR t appendChild(R tnode((sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyR+=s cS`sH|jjj|}|r4|jj||jn|jj|dS(N(R RtcreateTextNodet insertBeforeR+(R tdataR.ttext((sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyt insertTextAscS`s&|jj|j|j||_dS(N(R R.R*(R R,trefNode((sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyR.HscS`s8|jj|jkr+|jj|jnd|_dS(N(R t parentNodet removeChildR(R*(R R,((sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyR4LscS`sOx?|jjrA|jj}|jj||jj|qWg|_dS(N(R t hasChildNodest firstChildR4R+t childNodes(R t newParenttchild((sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pytreparentChildrenQs  c`s |jS(N(R (R (R (sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyt getAttributesXscS`s|rxt|jD]~\}}t|tr|ddk r]|dd|d}n |d}|jj|d||q|jj||qWndS(Niu:ii(RRRRR(R tsetAttributeNSt setAttribute(R RRRt qualifiedName((sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyt setAttributes[s   c`s|jjtS(N(R t cloneNodetFalse(R (R$(sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyR@jscS`s |jjS(N(R R5(R ((sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyt hasContentmscS`s4|jdkr td|jfS|j|jfSdS(Nuhtml(t namespaceR(RR(R ((sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyt getNameTuplepsN(R"R#R tpropertyRCR+R(R1R.R4R:R;R?RR@RBRDt nameTuple((R R$(sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyR$5s         t TreeBuilderc`seZfdZfdZd fdZfdZfdZdZfdZ dZ dZ d d Z Z d ZRS( c`s+jjddd|_tj|S(N(tgetDOMImplementationtcreateDocumentR(tdomtweakreftproxy(R (tDom(sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyt documentClassysc`st|d}|d}|d}j}|j|||}|jj|tkrp|j|_ndS(NunameupublicIdusystemId(RHtcreateDocumentTypetdocumentR+RRJR(R ttokenRtpublicIdtsystemIdtdomimpltdoctype(RMR$(sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyt insertDoctype}s     c`sO|dkr0|jdkr0|jj|}n|jj||}|S(N(R(tdefaultNamespaceRJt createElementtcreateElementNS(R RRCR,(R$(sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyt elementClasssc`s|jj|S(N(RJt createComment(R R/(R$(sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyt commentClasssc`s|jjS(N(RJtcreateDocumentFragment(R (R$(sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyt fragmentClassscS`s|jj|jdS(N(RJR+R (R R,((sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyR+sc`s |S(N((R R (ttestSerializer(sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyR_scS`s|jS(N(RJ(R ((sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyt getDocumentscS`stjj|jS(N(RRGt getFragmentR (R ((sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyRascS`s|}||kr+tjj|||nwt|jdrtj|jjkrt|jj|j_|jjj tjqn|jj |jj |dS(Nu_child_node_types( RRGR1R&RJRt TEXT_NODEt_child_node_typesRtappendR+R-(R R/R*((sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyR1s N(R"R#RNRVR(RZR\R^R+R_R`RaR1timplementationR((RMtDomImplementationR$R_(sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyRGxs     c`s?|jgdfd|ddjS(Nic `s|jtjkr|jr|js-|jrr|jp9d}|jpHd}jdd||j||fqjdd||jfqjdd|fn|jtjkrjdn|jtjkrjdn|jtj kr%jdd||j fnu|jtj krXjd d||j fnBt |d r|j dk rd tj|j |jf}n |j}jd d||f|jrg}xtt|jD]r}|jj|}|j}|j}|j } | r8d tj| |jf}n |j}|j||fqWx?t|D].\}}jd d|d||fqeWn|d7}x|jD]} | |qWdS(Nuu|%su u|%su|%su #documentu#document-fragmentu|%su|%s"%s"u namespaceURIu%s %su|%s<%s>u |%s%s="%s"i(tnodeTypeRtDOCUMENT_TYPE_NODERRRRSRdt DOCUMENT_NODEtDOCUMENT_FRAGMENT_NODEt COMMENT_NODEt nodeValueRbR&R'R(RtprefixesR%t hasAttributestrangeRRtitemRt localNametsortedR7( R tindentRRRSRRtiRRtnsR9(trvtserializeElement(sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyRwsN  !!!      ) u (t normalizetjoin(R ((RvRwsI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyR_s  . (RRRRGtlocals(RfRG((R RMRfR$R_sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyt getDomBuilders $"C(: 6(t __future__RRRt collectionsRtxml.domRRRKtRRRt_utilsR R{t getDomModule(((sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyts  dom.pyo000064400000026615147205641420006073 0ustar00 abc@`sddlmZmZmZddlmZddlmZmZddl Z ddl m Z ddl m Z dd l m Z dd lmZd ZeeZdS( i(tabsolute_importtdivisiontunicode_literals(tMutableMapping(tminidomtNodeNi(tbasei(t constants(t namespaces(tmoduleFactoryFactoryc`svdtfdYdtjffdYdtjffdY}dtS(NtAttrListcB`sPeZdZdZdZdZdZdZdZdZ RS(cS`s ||_dS(N(telement(tselfR ((sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyt__init__scS`st|jjjS(N(titerR t attributestkeys(R ((sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyt__iter__scS`sJt|trtn.|jjj|}||_||jj|:scS`s ||_|jj|jdS(N(tparentR t appendChild(R tnode((sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyR+=s cS`sH|jjj|}|r4|jj||jn|jj|dS(N(R RtcreateTextNodet insertBeforeR+(R tdataR.ttext((sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyt insertTextAscS`s&|jj|j|j||_dS(N(R R.R*(R R,trefNode((sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyR.HscS`s8|jj|jkr+|jj|jnd|_dS(N(R t parentNodet removeChildR(R*(R R,((sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyR4LscS`sOx?|jjrA|jj}|jj||jj|qWg|_dS(N(R t hasChildNodest firstChildR4R+t childNodes(R t newParenttchild((sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pytreparentChildrenQs  c`s |jS(N(R (R (R (sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyt getAttributesXscS`s|rxt|jD]~\}}t|tr|ddk r]|dd|d}n |d}|jj|d||q|jj||qWndS(Niu:ii(RRRRR(R tsetAttributeNSt setAttribute(R RRRt qualifiedName((sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyt setAttributes[s   c`s|jjtS(N(R t cloneNodetFalse(R (R$(sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyR@jscS`s |jjS(N(R R5(R ((sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyt hasContentmscS`s4|jdkr td|jfS|j|jfSdS(Nuhtml(t namespaceR(RR(R ((sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyt getNameTuplepsN(R"R#R tpropertyRCR+R(R1R.R4R:R;R?RR@RBRDt nameTuple((R R$(sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyR$5s         t TreeBuilderc`seZfdZfdZd fdZfdZfdZdZfdZ dZ dZ d d Z Z d ZRS( c`s+jjddd|_tj|S(N(tgetDOMImplementationtcreateDocumentR(tdomtweakreftproxy(R (tDom(sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyt documentClassysc`st|d}|d}|d}j}|j|||}|jj|tkrp|j|_ndS(NunameupublicIdusystemId(RHtcreateDocumentTypetdocumentR+RRJR(R ttokenRtpublicIdtsystemIdtdomimpltdoctype(RMR$(sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyt insertDoctype}s     c`sO|dkr0|jdkr0|jj|}n|jj||}|S(N(R(tdefaultNamespaceRJt createElementtcreateElementNS(R RRCR,(R$(sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyt elementClasssc`s|jj|S(N(RJt createComment(R R/(R$(sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyt commentClasssc`s|jjS(N(RJtcreateDocumentFragment(R (R$(sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyt fragmentClassscS`s|jj|jdS(N(RJR+R (R R,((sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyR+sc`s |S(N((R R (ttestSerializer(sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyR_scS`s|jS(N(RJ(R ((sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyt getDocumentscS`stjj|jS(N(RRGt getFragmentR (R ((sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyRascS`s|}||kr+tjj|||nwt|jdrtj|jjkrt|jj|j_|jjj tjqn|jj |jj |dS(Nu_child_node_types( RRGR1R&RJRt TEXT_NODEt_child_node_typesRtappendR+R-(R R/R*((sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyR1s N(R"R#RNRVR(RZR\R^R+R_R`RaR1timplementationR((RMtDomImplementationR$R_(sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyRGxs     c`s?|jgdfd|ddjS(Nic `s|jtjkr|jr|js-|jrr|jp9d}|jpHd}jdd||j||fqjdd||jfqjdd|fn|jtjkrjdn|jtjkrjdn|jtj kr%jdd||j fnu|jtj krXjd d||j fnBt |d r|j dk rd tj|j |jf}n |j}jd d||f|jrg}xtt|jD]r}|jj|}|j}|j}|j } | r8d tj| |jf}n |j}|j||fqWx?t|D].\}}jd d|d||fqeWn|d7}x|jD]} | |qWdS(Nuu|%su u|%su|%su #documentu#document-fragmentu|%su|%s"%s"u namespaceURIu%s %su|%s<%s>u |%s%s="%s"i(tnodeTypeRtDOCUMENT_TYPE_NODERRRRSRdt DOCUMENT_NODEtDOCUMENT_FRAGMENT_NODEt COMMENT_NODEt nodeValueRbR&R'R(RtprefixesR%t hasAttributestrangeRRtitemRt localNametsortedR7( R tindentRRRSRRtiRRtnsR9(trvtserializeElement(sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyRwsN  !!!      ) u (t normalizetjoin(R ((RvRwsI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyR_s  . (RRRRGtlocals(RfRG((R RMRfR$R_sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyt getDomBuilders $"C(: 6(t __future__RRRt collectionsRtxml.domRRRKtRRRt_utilsR R{t getDomModule(((sI/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/dom.pyts  etree.py000064400000030734147205641420006236 0ustar00from __future__ import absolute_import, division, unicode_literals # pylint:disable=protected-access from pip._vendor.six import text_type import re from . import base from .. import _ihatexml from .. import constants from ..constants import namespaces from .._utils import moduleFactoryFactory tag_regexp = re.compile("{([^}]*)}(.*)") def getETreeBuilder(ElementTreeImplementation, fullTree=False): ElementTree = ElementTreeImplementation ElementTreeCommentType = ElementTree.Comment("asd").tag class Element(base.Node): def __init__(self, name, namespace=None): self._name = name self._namespace = namespace self._element = ElementTree.Element(self._getETreeTag(name, namespace)) if namespace is None: self.nameTuple = namespaces["html"], self._name else: self.nameTuple = self._namespace, self._name self.parent = None self._childNodes = [] self._flags = [] def _getETreeTag(self, name, namespace): if namespace is None: etree_tag = name else: etree_tag = "{%s}%s" % (namespace, name) return etree_tag def _setName(self, name): self._name = name self._element.tag = self._getETreeTag(self._name, self._namespace) def _getName(self): return self._name name = property(_getName, _setName) def _setNamespace(self, namespace): self._namespace = namespace self._element.tag = self._getETreeTag(self._name, self._namespace) def _getNamespace(self): return self._namespace namespace = property(_getNamespace, _setNamespace) def _getAttributes(self): return self._element.attrib def _setAttributes(self, attributes): # Delete existing attributes first # XXX - there may be a better way to do this... for key in list(self._element.attrib.keys()): del self._element.attrib[key] for key, value in attributes.items(): if isinstance(key, tuple): name = "{%s}%s" % (key[2], key[1]) else: name = key self._element.set(name, value) attributes = property(_getAttributes, _setAttributes) def _getChildNodes(self): return self._childNodes def _setChildNodes(self, value): del self._element[:] self._childNodes = [] for element in value: self.insertChild(element) childNodes = property(_getChildNodes, _setChildNodes) def hasContent(self): """Return true if the node has children or text""" return bool(self._element.text or len(self._element)) def appendChild(self, node): self._childNodes.append(node) self._element.append(node._element) node.parent = self def insertBefore(self, node, refNode): index = list(self._element).index(refNode._element) self._element.insert(index, node._element) node.parent = self def removeChild(self, node): self._childNodes.remove(node) self._element.remove(node._element) node.parent = None def insertText(self, data, insertBefore=None): if not(len(self._element)): if not self._element.text: self._element.text = "" self._element.text += data elif insertBefore is None: # Insert the text as the tail of the last child element if not self._element[-1].tail: self._element[-1].tail = "" self._element[-1].tail += data else: # Insert the text before the specified node children = list(self._element) index = children.index(insertBefore._element) if index > 0: if not self._element[index - 1].tail: self._element[index - 1].tail = "" self._element[index - 1].tail += data else: if not self._element.text: self._element.text = "" self._element.text += data def cloneNode(self): element = type(self)(self.name, self.namespace) for name, value in self.attributes.items(): element.attributes[name] = value return element def reparentChildren(self, newParent): if newParent.childNodes: newParent.childNodes[-1]._element.tail += self._element.text else: if not newParent._element.text: newParent._element.text = "" if self._element.text is not None: newParent._element.text += self._element.text self._element.text = "" base.Node.reparentChildren(self, newParent) class Comment(Element): def __init__(self, data): # Use the superclass constructor to set all properties on the # wrapper element self._element = ElementTree.Comment(data) self.parent = None self._childNodes = [] self._flags = [] def _getData(self): return self._element.text def _setData(self, value): self._element.text = value data = property(_getData, _setData) class DocumentType(Element): def __init__(self, name, publicId, systemId): Element.__init__(self, "") self._element.text = name self.publicId = publicId self.systemId = systemId def _getPublicId(self): return self._element.get("publicId", "") def _setPublicId(self, value): if value is not None: self._element.set("publicId", value) publicId = property(_getPublicId, _setPublicId) def _getSystemId(self): return self._element.get("systemId", "") def _setSystemId(self, value): if value is not None: self._element.set("systemId", value) systemId = property(_getSystemId, _setSystemId) class Document(Element): def __init__(self): Element.__init__(self, "DOCUMENT_ROOT") class DocumentFragment(Element): def __init__(self): Element.__init__(self, "DOCUMENT_FRAGMENT") def testSerializer(element): rv = [] def serializeElement(element, indent=0): if not(hasattr(element, "tag")): element = element.getroot() if element.tag == "": if element.get("publicId") or element.get("systemId"): publicId = element.get("publicId") or "" systemId = element.get("systemId") or "" rv.append("""""" % (element.text, publicId, systemId)) else: rv.append("" % (element.text,)) elif element.tag == "DOCUMENT_ROOT": rv.append("#document") if element.text is not None: rv.append("|%s\"%s\"" % (' ' * (indent + 2), element.text)) if element.tail is not None: raise TypeError("Document node cannot have tail") if hasattr(element, "attrib") and len(element.attrib): raise TypeError("Document node cannot have attributes") elif element.tag == ElementTreeCommentType: rv.append("|%s" % (' ' * indent, element.text)) else: assert isinstance(element.tag, text_type), \ "Expected unicode, got %s, %s" % (type(element.tag), element.tag) nsmatch = tag_regexp.match(element.tag) if nsmatch is None: name = element.tag else: ns, name = nsmatch.groups() prefix = constants.prefixes[ns] name = "%s %s" % (prefix, name) rv.append("|%s<%s>" % (' ' * indent, name)) if hasattr(element, "attrib"): attributes = [] for name, value in element.attrib.items(): nsmatch = tag_regexp.match(name) if nsmatch is not None: ns, name = nsmatch.groups() prefix = constants.prefixes[ns] attr_string = "%s %s" % (prefix, name) else: attr_string = name attributes.append((attr_string, value)) for name, value in sorted(attributes): rv.append('|%s%s="%s"' % (' ' * (indent + 2), name, value)) if element.text: rv.append("|%s\"%s\"" % (' ' * (indent + 2), element.text)) indent += 2 for child in element: serializeElement(child, indent) if element.tail: rv.append("|%s\"%s\"" % (' ' * (indent - 2), element.tail)) serializeElement(element, 0) return "\n".join(rv) def tostring(element): # pylint:disable=unused-variable """Serialize an element and its child nodes to a string""" rv = [] filter = _ihatexml.InfosetFilter() def serializeElement(element): if isinstance(element, ElementTree.ElementTree): element = element.getroot() if element.tag == "": if element.get("publicId") or element.get("systemId"): publicId = element.get("publicId") or "" systemId = element.get("systemId") or "" rv.append("""""" % (element.text, publicId, systemId)) else: rv.append("" % (element.text,)) elif element.tag == "DOCUMENT_ROOT": if element.text is not None: rv.append(element.text) if element.tail is not None: raise TypeError("Document node cannot have tail") if hasattr(element, "attrib") and len(element.attrib): raise TypeError("Document node cannot have attributes") for child in element: serializeElement(child) elif element.tag == ElementTreeCommentType: rv.append("" % (element.text,)) else: # This is assumed to be an ordinary element if not element.attrib: rv.append("<%s>" % (filter.fromXmlName(element.tag),)) else: attr = " ".join(["%s=\"%s\"" % ( filter.fromXmlName(name), value) for name, value in element.attrib.items()]) rv.append("<%s %s>" % (element.tag, attr)) if element.text: rv.append(element.text) for child in element: serializeElement(child) rv.append("" % (element.tag,)) if element.tail: rv.append(element.tail) serializeElement(element) return "".join(rv) class TreeBuilder(base.TreeBuilder): # pylint:disable=unused-variable documentClass = Document doctypeClass = DocumentType elementClass = Element commentClass = Comment fragmentClass = DocumentFragment implementation = ElementTreeImplementation def testSerializer(self, element): return testSerializer(element) def getDocument(self): if fullTree: return self.document._element else: if self.defaultNamespace is not None: return self.document._element.find( "{%s}html" % self.defaultNamespace) else: return self.document._element.find("html") def getFragment(self): return base.TreeBuilder.getFragment(self)._element return locals() getETreeModule = moduleFactoryFactory(getETreeBuilder) etree.pyc000064400000034705147205641420006403 0ustar00 abc@`sddlmZmZmZddlmZddlZddlmZddlm Z ddlm Z dd l m Z dd l m Z ejd Zed Ze eZdS( i(tabsolute_importtdivisiontunicode_literals(t text_typeNi(tbasei(t _ihatexml(t constants(t namespaces(tmoduleFactoryFactoryu {([^}]*)}(.*)c `sjdjdtjffdYdffdYdffdYdffd Yd ffd Yfd fd }dtjf fdY}tS(NuasdtElementc`seZdfdZdZdZdZeeeZdZ dZ ee e Z dZ dZ ee e ZdZd ZeeeZd Zd Zd Zd ZddZdZdZRS(c`s||_||_j|j|||_|dkrUtd|jf|_n|j|jf|_d|_g|_ g|_ dS(Nuhtml( t_namet _namespaceR t _getETreeTagt_elementtNoneRt nameTupletparentt _childNodest_flags(tselftnamet namespace(t ElementTree(sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt__init__s     cS`s)|dkr|}nd||f}|S(Nu{%s}%s(R(RRRt etree_tag((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyR #s  cS`s+||_|j|j|j|j_dS(N(R R R R ttag(RR((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt_setName*s cS`s|jS(N(R (R((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt_getName.scS`s+||_|j|j|j|j_dS(N(R R R R R(RR((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt _setNamespace3s cS`s|jS(N(R (R((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt _getNamespace7scS`s |jjS(N(R tattrib(R((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt_getAttributes<scS`sx-t|jjjD]}|jj|=qWx]|jD]O\}}t|trsd|d|df}n|}|jj||q=WdS(Nu{%s}%sii(tlistR Rtkeystitemst isinstancettupletset(Rt attributestkeytvalueR((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt_setAttributes?scS`s|jS(N(R(R((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt_getChildNodesMscS`s2|j2g|_x|D]}|j|qWdS(N(R Rt insertChild(RR(telement((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt_setChildNodesPs  cS`st|jjpt|jS(u,Return true if the node has children or text(tboolR ttexttlen(R((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt hasContentXscS`s0|jj||jj|j||_dS(N(RtappendR R(Rtnode((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt appendChild\scS`s>t|jj|j}|jj||j||_dS(N(R R tindextinsertR(RR3trefNodeR5((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt insertBeforeascS`s0|jj||jj|jd|_dS(N(RtremoveR RR(RR3((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt removeChildfscS`s-t|js?|jjs*d|j_n|jj|7_n|dkr|jdjsnd|jd_n|jdj|7_nt|j}|j|j}|dkr|j|djsd|j|d_n|j|dj|7_n-|jjsd|j_n|jj|7_dS(Nuiii(R0R R/RttailR R5(RtdataR8tchildrenR5((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt insertTextks"    cS`sLt||j|j}x*|jjD]\}}||j|R@RC((R(sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyR s*               tCommentc`s8eZfdZdZdZeeeZRS(c`s1j||_d|_g|_g|_dS(N(RHR RRRR(RR<(R(sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyRs  cS`s |jjS(N(R R/(R((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt_getDatascS`s||j_dS(N(R R/(RR(((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt_setDatas(RERFRRIRJRGR<((R(sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyRHs  t DocumentTypec`sYeZfdZdZdZeeeZdZdZeeeZ RS(c`s2j|d||j_||_||_dS(Nu (RR R/tpublicIdtsystemId(RRRLRM(R (sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyRs  cS`s|jjddS(NupublicIdu(R tget(R((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt _getPublicIdscS`s&|dk r"|jjd|ndS(NupublicId(RR R%(RR(((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt _setPublicIds cS`s|jjddS(NusystemIdu(R RN(R((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt _getSystemIdscS`s&|dk r"|jjd|ndS(NusystemId(RR R%(RR(((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt _setSystemIds ( RERFRRORPRGRLRQRRRM((R (sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyRKs    tDocumentc`seZfdZRS(c`sj|ddS(Nu DOCUMENT_ROOT(R(R(R (sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyRs(RERFR((R (sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyRSstDocumentFragmentc`seZfdZRS(c`sj|ddS(NuDOCUMENT_FRAGMENT(R(R(R (sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyRs(RERFR((R (sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyRTsc`s8gdfd|ddjS(Nic `st|ds|j}n|jdkr|jdsK|jdr|jdp]d}|jdprd}jd|j||fq0jd|jfn|jdkrMjd |jdk rjd d |d |jfn|jdk rtd nt|dr0t |j r0tdq0n|jkr}jdd ||jfnt |jt st dt|j|jftj|j}|dkr|j}n/|j\}}tj|}d||f}jdd ||ft|drg}x|j jD]r\}} tj|}|dk r|j\}}tj|}d||f} n|} |j| | fqJWx?t|D].\}} jdd |d || fqWn|jr0jd d |d |jfn|d 7}x|D]} | |qAW|jrjd d |d |jfndS(Nutagu upublicIdusystemIduuu u DOCUMENT_ROOTu #documentu|%s"%s"u iuDocument node cannot have tailuattribu$Document node cannot have attributesu|%suExpected unicode, got %s, %su%s %su|%s<%s>u |%s%s="%s"(thasattrtgetrootRRNR2R/RR;t TypeErrorR0RR#RtAssertionErrorR?t tag_regexptmatchtgroupsRtprefixesR"tsorted( R,tindentRLRMtnsmatchRtnstprefixR&R(t attr_stringtchild(tElementTreeCommentTypetrvtserializeElement(sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyRfs^  %!     ) %   u (tjoin(R,(Rd(ReRfsK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyttestSerializers7 c`sDgtjfd|djS(u4Serialize an element and its child nodes to a stringc`smt|jr!|j}n|jdkr|jdsN|jdr|jdp`d}|jdpud}jd|j||fqMjd|jfn|jdkrL|jdk rj|jn|jdk rt dnt |d r.t |j r.t d nx|D]}|q5Wn|jkrujd |jfn|j sjd j |jfn^d jg|j jD]%\}}dj ||f^q}jd|j|f|jrj|jnx|D]}|q"Wjd|jf|jrij|jndS(Nu upublicIdusystemIduuu u DOCUMENT_ROOTuDocument node cannot have tailuattribu$Document node cannot have attributesu u<%s>u u%s="%s"u<%s %s>u(R#RRVRRNR2R/RR;RWRUR0Rt fromXmlNameRgR"(R,RLRMRcRR(tattr(RRdtfilterReRf(sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyRfs@   # ;   u(Rt InfosetFilterRg(R,(RRd(RkReRfsK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyttostrings  - t TreeBuilderc`sSeZZZZZZZfdZfdZ dZ RS(c`s |S(N((RR,(Rh(sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyRhAsc`sPr|jjS|jdk r9|jjjd|jS|jjjdSdS(Nu{%s}htmluhtml(tdocumentR tdefaultNamespaceRtfind(R(tfullTree(sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt getDocumentDs   cS`stjj|jS(N(RRnt getFragmentR (R((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyRtNs( RERFt documentClasst doctypeClasst elementClasst commentClasst fragmentClasstimplementationRhRsRt((RHRSRTRKR tElementTreeImplementationRrRh(sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyRn9s (RHRRRBRntlocals(R{RrRmRn(( RHRSRTRKR RRdR{RrRhsK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pytgetETreeBuilders~>64(t __future__RRRtpip._vendor.sixRtretRRRRt_utilsRtcompileRYtFalseR}tgetETreeModule(((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyts  Detree.pyo000064400000034512147205641420006413 0ustar00 abc@`sddlmZmZmZddlmZddlZddlmZddlm Z ddlm Z dd l m Z dd l m Z ejd Zed Ze eZdS( i(tabsolute_importtdivisiontunicode_literals(t text_typeNi(tbasei(t _ihatexml(t constants(t namespaces(tmoduleFactoryFactoryu {([^}]*)}(.*)c `sjdjdtjffdYdffdYdffdYdffd Yd ffd Yfd fd }dtjf fdY}tS(NuasdtElementc`seZdfdZdZdZdZeeeZdZ dZ ee e Z dZ dZ ee e ZdZd ZeeeZd Zd Zd Zd ZddZdZdZRS(c`s||_||_j|j|||_|dkrUtd|jf|_n|j|jf|_d|_g|_ g|_ dS(Nuhtml( t_namet _namespaceR t _getETreeTagt_elementtNoneRt nameTupletparentt _childNodest_flags(tselftnamet namespace(t ElementTree(sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt__init__s     cS`s)|dkr|}nd||f}|S(Nu{%s}%s(R(RRRt etree_tag((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyR #s  cS`s+||_|j|j|j|j_dS(N(R R R R ttag(RR((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt_setName*s cS`s|jS(N(R (R((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt_getName.scS`s+||_|j|j|j|j_dS(N(R R R R R(RR((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt _setNamespace3s cS`s|jS(N(R (R((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt _getNamespace7scS`s |jjS(N(R tattrib(R((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt_getAttributes<scS`sx-t|jjjD]}|jj|=qWx]|jD]O\}}t|trsd|d|df}n|}|jj||q=WdS(Nu{%s}%sii(tlistR Rtkeystitemst isinstancettupletset(Rt attributestkeytvalueR((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt_setAttributes?scS`s|jS(N(R(R((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt_getChildNodesMscS`s2|j2g|_x|D]}|j|qWdS(N(R Rt insertChild(RR(telement((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt_setChildNodesPs  cS`st|jjpt|jS(u,Return true if the node has children or text(tboolR ttexttlen(R((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt hasContentXscS`s0|jj||jj|j||_dS(N(RtappendR R(Rtnode((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt appendChild\scS`s>t|jj|j}|jj||j||_dS(N(R R tindextinsertR(RR3trefNodeR5((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt insertBeforeascS`s0|jj||jj|jd|_dS(N(RtremoveR RR(RR3((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt removeChildfscS`s-t|js?|jjs*d|j_n|jj|7_n|dkr|jdjsnd|jd_n|jdj|7_nt|j}|j|j}|dkr|j|djsd|j|d_n|j|dj|7_n-|jjsd|j_n|jj|7_dS(Nuiii(R0R R/RttailR R5(RtdataR8tchildrenR5((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt insertTextks"    cS`sLt||j|j}x*|jjD]\}}||j|R@RC((R(sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyR s*               tCommentc`s8eZfdZdZdZeeeZRS(c`s1j||_d|_g|_g|_dS(N(RHR RRRR(RR<(R(sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyRs  cS`s |jjS(N(R R/(R((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt_getDatascS`s||j_dS(N(R R/(RR(((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt_setDatas(RERFRRIRJRGR<((R(sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyRHs  t DocumentTypec`sYeZfdZdZdZeeeZdZdZeeeZ RS(c`s2j|d||j_||_||_dS(Nu (RR R/tpublicIdtsystemId(RRRLRM(R (sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyRs  cS`s|jjddS(NupublicIdu(R tget(R((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt _getPublicIdscS`s&|dk r"|jjd|ndS(NupublicId(RR R%(RR(((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt _setPublicIds cS`s|jjddS(NusystemIdu(R RN(R((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt _getSystemIdscS`s&|dk r"|jjd|ndS(NusystemId(RR R%(RR(((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt _setSystemIds ( RERFRRORPRGRLRQRRRM((R (sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyRKs    tDocumentc`seZfdZRS(c`sj|ddS(Nu DOCUMENT_ROOT(R(R(R (sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyRs(RERFR((R (sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyRSstDocumentFragmentc`seZfdZRS(c`sj|ddS(NuDOCUMENT_FRAGMENT(R(R(R (sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyRs(RERFR((R (sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyRTsc`s8gdfd|ddjS(Nic `sVt|ds|j}n|jdkr|jdsK|jdr|jdp]d}|jdprd}jd|j||fqjd|jfnM|jdkrMjd |jdk rjd d |d |jfn|jdk rtd nt|drt |j rtdqn|jkr}jdd ||jfnt j |j}|dkr|j}n/|j \}}tj|}d||f}jdd ||ft|drg}x|j jD]r\}} t j |}|dk ro|j \}}tj|}d||f} n|} |j| | fqWx?t|D].\}} jdd |d || fqWn|jrjd d |d |jfn|d 7}x|D]} | |q W|jrRjd d |d |jfndS(Nutagu upublicIdusystemIduuu u DOCUMENT_ROOTu #documentu|%s"%s"u iuDocument node cannot have tailuattribu$Document node cannot have attributesu|%su%s %su|%s<%s>u |%s%s="%s"(thasattrtgetrootRRNR2R/RR;t TypeErrorR0Rt tag_regexptmatchtgroupsRtprefixesR"tsorted( R,tindentRLRMtnsmatchRtnstprefixR&R(t attr_stringtchild(tElementTreeCommentTypetrvtserializeElement(sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyResZ  %!     ) %   u (tjoin(R,(Rc(RdResK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyttestSerializers7 c`sDgtjfd|djS(u4Serialize an element and its child nodes to a stringc`smt|jr!|j}n|jdkr|jdsN|jdr|jdp`d}|jdpud}jd|j||fqMjd|jfn|jdkrL|jdk rj|jn|jdk rt dnt |d r.t |j r.t d nx|D]}|q5Wn|jkrujd |jfn|j sjd j |jfn^d jg|j jD]%\}}dj ||f^q}jd|j|f|jrj|jnx|D]}|q"Wjd|jf|jrij|jndS(Nu upublicIdusystemIduuu u DOCUMENT_ROOTuDocument node cannot have tailuattribu$Document node cannot have attributesu u<%s>u u%s="%s"u<%s %s>u(R#RRVRRNR2R/RR;RWRUR0Rt fromXmlNameRfR"(R,RLRMRbRR(tattr(RRctfilterRdRe(sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyRes@   # ;   u(Rt InfosetFilterRf(R,(RRc(RjRdResK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyttostrings  - t TreeBuilderc`sSeZZZZZZZfdZfdZ dZ RS(c`s |S(N((RR,(Rg(sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyRgAsc`sPr|jjS|jdk r9|jjjd|jS|jjjdSdS(Nu{%s}htmluhtml(tdocumentR tdefaultNamespaceRtfind(R(tfullTree(sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyt getDocumentDs   cS`stjj|jS(N(RRmt getFragmentR (R((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyRsNs( RERFt documentClasst doctypeClasst elementClasst commentClasst fragmentClasstimplementationRgRrRs((RHRSRTRKR tElementTreeImplementationRqRg(sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyRm9s (RHRRRBRmtlocals(RzRqRlRm(( RHRSRTRKR RRcRzRqRgsK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pytgetETreeBuilders~>64(t __future__RRRtpip._vendor.sixRtretRRRRt_utilsRtcompileRXtFalseR|tgetETreeModule(((sK/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree.pyts  Detree_lxml.py000064400000033521147205641420007267 0ustar00"""Module for supporting the lxml.etree library. The idea here is to use as much of the native library as possible, without using fragile hacks like custom element names that break between releases. The downside of this is that we cannot represent all possible trees; specifically the following are known to cause problems: Text or comments as siblings of the root element Docypes with no name When any of these things occur, we emit a DataLossWarning """ from __future__ import absolute_import, division, unicode_literals # pylint:disable=protected-access import warnings import re import sys from . import base from ..constants import DataLossWarning from .. import constants from . import etree as etree_builders from .. import _ihatexml import lxml.etree as etree fullTree = True tag_regexp = re.compile("{([^}]*)}(.*)") comment_type = etree.Comment("asd").tag class DocumentType(object): def __init__(self, name, publicId, systemId): self.name = name self.publicId = publicId self.systemId = systemId class Document(object): def __init__(self): self._elementTree = None self._childNodes = [] def appendChild(self, element): self._elementTree.getroot().addnext(element._element) def _getChildNodes(self): return self._childNodes childNodes = property(_getChildNodes) def testSerializer(element): rv = [] infosetFilter = _ihatexml.InfosetFilter(preventDoubleDashComments=True) def serializeElement(element, indent=0): if not hasattr(element, "tag"): if hasattr(element, "getroot"): # Full tree case rv.append("#document") if element.docinfo.internalDTD: if not (element.docinfo.public_id or element.docinfo.system_url): dtd_str = "" % element.docinfo.root_name else: dtd_str = """""" % ( element.docinfo.root_name, element.docinfo.public_id, element.docinfo.system_url) rv.append("|%s%s" % (' ' * (indent + 2), dtd_str)) next_element = element.getroot() while next_element.getprevious() is not None: next_element = next_element.getprevious() while next_element is not None: serializeElement(next_element, indent + 2) next_element = next_element.getnext() elif isinstance(element, str) or isinstance(element, bytes): # Text in a fragment assert isinstance(element, str) or sys.version_info[0] == 2 rv.append("|%s\"%s\"" % (' ' * indent, element)) else: # Fragment case rv.append("#document-fragment") for next_element in element: serializeElement(next_element, indent + 2) elif element.tag == comment_type: rv.append("|%s" % (' ' * indent, element.text)) if hasattr(element, "tail") and element.tail: rv.append("|%s\"%s\"" % (' ' * indent, element.tail)) else: assert isinstance(element, etree._Element) nsmatch = etree_builders.tag_regexp.match(element.tag) if nsmatch is not None: ns = nsmatch.group(1) tag = nsmatch.group(2) prefix = constants.prefixes[ns] rv.append("|%s<%s %s>" % (' ' * indent, prefix, infosetFilter.fromXmlName(tag))) else: rv.append("|%s<%s>" % (' ' * indent, infosetFilter.fromXmlName(element.tag))) if hasattr(element, "attrib"): attributes = [] for name, value in element.attrib.items(): nsmatch = tag_regexp.match(name) if nsmatch is not None: ns, name = nsmatch.groups() name = infosetFilter.fromXmlName(name) prefix = constants.prefixes[ns] attr_string = "%s %s" % (prefix, name) else: attr_string = infosetFilter.fromXmlName(name) attributes.append((attr_string, value)) for name, value in sorted(attributes): rv.append('|%s%s="%s"' % (' ' * (indent + 2), name, value)) if element.text: rv.append("|%s\"%s\"" % (' ' * (indent + 2), element.text)) indent += 2 for child in element: serializeElement(child, indent) if hasattr(element, "tail") and element.tail: rv.append("|%s\"%s\"" % (' ' * (indent - 2), element.tail)) serializeElement(element, 0) return "\n".join(rv) def tostring(element): """Serialize an element and its child nodes to a string""" rv = [] def serializeElement(element): if not hasattr(element, "tag"): if element.docinfo.internalDTD: if element.docinfo.doctype: dtd_str = element.docinfo.doctype else: dtd_str = "" % element.docinfo.root_name rv.append(dtd_str) serializeElement(element.getroot()) elif element.tag == comment_type: rv.append("" % (element.text,)) else: # This is assumed to be an ordinary element if not element.attrib: rv.append("<%s>" % (element.tag,)) else: attr = " ".join(["%s=\"%s\"" % (name, value) for name, value in element.attrib.items()]) rv.append("<%s %s>" % (element.tag, attr)) if element.text: rv.append(element.text) for child in element: serializeElement(child) rv.append("" % (element.tag,)) if hasattr(element, "tail") and element.tail: rv.append(element.tail) serializeElement(element) return "".join(rv) class TreeBuilder(base.TreeBuilder): documentClass = Document doctypeClass = DocumentType elementClass = None commentClass = None fragmentClass = Document implementation = etree def __init__(self, namespaceHTMLElements, fullTree=False): builder = etree_builders.getETreeModule(etree, fullTree=fullTree) infosetFilter = self.infosetFilter = _ihatexml.InfosetFilter(preventDoubleDashComments=True) self.namespaceHTMLElements = namespaceHTMLElements class Attributes(dict): def __init__(self, element, value=None): if value is None: value = {} self._element = element dict.__init__(self, value) # pylint:disable=non-parent-init-called for key, value in self.items(): if isinstance(key, tuple): name = "{%s}%s" % (key[2], infosetFilter.coerceAttribute(key[1])) else: name = infosetFilter.coerceAttribute(key) self._element._element.attrib[name] = value def __setitem__(self, key, value): dict.__setitem__(self, key, value) if isinstance(key, tuple): name = "{%s}%s" % (key[2], infosetFilter.coerceAttribute(key[1])) else: name = infosetFilter.coerceAttribute(key) self._element._element.attrib[name] = value class Element(builder.Element): def __init__(self, name, namespace): name = infosetFilter.coerceElement(name) builder.Element.__init__(self, name, namespace=namespace) self._attributes = Attributes(self) def _setName(self, name): self._name = infosetFilter.coerceElement(name) self._element.tag = self._getETreeTag( self._name, self._namespace) def _getName(self): return infosetFilter.fromXmlName(self._name) name = property(_getName, _setName) def _getAttributes(self): return self._attributes def _setAttributes(self, attributes): self._attributes = Attributes(self, attributes) attributes = property(_getAttributes, _setAttributes) def insertText(self, data, insertBefore=None): data = infosetFilter.coerceCharacters(data) builder.Element.insertText(self, data, insertBefore) def appendChild(self, child): builder.Element.appendChild(self, child) class Comment(builder.Comment): def __init__(self, data): data = infosetFilter.coerceComment(data) builder.Comment.__init__(self, data) def _setData(self, data): data = infosetFilter.coerceComment(data) self._element.text = data def _getData(self): return self._element.text data = property(_getData, _setData) self.elementClass = Element self.commentClass = Comment # self.fragmentClass = builder.DocumentFragment base.TreeBuilder.__init__(self, namespaceHTMLElements) def reset(self): base.TreeBuilder.reset(self) self.insertComment = self.insertCommentInitial self.initial_comments = [] self.doctype = None def testSerializer(self, element): return testSerializer(element) def getDocument(self): if fullTree: return self.document._elementTree else: return self.document._elementTree.getroot() def getFragment(self): fragment = [] element = self.openElements[0]._element if element.text: fragment.append(element.text) fragment.extend(list(element)) if element.tail: fragment.append(element.tail) return fragment def insertDoctype(self, token): name = token["name"] publicId = token["publicId"] systemId = token["systemId"] if not name: warnings.warn("lxml cannot represent empty doctype", DataLossWarning) self.doctype = None else: coercedName = self.infosetFilter.coerceElement(name) if coercedName != name: warnings.warn("lxml cannot represent non-xml doctype", DataLossWarning) doctype = self.doctypeClass(coercedName, publicId, systemId) self.doctype = doctype def insertCommentInitial(self, data, parent=None): assert parent is None or parent is self.document assert self.document._elementTree is None self.initial_comments.append(data) def insertCommentMain(self, data, parent=None): if (parent == self.document and self.document._elementTree.getroot()[-1].tag == comment_type): warnings.warn("lxml cannot represent adjacent comments beyond the root elements", DataLossWarning) super(TreeBuilder, self).insertComment(data, parent) def insertRoot(self, token): """Create the document root""" # Because of the way libxml2 works, it doesn't seem to be possible to # alter information like the doctype after the tree has been parsed. # Therefore we need to use the built-in parser to create our initial # tree, after which we can add elements like normal docStr = "" if self.doctype: assert self.doctype.name docStr += "= 0 and sysid.find('"') >= 0: warnings.warn("DOCTYPE system cannot contain single and double quotes", DataLossWarning) sysid = sysid.replace("'", 'U00027') if sysid.find("'") >= 0: docStr += '"%s"' % sysid else: docStr += "'%s'" % sysid else: docStr += "''" docStr += ">" if self.doctype.name != token["name"]: warnings.warn("lxml cannot represent doctype with a different name to the root element", DataLossWarning) docStr += "" root = etree.fromstring(docStr) # Append the initial comments: for comment_token in self.initial_comments: comment = self.commentClass(comment_token["data"]) root.addprevious(comment._element) # Create the root document and add the ElementTree to it self.document = self.documentClass() self.document._elementTree = root.getroottree() # Give the root element the right name name = token["name"] namespace = token.get("namespace", self.defaultNamespace) if namespace is None: etree_tag = name else: etree_tag = "{%s}%s" % (namespace, name) root.tag = etree_tag # Add the root element to the internal child/open data structures root_element = self.elementClass(name, namespace) root_element._element = root self.document._childNodes.append(root_element) self.openElements.append(root_element) # Reset to the default insert comment function self.insertComment = self.insertCommentMain etree_lxml.pyc000064400000035622147205641420007436 0ustar00 abc@`s'dZddlmZmZmZddlZddlZddlZddlm Z ddl m Z ddlm Z dd lm Z dd lmZddlj Z eZejd Ze jd jZd efdYZdefdYZdZdZde jfdYZdS(uModule for supporting the lxml.etree library. The idea here is to use as much of the native library as possible, without using fragile hacks like custom element names that break between releases. The downside of this is that we cannot represent all possible trees; specifically the following are known to cause problems: Text or comments as siblings of the root element Docypes with no name When any of these things occur, we emit a DataLossWarning i(tabsolute_importtdivisiontunicode_literalsNi(tbasei(tDataLossWarning(t constants(tetree(t _ihatexmlu {([^}]*)}(.*)uasdt DocumentTypecB`seZdZRS(cC`s||_||_||_dS(N(tnametpublicIdtsystemId(tselfR R R ((sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt__init__#s  (t__name__t __module__R (((sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyR"stDocumentcB`s/eZdZdZdZeeZRS(cC`sd|_g|_dS(N(tNonet _elementTreet _childNodes(R ((sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyR *s cC`s|jjj|jdS(N(Rtgetroottaddnextt_element(R telement((sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt appendChild.scC`s|jS(N(R(R ((sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt_getChildNodes1s(RRR RRtpropertyt childNodes(((sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyR)s   c`sJgtjdtdfd|ddjS(NtpreventDoubleDashCommentsic `sMt|dst|dr jd|jjr|jjpL|jjsbd|jj}n%d|jj|jj|jjf}jdd|d|fn|j}x"|jdk r|j}qWx|dk r ||d|j }qWqIt |t s+t |t rqt |t sStjd dksStjd d||fqIjd x|D]}||dqWn|jtkr jd d||jft|d rI|jrIjd d||jfqIn=t |tjs$ttjj|j}|dk r|jd}|jd}tj|}jdd||j|fn'jdd|j|jft|drg}x|jjD]\} } tj| }|dk rN|j \}} j| } tj|}d|| f} nj| } |j| | fqWx?t!|D].\} } jdd|d| | fqWn|jrjd d|d|jfn|d7}x|D]} | |qWt|d rI|jrIjd d|d|jfndS(Nutagugetrootu #documentu uu|%s%su iiu|%s"%s"u#document-fragmentu|%sutailiu |%s<%s %s>u|%s<%s>uattribu%s %su |%s%s="%s"("thasattrtappendtdocinfot internalDTDt public_idt system_urlt root_nameRt getpreviousRtgetnextt isinstancetstrtbytestsyst version_infotAssertionErrorttagt comment_typettextttailRt_Elementtetree_builderst tag_regexptmatchtgroupRtprefixest fromXmlNametattribtitemstgroupstsorted( Rtindenttdtd_strt next_elementtnsmatchtnsR,tprefixt attributesR tvaluet attr_stringtchild(t infosetFiltertrvtserializeElement(sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyRG;st      " (  $    ) %  u (Rt InfosetFiltertTruetjoin(R((RERFRGsP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyttestSerializer7s F c`s/gfd|djS(u4Serialize an element and its child nodes to a stringc`st|dsi|jjrV|jjr6|jj}nd|jj}j|n|jn|jtkrjd|j fn|j sjd|jfnUdj g|j j D]\}}d||f^q}jd|j|f|j r&j|j nx|D]}|q-Wjd|jft|d r|j rj|j ndS( Nutagu u u<%s>u u%s="%s"u<%s %s>uutail(RRR tdoctypeR#RRR,R-R.R7RJR8R/(RR<R RBtattrRD(RFRG(sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyRGs*    2  u(RJ(R((RFRGsP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyttostrings t TreeBuildercB`seZeZeZd Zd ZeZ e Z e dZ dZdZdZdZdZd dZd dZdZRS( c`stjtd|tjdt|_||_dtffdYdj ffdY}dj ffdY}||_ ||_ t jj||dS( NtfullTreeRt Attributesc`s)eZdfdZfdZRS(c`s|dkri}n||_tj||xo|jD]a\}}t|trzd|dj|df}nj|}||jjj|unameuGlxml cannot represent doctype with a different name to the root elementu$udatau namespaceu{%s}%sN( RLR R+R RR REt coercePubidtfindRzR{RtreplaceRt fromstringRrRnt addpreviousRt documentClassRst getroottreeRtgettdefaultNamespaceR,RmRRRuRRq( R R}tdocStrtsysidtroott comment_tokentcommentR RXt etree_tagt root_element((sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt insertRoot7sL    *        N(RRRRRR|RRmRnt fragmentClassRtimplementationtFalseR RoRKRtRyRRpRR(((sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyROs L      (t__doc__t __future__RRRRztreR)tRRRRR1Rt lxml.etreeRIRPtcompileR2RgR,R-tobjectRRRKRNRO(((sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt s$    O )etree_lxml.pyo000064400000035244147205641420007452 0ustar00 abc@`s'dZddlmZmZmZddlZddlZddlZddlm Z ddl m Z ddlm Z dd lm Z dd lmZddlj Z eZejd Ze jd jZd efdYZdefdYZdZdZde jfdYZdS(uModule for supporting the lxml.etree library. The idea here is to use as much of the native library as possible, without using fragile hacks like custom element names that break between releases. The downside of this is that we cannot represent all possible trees; specifically the following are known to cause problems: Text or comments as siblings of the root element Docypes with no name When any of these things occur, we emit a DataLossWarning i(tabsolute_importtdivisiontunicode_literalsNi(tbasei(tDataLossWarning(t constants(tetree(t _ihatexmlu {([^}]*)}(.*)uasdt DocumentTypecB`seZdZRS(cC`s||_||_||_dS(N(tnametpublicIdtsystemId(tselfR R R ((sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt__init__#s  (t__name__t __module__R (((sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyR"stDocumentcB`s/eZdZdZdZeeZRS(cC`sd|_g|_dS(N(tNonet _elementTreet _childNodes(R ((sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyR *s cC`s|jjj|jdS(N(Rtgetroottaddnextt_element(R telement((sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt appendChild.scC`s|jS(N(R(R ((sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt_getChildNodes1s(RRR RRtpropertyt childNodes(((sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyR)s   c`sJgtjdtdfd|ddjS(NtpreventDoubleDashCommentsic `s t|ds{t|dr jd|jjr|jjpL|jjsbd|jj}n%d|jj|jj|jjf}jdd|d|fn|j}x"|jdk r|j}qWx|dk r ||d|j }qWq t |t s+t |t rIjd d||fq jd x|D]}||dq]Wn|jtkrjd d||jft|d r |jr jd d||jfq n%tjj|j}|dk rZ|jd }|jd}tj|}jdd||j|fn'jdd|j|jft|drvg}x|jjD]\} } tj| }|dk r|j\}} j| } tj|}d|| f} nj| } |j| | fqWx?t|D].\} } jdd|d| | fqAWn|jrjd d|d|jfn|d7}x|D]} | |qWt|d r |jr jd d|d|jfndS(Nutagugetrootu #documentu uu|%s%su iu|%s"%s"u#document-fragmentu|%sutailiu |%s<%s %s>u|%s<%s>uattribu%s %su |%s%s="%s"(thasattrtappendtdocinfot internalDTDt public_idt system_urlt root_nameRt getpreviousRtgetnextt isinstancetstrtbytesttagt comment_typettextttailtetree_builderst tag_regexptmatchtgroupRtprefixest fromXmlNametattribtitemstgroupstsorted( Rtindenttdtd_strt next_elementtnsmatchtnsR)tprefixt attributesR tvaluet attr_stringtchild(t infosetFiltertrvtserializeElement(sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyRC;sp      "   $    ) %  u (Rt InfosetFiltertTruetjoin(R((RARBRCsP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyttestSerializer7s F c`s/gfd|djS(u4Serialize an element and its child nodes to a stringc`st|dsi|jjrV|jjr6|jj}nd|jj}j|n|jn|jtkrjd|j fn|j sjd|jfnUdj g|j j D]\}}d||f^q}jd|j|f|j r&j|j nx|D]}|q-Wjd|jft|d r|j rj|j ndS( Nutagu u u<%s>u u%s="%s"u<%s %s>uutail(RRR tdoctypeR#RRR)R*R+R3RFR4R,(RR8R R>tattrR@(RBRC(sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyRCs*    2  u(RF(R((RBRCsP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyttostrings t TreeBuildercB`seZeZeZd Zd ZeZ e Z e dZ dZdZdZdZdZd dZd dZdZRS( c`stjtd|tjdt|_||_dtffdYdj ffdY}dj ffdY}||_ ||_ t jj||dS( NtfullTreeRt Attributesc`s)eZdfdZfdZRS(c`s|dkri}n||_tj||xo|jD]a\}}t|trzd|dj|df}nj|}||jjj|tkeyR (RA(sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyR s   $c`sltj|||t|trFd|dj|df}nj|}||jjj|R (RA(sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyRRs $N(RRRR RR((RA(sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyRMs tElementc`seZfdZfdZfdZeeeZdZfdZeeeZ dfdZ fdZ RS(c`s;j|}jj||d|||_dS(Nt namespace(t coerceElementRSR t _attributes(R R RT(RMtbuilderRA(sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyR sc`s4j||_|j|j|j|j_dS(N(RUt_namet _getETreeTagt _namespaceRR)(R R (RA(sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt_setNamesc`sj|jS(N(R2RX(R (RA(sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt_getNamescS`s|jS(N(RV(R ((sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt_getAttributessc`s|||_dS(N(RV(R R=(RM(sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt_setAttributessc`s)j|}jj|||dS(N(tcoerceCharactersRSt insertText(R tdatat insertBefore(RWRA(sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyR`sc`sjj||dS(N(RSR(R R@(RW(sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyRsN( RRR R[R\RR R]R^R=RR`R((RMRWRA(sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyRSs tCommentc`sAeZfdZfdZdZeeeZRS(c`s&j|}jj||dS(N(t coerceCommentRcR (R Ra(RWRA(sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyR sc`sj|}||j_dS(N(RdRR+(R Ra(RA(sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt_setDatascS`s |jjS(N(RR+(R ((sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt_getDatas(RRR ReRfRRa((RWRA(sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyRcs (R-tgetETreeModuleRRRDRERAtnamespaceHTMLElementsRNRSRct elementClasst commentClassRRKR (R RhRLRSRc((RMRWRAsP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyR s %"  cC`s2tjj||j|_g|_d|_dS(N(RRKtresettinsertCommentInitialt insertCommenttinitial_commentsRRH(R ((sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyRks  cC`s t|S(N(RG(R R((sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyRG scC`s$tr|jjS|jjjSdS(N(RLtdocumentRR(R ((sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt getDocument s cC`seg}|jdj}|jr2|j|jn|jt||jra|j|jn|S(Ni(t openElementsRR+RtextendtlistR,(R tfragmentR((sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt getFragments  cC`s|d}|d}|d}|s@tjdtd|_nO|jj|}||krqtjdtn|j|||}||_dS(NunameupublicIdusystemIdu#lxml cannot represent empty doctypeu%lxml cannot represent non-xml doctype(twarningstwarnRRRHRARUt doctypeClass(R ttokenR R R t coercedNameRH((sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt insertDoctypes     cC`s|jj|dS(N(RnR(R Ratparent((sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyRl,scC`s^||jkrA|jjjdjtkrAtjdtntt |j ||dS(Niu@lxml cannot represent adjacent comments beyond the root elements( RoRRR)R*RvRwRtsuperRKRm(R RaR|((sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pytinsertCommentMain1sc C`sZd}|jrN|d|jj7}|jjdk sG|jjdk r|d|jj|jjped7}|jjr |jj}|jddkr|jddkrtj dt |j dd}n|jddkr|d |7}q|d |7}q|d 7}n|d 7}|jj|d krNtj dt qNn|d7}t j |}x4|jD])}|j|d}|j|jqqW|j|_|j|j_|d }|jd|j}|dkr|} nd||f} | |_|j||} || _|jjj| |jj| |j|_dS(uCreate the document rootuu unameuGlxml cannot represent doctype with a different name to the root elementu$udatau namespaceu{%s}%sN(RHR R RR RAt coercePubidtfindRvRwRtreplaceRt fromstringRnRjt addpreviousRt documentClassRot getroottreeRtgettdefaultNamespaceR)RiRRRqR~Rm( R RytdocStrtsysidtroott comment_tokentcommentR RTt etree_tagt root_element((sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt insertRoot7sJ    *        N(RRRRRRxRRiRjt fragmentClassRtimplementationtFalseR RkRGRpRuR{RlR~R(((sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyRKs L      (t__doc__t __future__RRRRvtretsystRRRRR-Rt lxml.etreeRERLtcompileR.RcR)R*tobjectRRRGRJRK(((sP/usr/lib/python2.7/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.pyt s$    O )