B t `7ã @s8dZddlmZddlmZddlmZyddlmZWnFe k r~yddlmZWn e k rxddl mZYnXYnXyddl m Z Wn e k r°ddl m Z YnXyeZWnek rÒeZYnXyeZWnek rôeZYnXddlmZdZd Zd ZGd d „d eƒZGd d„dƒZdd„ZdS)a> Copyright (C) 2012 Martin Blech and individual contributors. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. é)Úexpat)Ú XMLGenerator)ÚAttributesImpl)ÚStringIO)Ú OrderedDict)Ú yaml_evalz Martin Blechz0.2ÚMITc@s eZdZdS)ÚParsingInterruptedN)Ú__name__Ú __module__Ú __qualname__©r r ú;/tmp/pip-unpacked-wheel-cqckmaqz/pyutilib/misc/xmltodict.pyr +sr c@sHeZdZddd„dddddfd d „Zd d „Zd d„Zdd„Zdd„ZdS)Ú_DictSAXHandlerrcGsdS)NTr )Úargsr r rÚ3óz_DictSAXHandler.Tú@z#textFÚcCsFg|_g|_d|_d|_||_||_||_||_||_||_ ||_ dS)N) ÚpathÚstackÚdataÚitemÚ item_depthÚ xml_attribsÚ item_callbackÚ attr_prefixÚ cdata_keyÚ force_cdataÚcdata_separator)Úselfrrrrrrrr r rÚ__init__1sz_DictSAXHandler.__init__cslˆj ||pdf¡tˆjƒˆjkrhˆj ˆjˆjf¡t‡fdd„| ¡Dƒƒ}ˆj r\|p^dˆ_dˆ_dS)Nc3s$|]\}}ˆj|t|ƒfVqdS)N)rr)Ú.0ÚkeyÚvalue)r r rú Isz/_DictSAXHandler.startElement..) rÚappendÚlenrrrrrÚitemsr)r ÚnameÚattrsr )r rÚ startElementEs z_DictSAXHandler.startElementcCsÊt|jƒ|jkr<|j}|dkr$|j}| |j|¡}|s>> doc = xmltodict.parse(""" ... ... 1 ... 2 ... ... """) >>> doc['a']['@prop'] u'x' >>> doc['a']['b'] [u'1', u'2'] If `item_depth` is `0`, the function returns a dictionary for the root element (default behavior). Otherwise, it calls `item_callback` every time an item at the specified depth is found and returns `None` in the end (streaming mode). The callback function receives two parameters: the `path` from the document root to the item (name-attribs pairs), and the `item` (dict). If the callback's return value is false-ish, parsing will be stopped with the :class:`ParsingInterrupted` exception. Streaming example:: >>> def handle(path, item): ... print 'path:%s item:%s' % (path, item) ... return True ... >>> xmltodict.parse(""" ... ... 1 ... 2 ... """, item_depth=2, item_callback=handle) path:[(u'a', {u'prop': u'x'}), (u'b', None)] item:1 path:[(u'a', {u'prop': u'x'}), (u'b', None)] item:2 ÚreadT) rrÚ ParserCreater+ÚStartElementHandlerr.ÚEndElementHandlerr0ÚCharacterDataHandlerÚhasattrÚ ParseFileÚParser)Z xml_inputrÚkwargsÚhandlerÚparserr r rÚparseys/    r?N)Ú__doc__Z xml.parsersrÚxml.sax.saxutilsrZxml.sax.xmlreaderrÚ cStringIOrÚ ImportErrorÚioÚ collectionsrZ ordereddictÚ basestringZ _basestringÚ NameErrorÚstrÚunicodeZ_unicodeZpyutilib.misc.pyyaml_utilrÚ __author__Ú __version__Ú __license__Ú Exceptionr rr?r r r rÚ s:      J