PageRenderTime 57ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/External.LCA_RESTRICTED/Languages/CPython/27/Lib/xml/etree/ElementTree.py

http://github.com/IronLanguages/main
Python | 1649 lines | 1538 code | 15 blank | 96 comment | 37 complexity | eef4cf8c2a75e1dbba6888808b0855b2 MD5 | raw file
Possible License(s): CPL-1.0, BSD-3-Clause, ISC, GPL-2.0, MPL-2.0-no-copyleft-exception

Large files files are truncated, but you can click here to view the full file

  1. #
  2. # ElementTree
  3. # $Id: ElementTree.py 3440 2008-07-18 14:45:01Z fredrik $
  4. #
  5. # light-weight XML support for Python 2.3 and later.
  6. #
  7. # history (since 1.2.6):
  8. # 2005-11-12 fl added tostringlist/fromstringlist helpers
  9. # 2006-07-05 fl merged in selected changes from the 1.3 sandbox
  10. # 2006-07-05 fl removed support for 2.1 and earlier
  11. # 2007-06-21 fl added deprecation/future warnings
  12. # 2007-08-25 fl added doctype hook, added parser version attribute etc
  13. # 2007-08-26 fl added new serializer code (better namespace handling, etc)
  14. # 2007-08-27 fl warn for broken /tag searches on tree level
  15. # 2007-09-02 fl added html/text methods to serializer (experimental)
  16. # 2007-09-05 fl added method argument to tostring/tostringlist
  17. # 2007-09-06 fl improved error handling
  18. # 2007-09-13 fl added itertext, iterfind; assorted cleanups
  19. # 2007-12-15 fl added C14N hooks, copy method (experimental)
  20. #
  21. # Copyright (c) 1999-2008 by Fredrik Lundh. All rights reserved.
  22. #
  23. # fredrik@pythonware.com
  24. # http://www.pythonware.com
  25. #
  26. # --------------------------------------------------------------------
  27. # The ElementTree toolkit is
  28. #
  29. # Copyright (c) 1999-2008 by Fredrik Lundh
  30. #
  31. # By obtaining, using, and/or copying this software and/or its
  32. # associated documentation, you agree that you have read, understood,
  33. # and will comply with the following terms and conditions:
  34. #
  35. # Permission to use, copy, modify, and distribute this software and
  36. # its associated documentation for any purpose and without fee is
  37. # hereby granted, provided that the above copyright notice appears in
  38. # all copies, and that both that copyright notice and this permission
  39. # notice appear in supporting documentation, and that the name of
  40. # Secret Labs AB or the author not be used in advertising or publicity
  41. # pertaining to distribution of the software without specific, written
  42. # prior permission.
  43. #
  44. # SECRET LABS AB AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  45. # TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANT-
  46. # ABILITY AND FITNESS. IN NO EVENT SHALL SECRET LABS AB OR THE AUTHOR
  47. # BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
  48. # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  49. # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
  50. # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  51. # OF THIS SOFTWARE.
  52. # --------------------------------------------------------------------
  53. # Licensed to PSF under a Contributor Agreement.
  54. # See http://www.python.org/psf/license for licensing details.
  55. __all__ = [
  56. # public symbols
  57. "Comment",
  58. "dump",
  59. "Element", "ElementTree",
  60. "fromstring", "fromstringlist",
  61. "iselement", "iterparse",
  62. "parse", "ParseError",
  63. "PI", "ProcessingInstruction",
  64. "QName",
  65. "SubElement",
  66. "tostring", "tostringlist",
  67. "TreeBuilder",
  68. "VERSION",
  69. "XML",
  70. "XMLParser", "XMLTreeBuilder",
  71. ]
  72. VERSION = "1.3.0"
  73. ##
  74. # The <b>Element</b> type is a flexible container object, designed to
  75. # store hierarchical data structures in memory. The type can be
  76. # described as a cross between a list and a dictionary.
  77. # <p>
  78. # Each element has a number of properties associated with it:
  79. # <ul>
  80. # <li>a <i>tag</i>. This is a string identifying what kind of data
  81. # this element represents (the element type, in other words).</li>
  82. # <li>a number of <i>attributes</i>, stored in a Python dictionary.</li>
  83. # <li>a <i>text</i> string.</li>
  84. # <li>an optional <i>tail</i> string.</li>
  85. # <li>a number of <i>child elements</i>, stored in a Python sequence</li>
  86. # </ul>
  87. #
  88. # To create an element instance, use the {@link #Element} constructor
  89. # or the {@link #SubElement} factory function.
  90. # <p>
  91. # The {@link #ElementTree} class can be used to wrap an element
  92. # structure, and convert it from and to XML.
  93. ##
  94. import sys
  95. import re
  96. import warnings
  97. class _SimpleElementPath(object):
  98. # emulate pre-1.2 find/findtext/findall behaviour
  99. def find(self, element, tag, namespaces=None):
  100. for elem in element:
  101. if elem.tag == tag:
  102. return elem
  103. return None
  104. def findtext(self, element, tag, default=None, namespaces=None):
  105. elem = self.find(element, tag)
  106. if elem is None:
  107. return default
  108. return elem.text or ""
  109. def iterfind(self, element, tag, namespaces=None):
  110. if tag[:3] == ".//":
  111. for elem in element.iter(tag[3:]):
  112. yield elem
  113. for elem in element:
  114. if elem.tag == tag:
  115. yield elem
  116. def findall(self, element, tag, namespaces=None):
  117. return list(self.iterfind(element, tag, namespaces))
  118. try:
  119. from . import ElementPath
  120. except ImportError:
  121. ElementPath = _SimpleElementPath()
  122. ##
  123. # Parser error. This is a subclass of <b>SyntaxError</b>.
  124. # <p>
  125. # In addition to the exception value, an exception instance contains a
  126. # specific exception code in the <b>code</b> attribute, and the line and
  127. # column of the error in the <b>position</b> attribute.
  128. class ParseError(SyntaxError):
  129. pass
  130. # --------------------------------------------------------------------
  131. ##
  132. # Checks if an object appears to be a valid element object.
  133. #
  134. # @param An element instance.
  135. # @return A true value if this is an element object.
  136. # @defreturn flag
  137. def iselement(element):
  138. # FIXME: not sure about this; might be a better idea to look
  139. # for tag/attrib/text attributes
  140. return isinstance(element, Element) or hasattr(element, "tag")
  141. ##
  142. # Element class. This class defines the Element interface, and
  143. # provides a reference implementation of this interface.
  144. # <p>
  145. # The element name, attribute names, and attribute values can be
  146. # either ASCII strings (ordinary Python strings containing only 7-bit
  147. # ASCII characters) or Unicode strings.
  148. #
  149. # @param tag The element name.
  150. # @param attrib An optional dictionary, containing element attributes.
  151. # @param **extra Additional attributes, given as keyword arguments.
  152. # @see Element
  153. # @see SubElement
  154. # @see Comment
  155. # @see ProcessingInstruction
  156. class Element(object):
  157. # <tag attrib>text<child/>...</tag>tail
  158. ##
  159. # (Attribute) Element tag.
  160. tag = None
  161. ##
  162. # (Attribute) Element attribute dictionary. Where possible, use
  163. # {@link #Element.get},
  164. # {@link #Element.set},
  165. # {@link #Element.keys}, and
  166. # {@link #Element.items} to access
  167. # element attributes.
  168. attrib = None
  169. ##
  170. # (Attribute) Text before first subelement. This is either a
  171. # string or the value None. Note that if there was no text, this
  172. # attribute may be either None or an empty string, depending on
  173. # the parser.
  174. text = None
  175. ##
  176. # (Attribute) Text after this element's end tag, but before the
  177. # next sibling element's start tag. This is either a string or
  178. # the value None. Note that if there was no text, this attribute
  179. # may be either None or an empty string, depending on the parser.
  180. tail = None # text after end tag, if any
  181. # constructor
  182. def __init__(self, tag, attrib={}, **extra):
  183. attrib = attrib.copy()
  184. attrib.update(extra)
  185. self.tag = tag
  186. self.attrib = attrib
  187. self._children = []
  188. def __repr__(self):
  189. return "<Element %s at 0x%x>" % (repr(self.tag), id(self))
  190. ##
  191. # Creates a new element object of the same type as this element.
  192. #
  193. # @param tag Element tag.
  194. # @param attrib Element attributes, given as a dictionary.
  195. # @return A new element instance.
  196. def makeelement(self, tag, attrib):
  197. return self.__class__(tag, attrib)
  198. ##
  199. # (Experimental) Copies the current element. This creates a
  200. # shallow copy; subelements will be shared with the original tree.
  201. #
  202. # @return A new element instance.
  203. def copy(self):
  204. elem = self.makeelement(self.tag, self.attrib)
  205. elem.text = self.text
  206. elem.tail = self.tail
  207. elem[:] = self
  208. return elem
  209. ##
  210. # Returns the number of subelements. Note that this only counts
  211. # full elements; to check if there's any content in an element, you
  212. # have to check both the length and the <b>text</b> attribute.
  213. #
  214. # @return The number of subelements.
  215. def __len__(self):
  216. return len(self._children)
  217. def __nonzero__(self):
  218. warnings.warn(
  219. "The behavior of this method will change in future versions. "
  220. "Use specific 'len(elem)' or 'elem is not None' test instead.",
  221. FutureWarning, stacklevel=2
  222. )
  223. return len(self._children) != 0 # emulate old behaviour, for now
  224. ##
  225. # Returns the given subelement, by index.
  226. #
  227. # @param index What subelement to return.
  228. # @return The given subelement.
  229. # @exception IndexError If the given element does not exist.
  230. def __getitem__(self, index):
  231. return self._children[index]
  232. ##
  233. # Replaces the given subelement, by index.
  234. #
  235. # @param index What subelement to replace.
  236. # @param element The new element value.
  237. # @exception IndexError If the given element does not exist.
  238. def __setitem__(self, index, element):
  239. # if isinstance(index, slice):
  240. # for elt in element:
  241. # assert iselement(elt)
  242. # else:
  243. # assert iselement(element)
  244. self._children[index] = element
  245. ##
  246. # Deletes the given subelement, by index.
  247. #
  248. # @param index What subelement to delete.
  249. # @exception IndexError If the given element does not exist.
  250. def __delitem__(self, index):
  251. del self._children[index]
  252. ##
  253. # Adds a subelement to the end of this element. In document order,
  254. # the new element will appear after the last existing subelement (or
  255. # directly after the text, if it's the first subelement), but before
  256. # the end tag for this element.
  257. #
  258. # @param element The element to add.
  259. def append(self, element):
  260. # assert iselement(element)
  261. self._children.append(element)
  262. ##
  263. # Appends subelements from a sequence.
  264. #
  265. # @param elements A sequence object with zero or more elements.
  266. # @since 1.3
  267. def extend(self, elements):
  268. # for element in elements:
  269. # assert iselement(element)
  270. self._children.extend(elements)
  271. ##
  272. # Inserts a subelement at the given position in this element.
  273. #
  274. # @param index Where to insert the new subelement.
  275. def insert(self, index, element):
  276. # assert iselement(element)
  277. self._children.insert(index, element)
  278. ##
  279. # Removes a matching subelement. Unlike the <b>find</b> methods,
  280. # this method compares elements based on identity, not on tag
  281. # value or contents. To remove subelements by other means, the
  282. # easiest way is often to use a list comprehension to select what
  283. # elements to keep, and use slice assignment to update the parent
  284. # element.
  285. #
  286. # @param element What element to remove.
  287. # @exception ValueError If a matching element could not be found.
  288. def remove(self, element):
  289. # assert iselement(element)
  290. self._children.remove(element)
  291. ##
  292. # (Deprecated) Returns all subelements. The elements are returned
  293. # in document order.
  294. #
  295. # @return A list of subelements.
  296. # @defreturn list of Element instances
  297. def getchildren(self):
  298. warnings.warn(
  299. "This method will be removed in future versions. "
  300. "Use 'list(elem)' or iteration over elem instead.",
  301. DeprecationWarning, stacklevel=2
  302. )
  303. return self._children
  304. ##
  305. # Finds the first matching subelement, by tag name or path.
  306. #
  307. # @param path What element to look for.
  308. # @keyparam namespaces Optional namespace prefix map.
  309. # @return The first matching element, or None if no element was found.
  310. # @defreturn Element or None
  311. def find(self, path, namespaces=None):
  312. return ElementPath.find(self, path, namespaces)
  313. ##
  314. # Finds text for the first matching subelement, by tag name or path.
  315. #
  316. # @param path What element to look for.
  317. # @param default What to return if the element was not found.
  318. # @keyparam namespaces Optional namespace prefix map.
  319. # @return The text content of the first matching element, or the
  320. # default value no element was found. Note that if the element
  321. # is found, but has no text content, this method returns an
  322. # empty string.
  323. # @defreturn string
  324. def findtext(self, path, default=None, namespaces=None):
  325. return ElementPath.findtext(self, path, default, namespaces)
  326. ##
  327. # Finds all matching subelements, by tag name or path.
  328. #
  329. # @param path What element to look for.
  330. # @keyparam namespaces Optional namespace prefix map.
  331. # @return A list or other sequence containing all matching elements,
  332. # in document order.
  333. # @defreturn list of Element instances
  334. def findall(self, path, namespaces=None):
  335. return ElementPath.findall(self, path, namespaces)
  336. ##
  337. # Finds all matching subelements, by tag name or path.
  338. #
  339. # @param path What element to look for.
  340. # @keyparam namespaces Optional namespace prefix map.
  341. # @return An iterator or sequence containing all matching elements,
  342. # in document order.
  343. # @defreturn a generated sequence of Element instances
  344. def iterfind(self, path, namespaces=None):
  345. return ElementPath.iterfind(self, path, namespaces)
  346. ##
  347. # Resets an element. This function removes all subelements, clears
  348. # all attributes, and sets the <b>text</b> and <b>tail</b> attributes
  349. # to None.
  350. def clear(self):
  351. self.attrib.clear()
  352. self._children = []
  353. self.text = self.tail = None
  354. ##
  355. # Gets an element attribute. Equivalent to <b>attrib.get</b>, but
  356. # some implementations may handle this a bit more efficiently.
  357. #
  358. # @param key What attribute to look for.
  359. # @param default What to return if the attribute was not found.
  360. # @return The attribute value, or the default value, if the
  361. # attribute was not found.
  362. # @defreturn string or None
  363. def get(self, key, default=None):
  364. return self.attrib.get(key, default)
  365. ##
  366. # Sets an element attribute. Equivalent to <b>attrib[key] = value</b>,
  367. # but some implementations may handle this a bit more efficiently.
  368. #
  369. # @param key What attribute to set.
  370. # @param value The attribute value.
  371. def set(self, key, value):
  372. self.attrib[key] = value
  373. ##
  374. # Gets a list of attribute names. The names are returned in an
  375. # arbitrary order (just like for an ordinary Python dictionary).
  376. # Equivalent to <b>attrib.keys()</b>.
  377. #
  378. # @return A list of element attribute names.
  379. # @defreturn list of strings
  380. def keys(self):
  381. return self.attrib.keys()
  382. ##
  383. # Gets element attributes, as a sequence. The attributes are
  384. # returned in an arbitrary order. Equivalent to <b>attrib.items()</b>.
  385. #
  386. # @return A list of (name, value) tuples for all attributes.
  387. # @defreturn list of (string, string) tuples
  388. def items(self):
  389. return self.attrib.items()
  390. ##
  391. # Creates a tree iterator. The iterator loops over this element
  392. # and all subelements, in document order, and returns all elements
  393. # with a matching tag.
  394. # <p>
  395. # If the tree structure is modified during iteration, new or removed
  396. # elements may or may not be included. To get a stable set, use the
  397. # list() function on the iterator, and loop over the resulting list.
  398. #
  399. # @param tag What tags to look for (default is to return all elements).
  400. # @return An iterator containing all the matching elements.
  401. # @defreturn iterator
  402. def iter(self, tag=None):
  403. if tag == "*":
  404. tag = None
  405. if tag is None or self.tag == tag:
  406. yield self
  407. for e in self._children:
  408. for e in e.iter(tag):
  409. yield e
  410. # compatibility
  411. def getiterator(self, tag=None):
  412. # Change for a DeprecationWarning in 1.4
  413. warnings.warn(
  414. "This method will be removed in future versions. "
  415. "Use 'elem.iter()' or 'list(elem.iter())' instead.",
  416. PendingDeprecationWarning, stacklevel=2
  417. )
  418. return list(self.iter(tag))
  419. ##
  420. # Creates a text iterator. The iterator loops over this element
  421. # and all subelements, in document order, and returns all inner
  422. # text.
  423. #
  424. # @return An iterator containing all inner text.
  425. # @defreturn iterator
  426. def itertext(self):
  427. tag = self.tag
  428. if not isinstance(tag, basestring) and tag is not None:
  429. return
  430. if self.text:
  431. yield self.text
  432. for e in self:
  433. for s in e.itertext():
  434. yield s
  435. if e.tail:
  436. yield e.tail
  437. # compatibility
  438. _Element = _ElementInterface = Element
  439. ##
  440. # Subelement factory. This function creates an element instance, and
  441. # appends it to an existing element.
  442. # <p>
  443. # The element name, attribute names, and attribute values can be
  444. # either 8-bit ASCII strings or Unicode strings.
  445. #
  446. # @param parent The parent element.
  447. # @param tag The subelement name.
  448. # @param attrib An optional dictionary, containing element attributes.
  449. # @param **extra Additional attributes, given as keyword arguments.
  450. # @return An element instance.
  451. # @defreturn Element
  452. def SubElement(parent, tag, attrib={}, **extra):
  453. attrib = attrib.copy()
  454. attrib.update(extra)
  455. element = parent.makeelement(tag, attrib)
  456. parent.append(element)
  457. return element
  458. ##
  459. # Comment element factory. This factory function creates a special
  460. # element that will be serialized as an XML comment by the standard
  461. # serializer.
  462. # <p>
  463. # The comment string can be either an 8-bit ASCII string or a Unicode
  464. # string.
  465. #
  466. # @param text A string containing the comment string.
  467. # @return An element instance, representing a comment.
  468. # @defreturn Element
  469. def Comment(text=None):
  470. element = Element(Comment)
  471. element.text = text
  472. return element
  473. ##
  474. # PI element factory. This factory function creates a special element
  475. # that will be serialized as an XML processing instruction by the standard
  476. # serializer.
  477. #
  478. # @param target A string containing the PI target.
  479. # @param text A string containing the PI contents, if any.
  480. # @return An element instance, representing a PI.
  481. # @defreturn Element
  482. def ProcessingInstruction(target, text=None):
  483. element = Element(ProcessingInstruction)
  484. element.text = target
  485. if text:
  486. element.text = element.text + " " + text
  487. return element
  488. PI = ProcessingInstruction
  489. ##
  490. # QName wrapper. This can be used to wrap a QName attribute value, in
  491. # order to get proper namespace handling on output.
  492. #
  493. # @param text A string containing the QName value, in the form {uri}local,
  494. # or, if the tag argument is given, the URI part of a QName.
  495. # @param tag Optional tag. If given, the first argument is interpreted as
  496. # an URI, and this argument is interpreted as a local name.
  497. # @return An opaque object, representing the QName.
  498. class QName(object):
  499. def __init__(self, text_or_uri, tag=None):
  500. if tag:
  501. text_or_uri = "{%s}%s" % (text_or_uri, tag)
  502. self.text = text_or_uri
  503. def __str__(self):
  504. return self.text
  505. def __hash__(self):
  506. return hash(self.text)
  507. def __cmp__(self, other):
  508. if isinstance(other, QName):
  509. return cmp(self.text, other.text)
  510. return cmp(self.text, other)
  511. # --------------------------------------------------------------------
  512. ##
  513. # ElementTree wrapper class. This class represents an entire element
  514. # hierarchy, and adds some extra support for serialization to and from
  515. # standard XML.
  516. #
  517. # @param element Optional root element.
  518. # @keyparam file Optional file handle or file name. If given, the
  519. # tree is initialized with the contents of this XML file.
  520. class ElementTree(object):
  521. def __init__(self, element=None, file=None):
  522. # assert element is None or iselement(element)
  523. self._root = element # first node
  524. if file:
  525. self.parse(file)
  526. ##
  527. # Gets the root element for this tree.
  528. #
  529. # @return An element instance.
  530. # @defreturn Element
  531. def getroot(self):
  532. return self._root
  533. ##
  534. # Replaces the root element for this tree. This discards the
  535. # current contents of the tree, and replaces it with the given
  536. # element. Use with care.
  537. #
  538. # @param element An element instance.
  539. def _setroot(self, element):
  540. # assert iselement(element)
  541. self._root = element
  542. ##
  543. # Loads an external XML document into this element tree.
  544. #
  545. # @param source A file name or file object. If a file object is
  546. # given, it only has to implement a <b>read(n)</b> method.
  547. # @keyparam parser An optional parser instance. If not given, the
  548. # standard {@link XMLParser} parser is used.
  549. # @return The document root element.
  550. # @defreturn Element
  551. # @exception ParseError If the parser fails to parse the document.
  552. def parse(self, source, parser=None):
  553. if not hasattr(source, "read"):
  554. source = open(source, "rb")
  555. if not parser:
  556. parser = XMLParser(target=TreeBuilder())
  557. while 1:
  558. data = source.read(65536)
  559. if not data:
  560. break
  561. parser.feed(data)
  562. self._root = parser.close()
  563. return self._root
  564. ##
  565. # Creates a tree iterator for the root element. The iterator loops
  566. # over all elements in this tree, in document order.
  567. #
  568. # @param tag What tags to look for (default is to return all elements)
  569. # @return An iterator.
  570. # @defreturn iterator
  571. def iter(self, tag=None):
  572. # assert self._root is not None
  573. return self._root.iter(tag)
  574. # compatibility
  575. def getiterator(self, tag=None):
  576. # Change for a DeprecationWarning in 1.4
  577. warnings.warn(
  578. "This method will be removed in future versions. "
  579. "Use 'tree.iter()' or 'list(tree.iter())' instead.",
  580. PendingDeprecationWarning, stacklevel=2
  581. )
  582. return list(self.iter(tag))
  583. ##
  584. # Finds the first toplevel element with given tag.
  585. # Same as getroot().find(path).
  586. #
  587. # @param path What element to look for.
  588. # @keyparam namespaces Optional namespace prefix map.
  589. # @return The first matching element, or None if no element was found.
  590. # @defreturn Element or None
  591. def find(self, path, namespaces=None):
  592. # assert self._root is not None
  593. if path[:1] == "/":
  594. path = "." + path
  595. warnings.warn(
  596. "This search is broken in 1.3 and earlier, and will be "
  597. "fixed in a future version. If you rely on the current "
  598. "behaviour, change it to %r" % path,
  599. FutureWarning, stacklevel=2
  600. )
  601. return self._root.find(path, namespaces)
  602. ##
  603. # Finds the element text for the first toplevel element with given
  604. # tag. Same as getroot().findtext(path).
  605. #
  606. # @param path What toplevel element to look for.
  607. # @param default What to return if the element was not found.
  608. # @keyparam namespaces Optional namespace prefix map.
  609. # @return The text content of the first matching element, or the
  610. # default value no element was found. Note that if the element
  611. # is found, but has no text content, this method returns an
  612. # empty string.
  613. # @defreturn string
  614. def findtext(self, path, default=None, namespaces=None):
  615. # assert self._root is not None
  616. if path[:1] == "/":
  617. path = "." + path
  618. warnings.warn(
  619. "This search is broken in 1.3 and earlier, and will be "
  620. "fixed in a future version. If you rely on the current "
  621. "behaviour, change it to %r" % path,
  622. FutureWarning, stacklevel=2
  623. )
  624. return self._root.findtext(path, default, namespaces)
  625. ##
  626. # Finds all toplevel elements with the given tag.
  627. # Same as getroot().findall(path).
  628. #
  629. # @param path What element to look for.
  630. # @keyparam namespaces Optional namespace prefix map.
  631. # @return A list or iterator containing all matching elements,
  632. # in document order.
  633. # @defreturn list of Element instances
  634. def findall(self, path, namespaces=None):
  635. # assert self._root is not None
  636. if path[:1] == "/":
  637. path = "." + path
  638. warnings.warn(
  639. "This search is broken in 1.3 and earlier, and will be "
  640. "fixed in a future version. If you rely on the current "
  641. "behaviour, change it to %r" % path,
  642. FutureWarning, stacklevel=2
  643. )
  644. return self._root.findall(path, namespaces)
  645. ##
  646. # Finds all matching subelements, by tag name or path.
  647. # Same as getroot().iterfind(path).
  648. #
  649. # @param path What element to look for.
  650. # @keyparam namespaces Optional namespace prefix map.
  651. # @return An iterator or sequence containing all matching elements,
  652. # in document order.
  653. # @defreturn a generated sequence of Element instances
  654. def iterfind(self, path, namespaces=None):
  655. # assert self._root is not None
  656. if path[:1] == "/":
  657. path = "." + path
  658. warnings.warn(
  659. "This search is broken in 1.3 and earlier, and will be "
  660. "fixed in a future version. If you rely on the current "
  661. "behaviour, change it to %r" % path,
  662. FutureWarning, stacklevel=2
  663. )
  664. return self._root.iterfind(path, namespaces)
  665. ##
  666. # Writes the element tree to a file, as XML.
  667. #
  668. # @def write(file, **options)
  669. # @param file A file name, or a file object opened for writing.
  670. # @param **options Options, given as keyword arguments.
  671. # @keyparam encoding Optional output encoding (default is US-ASCII).
  672. # @keyparam method Optional output method ("xml", "html", "text" or
  673. # "c14n"; default is "xml").
  674. # @keyparam xml_declaration Controls if an XML declaration should
  675. # be added to the file. Use False for never, True for always,
  676. # None for only if not US-ASCII or UTF-8. None is default.
  677. def write(self, file_or_filename,
  678. # keyword arguments
  679. encoding=None,
  680. xml_declaration=None,
  681. default_namespace=None,
  682. method=None):
  683. # assert self._root is not None
  684. if not method:
  685. method = "xml"
  686. elif method not in _serialize:
  687. # FIXME: raise an ImportError for c14n if ElementC14N is missing?
  688. raise ValueError("unknown method %r" % method)
  689. if hasattr(file_or_filename, "write"):
  690. file = file_or_filename
  691. else:
  692. file = open(file_or_filename, "wb")
  693. write = file.write
  694. if not encoding:
  695. if method == "c14n":
  696. encoding = "utf-8"
  697. else:
  698. encoding = "us-ascii"
  699. elif xml_declaration or (xml_declaration is None and
  700. encoding not in ("utf-8", "us-ascii")):
  701. if method == "xml":
  702. write("<?xml version='1.0' encoding='%s'?>\n" % encoding)
  703. if method == "text":
  704. _serialize_text(write, self._root, encoding)
  705. else:
  706. qnames, namespaces = _namespaces(
  707. self._root, encoding, default_namespace
  708. )
  709. serialize = _serialize[method]
  710. serialize(write, self._root, encoding, qnames, namespaces)
  711. if file_or_filename is not file:
  712. file.close()
  713. def write_c14n(self, file):
  714. # lxml.etree compatibility. use output method instead
  715. return self.write(file, method="c14n")
  716. # --------------------------------------------------------------------
  717. # serialization support
  718. def _namespaces(elem, encoding, default_namespace=None):
  719. # identify namespaces used in this tree
  720. # maps qnames to *encoded* prefix:local names
  721. qnames = {None: None}
  722. # maps uri:s to prefixes
  723. namespaces = {}
  724. if default_namespace:
  725. namespaces[default_namespace] = ""
  726. def encode(text):
  727. return text.encode(encoding)
  728. def add_qname(qname):
  729. # calculate serialized qname representation
  730. try:
  731. if qname[:1] == "{":
  732. uri, tag = qname[1:].rsplit("}", 1)
  733. prefix = namespaces.get(uri)
  734. if prefix is None:
  735. prefix = _namespace_map.get(uri)
  736. if prefix is None:
  737. prefix = "ns%d" % len(namespaces)
  738. if prefix != "xml":
  739. namespaces[uri] = prefix
  740. if prefix:
  741. qnames[qname] = encode("%s:%s" % (prefix, tag))
  742. else:
  743. qnames[qname] = encode(tag) # default element
  744. else:
  745. if default_namespace:
  746. # FIXME: can this be handled in XML 1.0?
  747. raise ValueError(
  748. "cannot use non-qualified names with "
  749. "default_namespace option"
  750. )
  751. qnames[qname] = encode(qname)
  752. except TypeError:
  753. _raise_serialization_error(qname)
  754. # populate qname and namespaces table
  755. try:
  756. iterate = elem.iter
  757. except AttributeError:
  758. iterate = elem.getiterator # cET compatibility
  759. for elem in iterate():
  760. tag = elem.tag
  761. if isinstance(tag, QName):
  762. if tag.text not in qnames:
  763. add_qname(tag.text)
  764. elif isinstance(tag, basestring):
  765. if tag not in qnames:
  766. add_qname(tag)
  767. elif tag is not None and tag is not Comment and tag is not PI:
  768. _raise_serialization_error(tag)
  769. for key, value in elem.items():
  770. if isinstance(key, QName):
  771. key = key.text
  772. if key not in qnames:
  773. add_qname(key)
  774. if isinstance(value, QName) and value.text not in qnames:
  775. add_qname(value.text)
  776. text = elem.text
  777. if isinstance(text, QName) and text.text not in qnames:
  778. add_qname(text.text)
  779. return qnames, namespaces
  780. def _serialize_xml(write, elem, encoding, qnames, namespaces):
  781. tag = elem.tag
  782. text = elem.text
  783. if tag is Comment:
  784. write("<!--%s-->" % _encode(text, encoding))
  785. elif tag is ProcessingInstruction:
  786. write("<?%s?>" % _encode(text, encoding))
  787. else:
  788. tag = qnames[tag]
  789. if tag is None:
  790. if text:
  791. write(_escape_cdata(text, encoding))
  792. for e in elem:
  793. _serialize_xml(write, e, encoding, qnames, None)
  794. else:
  795. write("<" + tag)
  796. items = elem.items()
  797. if items or namespaces:
  798. if namespaces:
  799. for v, k in sorted(namespaces.items(),
  800. key=lambda x: x[1]): # sort on prefix
  801. if k:
  802. k = ":" + k
  803. write(" xmlns%s=\"%s\"" % (
  804. k.encode(encoding),
  805. _escape_attrib(v, encoding)
  806. ))
  807. for k, v in sorted(items): # lexical order
  808. if isinstance(k, QName):
  809. k = k.text
  810. if isinstance(v, QName):
  811. v = qnames[v.text]
  812. else:
  813. v = _escape_attrib(v, encoding)
  814. write(" %s=\"%s\"" % (qnames[k], v))
  815. if text or len(elem):
  816. write(">")
  817. if text:
  818. write(_escape_cdata(text, encoding))
  819. for e in elem:
  820. _serialize_xml(write, e, encoding, qnames, None)
  821. write("</" + tag + ">")
  822. else:
  823. write(" />")
  824. if elem.tail:
  825. write(_escape_cdata(elem.tail, encoding))
  826. HTML_EMPTY = ("area", "base", "basefont", "br", "col", "frame", "hr",
  827. "img", "input", "isindex", "link", "meta" "param")
  828. try:
  829. HTML_EMPTY = set(HTML_EMPTY)
  830. except NameError:
  831. pass
  832. def _serialize_html(write, elem, encoding, qnames, namespaces):
  833. tag = elem.tag
  834. text = elem.text
  835. if tag is Comment:
  836. write("<!--%s-->" % _escape_cdata(text, encoding))
  837. elif tag is ProcessingInstruction:
  838. write("<?%s?>" % _escape_cdata(text, encoding))
  839. else:
  840. tag = qnames[tag]
  841. if tag is None:
  842. if text:
  843. write(_escape_cdata(text, encoding))
  844. for e in elem:
  845. _serialize_html(write, e, encoding, qnames, None)
  846. else:
  847. write("<" + tag)
  848. items = elem.items()
  849. if items or namespaces:
  850. if namespaces:
  851. for v, k in sorted(namespaces.items(),
  852. key=lambda x: x[1]): # sort on prefix
  853. if k:
  854. k = ":" + k
  855. write(" xmlns%s=\"%s\"" % (
  856. k.encode(encoding),
  857. _escape_attrib(v, encoding)
  858. ))
  859. for k, v in sorted(items): # lexical order
  860. if isinstance(k, QName):
  861. k = k.text
  862. if isinstance(v, QName):
  863. v = qnames[v.text]
  864. else:
  865. v = _escape_attrib_html(v, encoding)
  866. # FIXME: handle boolean attributes
  867. write(" %s=\"%s\"" % (qnames[k], v))
  868. write(">")
  869. tag = tag.lower()
  870. if text:
  871. if tag == "script" or tag == "style":
  872. write(_encode(text, encoding))
  873. else:
  874. write(_escape_cdata(text, encoding))
  875. for e in elem:
  876. _serialize_html(write, e, encoding, qnames, None)
  877. if tag not in HTML_EMPTY:
  878. write("</" + tag + ">")
  879. if elem.tail:
  880. write(_escape_cdata(elem.tail, encoding))
  881. def _serialize_text(write, elem, encoding):
  882. for part in elem.itertext():
  883. write(part.encode(encoding))
  884. if elem.tail:
  885. write(elem.tail.encode(encoding))
  886. _serialize = {
  887. "xml": _serialize_xml,
  888. "html": _serialize_html,
  889. "text": _serialize_text,
  890. # this optional method is imported at the end of the module
  891. # "c14n": _serialize_c14n,
  892. }
  893. ##
  894. # Registers a namespace prefix. The registry is global, and any
  895. # existing mapping for either the given prefix or the namespace URI
  896. # will be removed.
  897. #
  898. # @param prefix Namespace prefix.
  899. # @param uri Namespace uri. Tags and attributes in this namespace
  900. # will be serialized with the given prefix, if at all possible.
  901. # @exception ValueError If the prefix is reserved, or is otherwise
  902. # invalid.
  903. def register_namespace(prefix, uri):
  904. if re.match("ns\d+$", prefix):
  905. raise ValueError("Prefix format reserved for internal use")
  906. for k, v in _namespace_map.items():
  907. if k == uri or v == prefix:
  908. del _namespace_map[k]
  909. _namespace_map[uri] = prefix
  910. _namespace_map = {
  911. # "well-known" namespace prefixes
  912. "http://www.w3.org/XML/1998/namespace": "xml",
  913. "http://www.w3.org/1999/xhtml": "html",
  914. "http://www.w3.org/1999/02/22-rdf-syntax-ns#": "rdf",
  915. "http://schemas.xmlsoap.org/wsdl/": "wsdl",
  916. # xml schema
  917. "http://www.w3.org/2001/XMLSchema": "xs",
  918. "http://www.w3.org/2001/XMLSchema-instance": "xsi",
  919. # dublin core
  920. "http://purl.org/dc/elements/1.1/": "dc",
  921. }
  922. def _raise_serialization_error(text):
  923. raise TypeError(
  924. "cannot serialize %r (type %s)" % (text, type(text).__name__)
  925. )
  926. def _encode(text, encoding):
  927. try:
  928. return text.encode(encoding, "xmlcharrefreplace")
  929. except (TypeError, AttributeError):
  930. _raise_serialization_error(text)
  931. def _escape_cdata(text, encoding):
  932. # escape character data
  933. try:
  934. # it's worth avoiding do-nothing calls for strings that are
  935. # shorter than 500 character, or so. assume that's, by far,
  936. # the most common case in most applications.
  937. if "&" in text:
  938. text = text.replace("&", "&amp;")
  939. if "<" in text:
  940. text = text.replace("<", "&lt;")
  941. if ">" in text:
  942. text = text.replace(">", "&gt;")
  943. return text.encode(encoding, "xmlcharrefreplace")
  944. except (TypeError, AttributeError):
  945. _raise_serialization_error(text)
  946. def _escape_attrib(text, encoding):
  947. # escape attribute value
  948. try:
  949. if "&" in text:
  950. text = text.replace("&", "&amp;")
  951. if "<" in text:
  952. text = text.replace("<", "&lt;")
  953. if ">" in text:
  954. text = text.replace(">", "&gt;")
  955. if "\"" in text:
  956. text = text.replace("\"", "&quot;")
  957. if "\n" in text:
  958. text = text.replace("\n", "&#10;")
  959. return text.encode(encoding, "xmlcharrefreplace")
  960. except (TypeError, AttributeError):
  961. _raise_serialization_error(text)
  962. def _escape_attrib_html(text, encoding):
  963. # escape attribute value
  964. try:
  965. if "&" in text:
  966. text = text.replace("&", "&amp;")
  967. if ">" in text:
  968. text = text.replace(">", "&gt;")
  969. if "\"" in text:
  970. text = text.replace("\"", "&quot;")
  971. return text.encode(encoding, "xmlcharrefreplace")
  972. except (TypeError, AttributeError):
  973. _raise_serialization_error(text)
  974. # --------------------------------------------------------------------
  975. ##
  976. # Generates a string representation of an XML element, including all
  977. # subelements.
  978. #
  979. # @param element An Element instance.
  980. # @keyparam encoding Optional output encoding (default is US-ASCII).
  981. # @keyparam method Optional output method ("xml", "html", "text" or
  982. # "c14n"; default is "xml").
  983. # @return An encoded string containing the XML data.
  984. # @defreturn string
  985. def tostring(element, encoding=None, method=None):
  986. class dummy:
  987. pass
  988. data = []
  989. file = dummy()
  990. file.write = data.append
  991. ElementTree(element).write(file, encoding, method=method)
  992. return "".join(data)
  993. ##
  994. # Generates a string representation of an XML element, including all
  995. # subelements. The string is returned as a sequence of string fragments.
  996. #
  997. # @param element An Element instance.
  998. # @keyparam encoding Optional output encoding (default is US-ASCII).
  999. # @keyparam method Optional output method ("xml", "html", "text" or
  1000. # "c14n"; default is "xml").
  1001. # @return A sequence object containing the XML data.
  1002. # @defreturn sequence
  1003. # @since 1.3
  1004. def tostringlist(element, encoding=None, method=None):
  1005. class dummy:
  1006. pass
  1007. data = []
  1008. file = dummy()
  1009. file.write = data.append
  1010. ElementTree(element).write(file, encoding, method=method)
  1011. # FIXME: merge small fragments into larger parts
  1012. return data
  1013. ##
  1014. # Writes an element tree or element structure to sys.stdout. This
  1015. # function should be used for debugging only.
  1016. # <p>
  1017. # The exact output format is implementation dependent. In this
  1018. # version, it's written as an ordinary XML file.
  1019. #
  1020. # @param elem An element tree or an individual element.
  1021. def dump(elem):
  1022. # debugging
  1023. if not isinstance(elem, ElementTree):
  1024. elem = ElementTree(elem)
  1025. elem.write(sys.stdout)
  1026. tail = elem.getroot().tail
  1027. if not tail or tail[-1] != "\n":
  1028. sys.stdout.write("\n")
  1029. # --------------------------------------------------------------------
  1030. # parsing
  1031. ##
  1032. # Parses an XML document into an element tree.
  1033. #
  1034. # @param source A filename or file object containing XML data.
  1035. # @param parser An optional parser instance. If not given, the
  1036. # standard {@link XMLParser} parser is used.
  1037. # @return An ElementTree instance
  1038. def parse(source, parser=None):
  1039. tree = ElementTree()
  1040. tree.parse(source, parser)
  1041. return tree
  1042. ##
  1043. # Parses an XML document into an element tree incrementally, and reports
  1044. # what's going on to the user.
  1045. #
  1046. # @param source A filename or file object containing XML data.
  1047. # @param events A list of events to report back. If omitted, only "end"
  1048. # events are reported.
  1049. # @param parser An optional parser instance. If not given, the
  1050. # standard {@link XMLParser} parser is used.
  1051. # @return A (event, elem) iterator.
  1052. def iterparse(source, events=None, parser=None):
  1053. if not hasattr(source, "read"):
  1054. source = open(source, "rb")
  1055. if not parser:
  1056. parser = XMLParser(target=TreeBuilder())
  1057. return _IterParseIterator(source, events, parser)
  1058. class _IterParseIterator(object):
  1059. def __init__(self, source, events, parser):
  1060. self._file = source
  1061. self._events = []
  1062. self._index = 0
  1063. self.root = self._root = None
  1064. self._parser = parser
  1065. # wire up the parser for event reporting
  1066. parser = self._parser._parser
  1067. append = self._events.append
  1068. if events is None:
  1069. events = ["end"]
  1070. for event in events:
  1071. if event == "start":
  1072. try:
  1073. parser.ordered_attributes = 1
  1074. parser.specified_attributes = 1
  1075. def handler(tag, attrib_in, event=event, append=append,
  1076. start=self._parser._start_list):
  1077. append((event, start(tag, attrib_in)))
  1078. parser.StartElementHandler = handler
  1079. except AttributeError:
  1080. def handler(tag, attrib_in, event=event, append=append,
  1081. start=self._parser._start):
  1082. append((event, start(tag, attrib_in)))
  1083. parser.StartElementHandler = handler
  1084. elif event == "end":
  1085. def handler(tag, event=event, append=append,
  1086. end=self._parser._end):
  1087. append((event, end(tag)))
  1088. parser.EndElementHandler = handler
  1089. elif event == "start-ns":
  1090. def handler(prefix, uri, event=event, append=append):
  1091. try:
  1092. uri = (uri or "").encode("ascii")
  1093. except UnicodeError:
  1094. pass
  1095. append((event, (prefix or "", uri or "")))
  1096. parser.StartNamespaceDeclHandler = handler
  1097. elif event == "end-ns":
  1098. def handler(prefix, event=event, append=append):
  1099. append((event, None))
  1100. parser.EndNamespaceDeclHandler = handler
  1101. else:
  1102. raise ValueError("unknown event %r" % event)
  1103. def next(self):
  1104. while 1:
  1105. try:
  1106. item = self._events[self._index]
  1107. except IndexError:
  1108. if self._parser is None:
  1109. self.root = self._root
  1110. raise StopIteration
  1111. # load event buffer
  1112. del self._events[:]
  1113. self._index = 0
  1114. data = self._file.read(16384)
  1115. if data:
  1116. self._parser.feed(data)
  1117. else:
  1118. self._root = self._parser.close()
  1119. self._parser = None
  1120. else:
  1121. self._index = self._index + 1
  1122. return item
  1123. def __iter__(self):
  1124. return self
  1125. ##
  1126. # Parses an XML document from a string constant. This function can
  1127. # be used to embed "XML literals" in Python code.
  1128. #
  1129. # @param source A string containing XML data.
  1130. # @param parser An optional parser instance. If not given, the
  1131. # standard {@link XMLParser} parser is used.
  1132. # @return An Element instance.
  1133. # @defreturn Element
  1134. def XML(text, parser=None):
  1135. if not parser:
  1136. parser = XMLParser(target=TreeBuilder())
  1137. parser.feed(text)
  1138. return parser.close()
  1139. ##
  1140. # Parses an XML document from a string constant, and also returns
  1141. # a dictionary which maps from element id:s to elements.
  1142. #
  1143. # @param source A string containing XML data.
  1144. # @param parser An optional parser instance. If not given, the
  1145. # standard {@link XMLParser} parser is used.
  1146. # @return A tuple containing an Element instance and a dictionary.
  1147. # @defreturn (Element, dictionary)
  1148. def XMLID(text, parser=None):
  1149. if not parser:
  1150. parser = XMLParser(target=TreeBuilder())
  1151. parser.feed(text)
  1152. tree = parser.close()
  1153. ids = {}
  1154. for elem in tree.iter():
  1155. id = elem.get("id")
  1156. if id:
  1157. ids[id] = elem
  1158. return tree, ids
  1159. ##
  1160. # Parses an XML document from a string constant. Same as {@link #XML}.
  1161. #
  1162. # @def fromstring(text)
  1163. # @param source A string containing XML data.
  1164. # @return An Element instance.
  1165. # @defreturn Element
  1166. fromstring = XML
  1167. ##
  1168. # Parses an XML document from a sequence of string fragments.
  1169. #
  1170. # @param sequence A list or other sequence containing XML data fragments.
  1171. # @param parser An optional parser instance. If not given, the
  1172. # standard {@link XMLParser} parser is used.
  1173. # @return An Element instance.
  1174. # @defreturn Element
  1175. # @since 1.3
  1176. def fromstringlist(sequence, parser=None):
  1177. if not parser:
  1178. parser = XMLParser(target=TreeBuilder())
  1179. for text in sequence:
  1180. parser.feed(text)
  1181. return parser.close()
  1182. # --------------------------------------------------------------------
  1183. ##
  1184. # Generic element structure builder. This builder converts a sequence
  1185. # of {@link #TreeBuilder.start}, {@link #TreeBuilder.data}, and {@link
  1186. # #TreeBuilder.end} method calls to a well-formed element structure.
  1187. # <p>
  1188. # You can use this class to build an element structure using a custom XML
  1189. # parser, or a parser for some other XML-like format.
  1190. #
  1191. # @param element_factory Optional element factory. This factory
  1192. # is called to create new Element instances, as necessary.
  1193. class TreeBuilder(object):
  1194. def __init__(self, element_factory=None):
  1195. self._data = [] # data collector
  1196. self._elem = [] # element stack
  1197. self._last = None # last element
  1198. self._tail = None # true if we're after an end tag
  1199. if element_factory is None:
  1200. element_factory = Element
  1201. self._factory = element_factory
  1202. ##
  1203. # Flushes the builder buffers, and returns the toplevel document
  1204. # element.
  1205. #
  1206. # @return An Element instance.
  1207. # @defreturn Element
  1208. def close(self):
  1209. assert len(self._elem) == 0, "missing end tags"
  1210. assert self._last is not None, "missing toplevel element"
  1211. return self._last
  1212. def _flush(self):
  1213. if self._data:
  1214. if self._last is not None:
  1215. text = "".join(self._data)
  1216. if self._tail:
  1217. assert self._last.tail is None, "internal error (tail)"
  1218. self._last.tail = text
  1219. else:
  1220. assert self._last.text is None, "internal error (text)"
  1221. self._last.text = text
  1222. self._data = []
  1223. ##
  1224. # Adds text to the current element.
  1225. #
  1226. # @param data A string. This should be either an 8-bit string
  1227. # containing ASCII text, or a Unicode string.
  1228. def data(self, data):
  1229. self._data.append(data)
  1230. ##
  1231. # Opens a new element.
  1232. #
  1233. # @param tag The element name.
  1234. # @param attrib A dictionary containing element attributes.
  1235. # @return The opened element.
  1236. # @defreturn Element
  1237. def start(self, tag, attrs):
  1238. self._flush()
  1239. self._last = elem = self._factory(tag, attrs)
  1240. if self._elem:
  1241. self._elem[-1].append(elem)
  1242. self._elem.append(elem)
  1243. self._tail = 0
  1244. return elem
  1245. ##
  1246. # Closes the current element.
  1247. #
  1248. # @param tag The element name.
  1249. # @return The closed element.
  1250. # @defreturn Element
  1251. def end(self, tag):
  1252. self._flush()
  1253. self._last = self._elem.pop()
  1254. assert self._last.tag == tag,\
  1255. "end tag mismatch (expected %s, got %s)" % (
  1256. self._last.tag, tag)
  1257. self._tail = 1
  1258. return self._last
  1259. ##
  1260. # Element structure builder for XML source data, based on the
  1261. # <b>expat</b> parser.
  1262. #
  1263. # @keyparam target Target object. If omitted, the builder uses an
  1264. # instance of the standard {@link #TreeBuilder} class.
  1265. # @keyparam html Predefine HTML entities. This flag is not supported
  1266. # by the current implementation.
  1267. # @keyparam encoding Optional encoding. If given, the value overrides
  1268. # the encoding specified in the XML file.
  1269. # @see #ElementTree
  1270. # @see #TreeBuilder
  1271. class XMLParser(object):
  1272. def __init__(self, html=0, target=None, encoding=None):
  1273. try:
  1274. from xml.parsers import expat
  1275. except ImportError:
  1276. try:
  1277. import pyexpat as expat
  1278. except ImportError:
  1279. raise ImportError(
  1280. "No module named expat; use SimpleXMLTreeBuilder instead"
  1281. )
  1282. parser = expat.ParserCreate(encoding, "}")
  1283. if target is None:
  1284. target = TreeBuilder()
  1285. # underscored names are provided for compatibility only
  1286. self.parser = self._parser = parser
  1287. self.target = self._target = target
  1288. self._error = expat.error
  1289. self._names = {} # name memo cache
  1290. # callbacks
  1291. parser.DefaultHandlerExpand = self._default
  1292. parser.StartElementHandler = self._start
  1293. parser.EndElementHandler = self._end
  1294. parser.CharacterDataHandler = self._data
  1295. # optional callbacks
  1296. pa

Large files files are truncated, but you can click here to view the full file