pax_global_header00006660000000000000000000000064142600500600014503gustar00rootroot0000000000000052 comment=e988ee2ce3cb296308ef0d1442c74bd4b17b3b1b untangle-1.2.1/000077500000000000000000000000001426005006000133215ustar00rootroot00000000000000untangle-1.2.1/.flake8000066400000000000000000000001231426005006000144700ustar00rootroot00000000000000[flake8] exclude = .git,__pycache__,docs/conf.py,old,build,dist,.tox ignore = E501 untangle-1.2.1/.github/000077500000000000000000000000001426005006000146615ustar00rootroot00000000000000untangle-1.2.1/.github/FUNDING.yml000066400000000000000000000000431426005006000164730ustar00rootroot00000000000000github: stchris liberapay: stchris untangle-1.2.1/.github/dependabot.yml000066400000000000000000000007651426005006000175210ustar00rootroot00000000000000# To get started with Dependabot version updates, you'll need to specify which # package ecosystems to update and where the package manifests are located. # Please see the documentation for all configuration options: # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates version: 2 updates: - package-ecosystem: "pip" # See documentation for possible values directory: "/" # Location of package manifests schedule: interval: "daily" untangle-1.2.1/.github/workflows/000077500000000000000000000000001426005006000167165ustar00rootroot00000000000000untangle-1.2.1/.github/workflows/build.yml000066400000000000000000000030641426005006000205430ustar00rootroot00000000000000name: build on: push jobs: test: name: Test Python ${{ matrix.python-version }} (${{ matrix.os }}) strategy: matrix: python-version: ["3.7", "3.8", "3.9", "3.10"] os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v3 with: python-version: ${{ matrix.python-version }} - name: Install dependencies run: make setup - name: Lint run: make lint - name: Run tests run: make test release: name: Release needs: test runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v3 with: python-version: "3.10" - name: Install requirements run: python -m pip install wheel setuptools build - name: Build a distribution run: python -m build - name: Publish package to TestPyPI uses: pypa/gh-action-pypi-publish@master with: user: __token__ password: ${{ secrets.TEST_PYPI_API_TOKEN }} repository_url: https://test.pypi.org/legacy/ skip_existing: true - name: Publish package to PyPI uses: pypa/gh-action-pypi-publish@master if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') with: user: __token__ password: ${{ secrets.PYPI_API_TOKEN }} untangle-1.2.1/.gitignore000066400000000000000000000002061426005006000153070ustar00rootroot00000000000000build/** dist/** deb_dist/** debian/** **/*.pyc *.pyc *.DS_Store MANIFEST untangle.egg-info .tox/ tox.init untangle-*.tar.gz .cache/* untangle-1.2.1/AUTHORS000066400000000000000000000003161426005006000143710ustar00rootroot00000000000000Christian Stefanescu # Contributions from: Florian Idelberger Apalala Reverb Chu Henrikki Tenkanen untangle-1.2.1/CHANGELOG.md000066400000000000000000000033771426005006000151440ustar00rootroot00000000000000Changelog --------- Unreleased 1.2.1 - (SECURITY) Use [defusedxml](https://github.com/tiran/defusedxml) to prevent XML SAX vulnerabilities ([#94](https://github.com/stchris/untangle/pull/94)) 1.2.0 - (SECURITY) Prevent XML SAX vulnerability: External Entities injection ([#60](https://github.com/stchris/untangle/issues/60)) - support for python keywords as element names ([#43](https://github.com/stchris/untangle/pull/43)) - support Element truthiness on Python 3 ([#68](https://github.com/stchris/untangle/pull/68/)) - dropped support for Python 3.4-3.6 and pypy, untangle currently support Python 3.7-3.10 - fixed setup.py warning ([#77](https://github.com/stchris/untangle/pull/77/)) - dropped support for Python 2.6, 3.3 - formatted code with black - flake8 linter enforced in CI - `main` is now the default branch - switch to Github Actions - switch to poetry and pytest 1.1.1 - added generic SAX feature toggle ([#26](https://github.com/stchris/untangle/pull/26)) - added support for `hasattribute`/`getattribute` ([#15](https://github.com/stchris/untangle/pull/15)) - added support for `len()` on parsed objects ([https://github.com/stchris/untangle/commit/31f3078]()) - fixed a potential bug when trying to detect URLs ([https://github.com/stchris/untangle/commit/cfa11d16]()) - include CDATA in `str` representation ([https://github.com/stchris/untangle/commit/63aaa]()) - added support for parsing file-like objects ([#9](https://github.com/stchris/untangle/issues/9)) - dropped support for Python 3.2 (untangle now supports Python versions 2.6, 2.7, 3.3, 3.4, 3.5, 3.6 and pypy) - improved unit test coverage and quality - better documentation and examples for accessing cdata 1.1.0 - __dir__ support for untangled objects - code cleanups 1.0.0 - first official release untangle-1.2.1/LICENSE000066400000000000000000000020471426005006000143310ustar00rootroot00000000000000 Copyright (c) 2011 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. untangle-1.2.1/MANIFEST.in000066400000000000000000000000221426005006000150510ustar00rootroot00000000000000include README.md untangle-1.2.1/Makefile000066400000000000000000000006201426005006000147570ustar00rootroot00000000000000 .DEFAULT_GOAL=compile compile: python -m compileall -q untangle.py tests/tests.py setup: python -m pip install poetry poetry install lint: poetry run flake8 . poetry run black --check . test: poetry run pytest -v # needs python-stdeb package_deb: python setup.py --command-packages=stdeb.command bdist_deb clean: rm -rf deb_dist/ rm -rf debian/ rm -rf dist/ rm -f untangle-*.tar.gz untangle-1.2.1/README.md000066400000000000000000000036451426005006000146100ustar00rootroot00000000000000untangle ======== [![Build Status](https://github.com/stchris/untangle/actions/workflows/build.yml/badge.svg)](https://github.com/stchris/untangle/actions) [![PyPi version](https://img.shields.io/pypi/v/untangle.svg)](https://pypi.python.org/pypi/untangle) Code style: black [Documentation](http://readthedocs.org/docs/untangle/en/latest/) * Converts XML to a Python object. * Siblings with similar names are grouped into a list. * Children can be accessed with ``parent.child``, attributes with ``element['attribute']``. * You can call the ``parse()`` method with a filename, an URL or an XML string. * Substitutes ``-``, ``.`` and ``:`` with ``_`` ```` can be accessed with ``foobar.foo_bar``, ```` can be accessed with ``foo_bar_baz`` and ```` can be accessed with ``foo_bar.foo_baz`` * Works with Python 3.7 - 3.10 Installation ------------ With pip: ``` pip install untangle ``` With conda: ``` conda install -c conda-forge untangle ``` Conda feedstock maintained by @htenkanen. Issues and questions about conda-forge packaging / installation can be done [here](https://github.com/conda-forge/untangle-feedstock/issues). Usage ----- (See and run examples.py or this blog post: [Read XML painlessly](http://pythonadventures.wordpress.com/2011/10/30/read-xml-painlessly/) for more info) ```python import untangle obj = untangle.parse(resource) ``` ``resource`` can be: * a URL * a filename * an XML string Running the above code and passing this XML: ```xml ``` allows it to be navigated from the ``untangle``d object like this: ```python obj.root.child['name'] # u'child1' ``` Changelog --------- see CHANGELOG.md untangle-1.2.1/docs/000077500000000000000000000000001426005006000142515ustar00rootroot00000000000000untangle-1.2.1/docs/Makefile000066400000000000000000000127041426005006000157150ustar00rootroot00000000000000# Makefile for Sphinx documentation # # You can set these variables from the command line. SPHINXOPTS = SPHINXBUILD = sphinx-build PAPER = BUILDDIR = _build # Internal variables. PAPEROPT_a4 = -D latex_paper_size=a4 PAPEROPT_letter = -D latex_paper_size=letter ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . # the i18n builder cannot share the environment and doctrees with the others I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext help: @echo "Please use \`make ' where is one of" @echo " html to make standalone HTML files" @echo " dirhtml to make HTML files named index.html in directories" @echo " singlehtml to make a single large HTML file" @echo " pickle to make pickle files" @echo " json to make JSON files" @echo " htmlhelp to make HTML files and a HTML help project" @echo " qthelp to make HTML files and a qthelp project" @echo " devhelp to make HTML files and a Devhelp project" @echo " epub to make an epub" @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" @echo " latexpdf to make LaTeX files and run them through pdflatex" @echo " text to make text files" @echo " man to make manual pages" @echo " texinfo to make Texinfo files" @echo " info to make Texinfo files and run them through makeinfo" @echo " gettext to make PO message catalogs" @echo " changes to make an overview of all changed/added/deprecated items" @echo " linkcheck to check all external links for integrity" @echo " doctest to run all doctests embedded in the documentation (if enabled)" clean: -rm -rf $(BUILDDIR)/* html: $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." dirhtml: $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." singlehtml: $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml @echo @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." pickle: $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle @echo @echo "Build finished; now you can process the pickle files." json: $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json @echo @echo "Build finished; now you can process the JSON files." htmlhelp: $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp @echo @echo "Build finished; now you can run HTML Help Workshop with the" \ ".hhp project file in $(BUILDDIR)/htmlhelp." qthelp: $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp @echo @echo "Build finished; now you can run "qcollectiongenerator" with the" \ ".qhcp project file in $(BUILDDIR)/qthelp, like this:" @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/untangle.qhcp" @echo "To view the help file:" @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/untangle.qhc" devhelp: $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp @echo @echo "Build finished." @echo "To view the help file:" @echo "# mkdir -p $$HOME/.local/share/devhelp/untangle" @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/untangle" @echo "# devhelp" epub: $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub @echo @echo "Build finished. The epub file is in $(BUILDDIR)/epub." latex: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." @echo "Run \`make' in that directory to run these through (pdf)latex" \ "(use \`make latexpdf' here to do that automatically)." latexpdf: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo "Running LaTeX files through pdflatex..." $(MAKE) -C $(BUILDDIR)/latex all-pdf @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." text: $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text @echo @echo "Build finished. The text files are in $(BUILDDIR)/text." man: $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man @echo @echo "Build finished. The manual pages are in $(BUILDDIR)/man." texinfo: $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo @echo @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." @echo "Run \`make' in that directory to run these through makeinfo" \ "(use \`make info' here to do that automatically)." info: $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo @echo "Running Texinfo files through makeinfo..." make -C $(BUILDDIR)/texinfo info @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." gettext: $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale @echo @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." changes: $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes @echo @echo "The overview file is in $(BUILDDIR)/changes." linkcheck: $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck @echo @echo "Link check complete; look for any errors in the above output " \ "or in $(BUILDDIR)/linkcheck/output.txt." doctest: $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest @echo "Testing of doctests in the sources finished, look at the " \ "results in $(BUILDDIR)/doctest/output.txt." untangle-1.2.1/docs/conf.py000066400000000000000000000174561426005006000155650ustar00rootroot00000000000000# -*- coding: utf-8 -*- # # untangle documentation build configuration file, created by # sphinx-quickstart on Fri Apr 6 16:05:20 2012. # # This file is execfile()d with the current directory set to its containing dir. # # Note that not all possible configuration values are present in this # autogenerated file. # # All configuration values have a default; values that are commented out # serve to show the default. import sys, os # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. sys.path.insert(0, os.path.abspath("..")) import untangle # -- General configuration ----------------------------------------------------- # If your documentation needs a minimal Sphinx version, state it here. # needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. extensions = ["sphinx.ext.autodoc"] # Add any paths that contain templates here, relative to this directory. templates_path = ["_templates"] # The suffix of source filenames. source_suffix = ".rst" # The encoding of source files. # source_encoding = 'utf-8-sig' # The master toctree document. master_doc = "index" # General information about the project. project = "untangle" copyright = "2012, Christian Stefanescu" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. version = untangle.__version__ # The full version, including alpha/beta/rc tags. release = untangle.__version__ # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. # language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: # today = '' # Else, today_fmt is used as the format for a strftime call. # today_fmt = '%B %d, %Y' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. exclude_patterns = ["_build"] # The reST default role (used for this markup: `text`) to use for all documents. # default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. # add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). # add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. # show_authors = False # The name of the Pygments (syntax highlighting) style to use. pygments_style = "sphinx" # A list of ignored prefixes for module index sorting. # modindex_common_prefix = [] # -- Options for HTML output --------------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. html_theme = "default" # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. # html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. # html_theme_path = [] # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". # html_title = None # A shorter title for the navigation bar. Default is the same as html_title. # html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. # html_logo = None # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. # html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ["_static"] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. # html_last_updated_fmt = '%b %d, %Y' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. # html_use_smartypants = True # Custom sidebar templates, maps document names to template names. # html_sidebars = {} # Additional templates that should be rendered to pages, maps page names to # template names. # html_additional_pages = {} # If false, no module index is generated. # html_domain_indices = True # If false, no index is generated. # html_use_index = True # If true, the index is split into individual pages for each letter. # html_split_index = False # If true, links to the reST sources are added to the pages. # html_show_sourcelink = True # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. # html_show_sphinx = True # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. # html_show_copyright = True # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. # html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). # html_file_suffix = None # Output file base name for HTML help builder. htmlhelp_basename = "untangledoc" # -- Options for LaTeX output -------------------------------------------------- latex_elements = { # The paper size ('letterpaper' or 'a4paper'). #'papersize': 'letterpaper', # The font size ('10pt', '11pt' or '12pt'). #'pointsize': '10pt', # Additional stuff for the LaTeX preamble. #'preamble': '', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, documentclass [howto/manual]). latex_documents = [ ( "index", "untangle.tex", "untangle Documentation", "Christian Stefanescu", "manual", ), ] # The name of an image file (relative to this directory) to place at the top of # the title page. # latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. # latex_use_parts = False # If true, show page references after internal links. # latex_show_pagerefs = False # If true, show URL addresses after external links. # latex_show_urls = False # Documents to append as an appendix to all manuals. # latex_appendices = [] # If false, no module index is generated. # latex_domain_indices = True # -- Options for manual page output -------------------------------------------- # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ ("index", "untangle", "untangle Documentation", ["Christian Stefanescu"], 1) ] # If true, show URL addresses after external links. # man_show_urls = False # -- Options for Texinfo output ------------------------------------------------ # Grouping the document tree into Texinfo files. List of tuples # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ ( "index", "untangle", "untangle Documentation", "Christian Stefanescu", "untangle", "One line description of project.", "Miscellaneous", ), ] # Documents to append as an appendix to all manuals. # texinfo_appendices = [] # If false, no module index is generated. # texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. # texinfo_show_urls = 'footnote' untangle-1.2.1/docs/index.rst000066400000000000000000000072241426005006000161170ustar00rootroot00000000000000.. untangle documentation master file, created by sphinx-quickstart on Fri Apr 6 16:05:20 2012. You can adapt this file completely to your liking, but it should at least contain the root `toctree` directive. untangle: Convert XML to Python objects ======================================= `untangle `_ is a tiny Python library which converts an XML document to a Python object. It is available under the `MIT license `_. .. contents:: Usage ----- .. module:: untangle untangle has a very simple API. You just need to call the parse function to get back a Python object. The parameter can be: * a string * a filename * a URL .. autofunction:: parse If you are looking for information on a specific function, class or method, this part of the documentation is for you. The object you get back represents the complete XML document. Child elements can be accessed with ``parent.child``, attributes with ``element['attribute']``. Siblings with similar names are grouped into a list. Example ------- Considering this XML document: :: and assuming it's available in a variable called `xml`, we could use untangle like this: :: doc = untangle.parse(xml) child_name = doc.root.child['name'] # 'child1' For text/data inbetween tags, this is described as cdata. After specifying the relevant element as explained above, the data/cdata can be accessed by adding ".cdata" (without the quotes) to the end of your dictionary call. For more examples, have a look at (and launch) `examples.py `_. Installation ------------ :: pip install untangle Alternatively, you can install untangle with conda from conda-forge: :: conda install -c conda-forge untangle Motivation ---------- untangle is available for that use case, where you have a 20-line XML file you got back from an API and you just need to extract some values out of it. You might not want to use regular expressions, but just as well you might not want to install a complex libxml2-based solution (and look up its terse API). Performance and memory usage might be bad, but these tradeoffs were made in order to allow a simple API and no external dependencies. See also: Limitations_. Limitations ----------- untangle trades features for a simple API, which is why untangle substitutes ``-``, ``.`` and ``:`` with ``_``: * ```` can be accessed with ``foobar.foo_bar`` * ```` can be accessed with ``foo_bar_baz`` * ```` can be accessed with ``foo_bar.foo_baz`` Encoding --------- Be aware that with certain characters or maybe also depending on the python version you might get an error on accessing specific attributes, such as ``UnicodeEncodeError: 'ascii' codec can't encode character u'\xfc' in position 385: ordinal not in range(128)`` In most cases it should be enough to import the sys module, and set utf-8 as encoding, with: :: import sys reload(sys) # just to be sure sys.setdefaultencoding('utf-8') SAX features ------------ It is possible to pass specific SAX features to the handler used by untangle, for instance: :: untangle.parse(my_xml, feature_external_ges=False) This will toggle the SAX handler feature described `here `_. Changelog --------- see https://github.com/stchris/untangle/blob/main/CHANGELOG.md Indices and tables ================== * :ref:`genindex` * :ref:`modindex` * :ref:`search` untangle-1.2.1/examples.py000077500000000000000000000024601426005006000155160ustar00rootroot00000000000000#!/usr/bin/env python """ Usage examples for untangle """ import untangle def access(): """ Shows basic attribute access and node navigation. """ o = untangle.parse('This is cdata') return "Node id = %s, subnode value = %s" % (o.node["id"], o.node.subnode["value"]) def siblings_list(): """ Shows child element iteration """ o = untangle.parse( """ """ ) return ",".join([child["name"] for child in o.root.child]) def access_cdata(): """ Shows how to handle CDATA elements """ o = untangle.parse('This is cdata') return "%s" % (o.node.cdata) examples = [ ( "Access children with parent.children and" ' attributes with element["attribute"]', access, ), ("Access siblings as list", siblings_list), ("Access cdata text or other data", access_cdata), ] if __name__ == "__main__": for description, func in examples: print("=" * 70) print(description) print("=" * 70) print() print(func()) print() # vim: set expandtab ts=4 sw=4: untangle-1.2.1/poetry.lock000066400000000000000000000547501426005006000155300ustar00rootroot00000000000000[[package]] name = "atomicwrites" version = "1.4.0" description = "Atomic file writes." category = "dev" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" [[package]] name = "attrs" version = "21.4.0" description = "Classes Without Boilerplate" category = "dev" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" [package.extras] dev = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins", "zope.interface", "furo", "sphinx", "sphinx-notfound-page", "pre-commit", "cloudpickle"] docs = ["furo", "sphinx", "zope.interface", "sphinx-notfound-page"] tests = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins", "zope.interface", "cloudpickle"] tests_no_zope = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins", "cloudpickle"] [[package]] name = "black" version = "22.6.0" description = "The uncompromising code formatter." category = "dev" optional = false python-versions = ">=3.6.2" [package.dependencies] click = ">=8.0.0" mypy-extensions = ">=0.4.3" pathspec = ">=0.9.0" platformdirs = ">=2" tomli = {version = ">=1.1.0", markers = "python_full_version < \"3.11.0a7\""} typed-ast = {version = ">=1.4.2", markers = "python_version < \"3.8\" and implementation_name == \"cpython\""} typing-extensions = {version = ">=3.10.0.0", markers = "python_version < \"3.10\""} [package.extras] colorama = ["colorama (>=0.4.3)"] d = ["aiohttp (>=3.7.4)"] jupyter = ["ipython (>=7.8.0)", "tokenize-rt (>=3.2.0)"] uvloop = ["uvloop (>=0.15.2)"] [[package]] name = "build" version = "0.8.0" description = "A simple, correct PEP 517 build frontend" category = "dev" optional = false python-versions = ">=3.6" [package.dependencies] colorama = {version = "*", markers = "os_name == \"nt\""} importlib-metadata = {version = ">=0.22", markers = "python_version < \"3.8\""} packaging = ">=19.0" pep517 = ">=0.9.1" tomli = {version = ">=1.0.0", markers = "python_version < \"3.11\""} [package.extras] docs = ["furo (>=2021.08.31)", "sphinx (>=4.0,<5.0)", "sphinx-argparse-cli (>=1.5)", "sphinx-autodoc-typehints (>=1.10)"] test = ["filelock (>=3)", "pytest (>=6.2.4)", "pytest-cov (>=2.12)", "pytest-mock (>=2)", "pytest-rerunfailures (>=9.1)", "pytest-xdist (>=1.34)", "toml (>=0.10.0)", "wheel (>=0.36.0)", "setuptools (>=42.0.0)", "setuptools (>=56.0.0)"] typing = ["importlib-metadata (>=4.6.4)", "mypy (==0.950)", "typing-extensions (>=3.7.4.3)"] virtualenv = ["virtualenv (>=20.0.35)"] [[package]] name = "click" version = "8.1.3" description = "Composable command line interface toolkit" category = "dev" optional = false python-versions = ">=3.7" [package.dependencies] colorama = {version = "*", markers = "platform_system == \"Windows\""} importlib-metadata = {version = "*", markers = "python_version < \"3.8\""} [[package]] name = "colorama" version = "0.4.5" description = "Cross-platform colored terminal text." category = "dev" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" [[package]] name = "defusedxml" version = "0.7.1" description = "XML bomb protection for Python stdlib modules" category = "main" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" [[package]] name = "flake8" version = "4.0.1" description = "the modular source code checker: pep8 pyflakes and co" category = "dev" optional = false python-versions = ">=3.6" [package.dependencies] importlib-metadata = {version = "<4.3", markers = "python_version < \"3.8\""} mccabe = ">=0.6.0,<0.7.0" pycodestyle = ">=2.8.0,<2.9.0" pyflakes = ">=2.4.0,<2.5.0" [[package]] name = "importlib-metadata" version = "4.2.0" description = "Read metadata from Python packages" category = "dev" optional = false python-versions = ">=3.6" [package.dependencies] typing-extensions = {version = ">=3.6.4", markers = "python_version < \"3.8\""} zipp = ">=0.5" [package.extras] docs = ["sphinx", "jaraco.packaging (>=8.2)", "rst.linker (>=1.9)"] testing = ["pytest (>=4.6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest-cov", "pytest-enabler (>=1.0.1)", "packaging", "pep517", "pyfakefs", "flufl.flake8", "pytest-black (>=0.3.7)", "pytest-mypy", "importlib-resources (>=1.3)"] [[package]] name = "iniconfig" version = "1.1.1" description = "iniconfig: brain-dead simple config-ini parsing" category = "dev" optional = false python-versions = "*" [[package]] name = "mccabe" version = "0.6.1" description = "McCabe checker, plugin for flake8" category = "dev" optional = false python-versions = "*" [[package]] name = "mypy-extensions" version = "0.4.3" description = "Experimental type system extensions for programs checked with the mypy typechecker." category = "dev" optional = false python-versions = "*" [[package]] name = "packaging" version = "21.3" description = "Core utilities for Python packages" category = "dev" optional = false python-versions = ">=3.6" [package.dependencies] pyparsing = ">=2.0.2,<3.0.5 || >3.0.5" [[package]] name = "pathspec" version = "0.9.0" description = "Utility library for gitignore style pattern matching of file paths." category = "dev" optional = false python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7" [[package]] name = "pep517" version = "0.12.0" description = "Wrappers to build Python packages using PEP 517 hooks" category = "dev" optional = false python-versions = "*" [package.dependencies] importlib_metadata = {version = "*", markers = "python_version < \"3.8\""} tomli = {version = ">=1.1.0", markers = "python_version >= \"3.6\""} zipp = {version = "*", markers = "python_version < \"3.8\""} [[package]] name = "platformdirs" version = "2.5.2" description = "A small Python module for determining appropriate platform-specific dirs, e.g. a \"user data dir\"." category = "dev" optional = false python-versions = ">=3.7" [package.extras] docs = ["furo (>=2021.7.5b38)", "proselint (>=0.10.2)", "sphinx-autodoc-typehints (>=1.12)", "sphinx (>=4)"] test = ["appdirs (==1.4.4)", "pytest-cov (>=2.7)", "pytest-mock (>=3.6)", "pytest (>=6)"] [[package]] name = "pluggy" version = "1.0.0" description = "plugin and hook calling mechanisms for python" category = "dev" optional = false python-versions = ">=3.6" [package.dependencies] importlib-metadata = {version = ">=0.12", markers = "python_version < \"3.8\""} [package.extras] dev = ["pre-commit", "tox"] testing = ["pytest", "pytest-benchmark"] [[package]] name = "py" version = "1.11.0" description = "library with cross-python path, ini-parsing, io, code, log facilities" category = "dev" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" [[package]] name = "pycodestyle" version = "2.8.0" description = "Python style guide checker" category = "dev" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" [[package]] name = "pyflakes" version = "2.4.0" description = "passive checker of Python programs" category = "dev" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" [[package]] name = "pyparsing" version = "3.0.9" description = "pyparsing module - Classes and methods to define and execute parsing grammars" category = "dev" optional = false python-versions = ">=3.6.8" [package.extras] diagrams = ["railroad-diagrams", "jinja2"] [[package]] name = "pytest" version = "7.1.2" description = "pytest: simple powerful testing with Python" category = "dev" optional = false python-versions = ">=3.7" [package.dependencies] atomicwrites = {version = ">=1.0", markers = "sys_platform == \"win32\""} attrs = ">=19.2.0" colorama = {version = "*", markers = "sys_platform == \"win32\""} importlib-metadata = {version = ">=0.12", markers = "python_version < \"3.8\""} iniconfig = "*" packaging = "*" pluggy = ">=0.12,<2.0" py = ">=1.8.2" tomli = ">=1.0.0" [package.extras] testing = ["argcomplete", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "xmlschema"] [[package]] name = "tomli" version = "2.0.1" description = "A lil' TOML parser" category = "dev" optional = false python-versions = ">=3.7" [[package]] name = "typed-ast" version = "1.5.4" description = "a fork of Python 2 and 3 ast modules with type comment support" category = "dev" optional = false python-versions = ">=3.6" [[package]] name = "typing-extensions" version = "4.2.0" description = "Backported and Experimental Type Hints for Python 3.7+" category = "dev" optional = false python-versions = ">=3.7" [[package]] name = "zipp" version = "3.8.0" description = "Backport of pathlib-compatible object wrapper for zip files" category = "dev" optional = false python-versions = ">=3.7" [package.extras] docs = ["sphinx", "jaraco.packaging (>=9)", "rst.linker (>=1.9)"] testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest-cov", "pytest-enabler (>=1.0.1)", "jaraco.itertools", "func-timeout", "pytest-black (>=0.3.7)", "pytest-mypy (>=0.9.1)"] [metadata] lock-version = "1.1" python-versions = "^3.7" content-hash = "b27722b23f8379a524e0e979e75811a164f0b50a672c44b764c020e1b7779fc4" [metadata.files] atomicwrites = [ {file = "atomicwrites-1.4.0-py2.py3-none-any.whl", hash = "sha256:6d1784dea7c0c8d4a5172b6c620f40b6e4cbfdf96d783691f2e1302a7b88e197"}, {file = "atomicwrites-1.4.0.tar.gz", hash = "sha256:ae70396ad1a434f9c7046fd2dd196fc04b12f9e91ffb859164193be8b6168a7a"}, ] attrs = [ {file = "attrs-21.4.0-py2.py3-none-any.whl", hash = "sha256:2d27e3784d7a565d36ab851fe94887c5eccd6a463168875832a1be79c82828b4"}, {file = "attrs-21.4.0.tar.gz", hash = "sha256:626ba8234211db98e869df76230a137c4c40a12d72445c45d5f5b716f076e2fd"}, ] black = [ {file = "black-22.6.0-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:f586c26118bc6e714ec58c09df0157fe2d9ee195c764f630eb0d8e7ccce72e69"}, {file = "black-22.6.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:b270a168d69edb8b7ed32c193ef10fd27844e5c60852039599f9184460ce0807"}, {file = "black-22.6.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:6797f58943fceb1c461fb572edbe828d811e719c24e03375fd25170ada53825e"}, {file = "black-22.6.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c85928b9d5f83b23cee7d0efcb310172412fbf7cb9d9ce963bd67fd141781def"}, {file = "black-22.6.0-cp310-cp310-win_amd64.whl", hash = "sha256:f6fe02afde060bbeef044af7996f335fbe90b039ccf3f5eb8f16df8b20f77666"}, {file = "black-22.6.0-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:cfaf3895a9634e882bf9d2363fed5af8888802d670f58b279b0bece00e9a872d"}, {file = "black-22.6.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:94783f636bca89f11eb5d50437e8e17fbc6a929a628d82304c80fa9cd945f256"}, {file = "black-22.6.0-cp36-cp36m-win_amd64.whl", hash = "sha256:2ea29072e954a4d55a2ff58971b83365eba5d3d357352a07a7a4df0d95f51c78"}, {file = "black-22.6.0-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:e439798f819d49ba1c0bd9664427a05aab79bfba777a6db94fd4e56fae0cb849"}, {file = "black-22.6.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:187d96c5e713f441a5829e77120c269b6514418f4513a390b0499b0987f2ff1c"}, {file = "black-22.6.0-cp37-cp37m-win_amd64.whl", hash = "sha256:074458dc2f6e0d3dab7928d4417bb6957bb834434516f21514138437accdbe90"}, {file = "black-22.6.0-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:a218d7e5856f91d20f04e931b6f16d15356db1c846ee55f01bac297a705ca24f"}, {file = "black-22.6.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:568ac3c465b1c8b34b61cd7a4e349e93f91abf0f9371eda1cf87194663ab684e"}, {file = "black-22.6.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:6c1734ab264b8f7929cef8ae5f900b85d579e6cbfde09d7387da8f04771b51c6"}, {file = "black-22.6.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c9a3ac16efe9ec7d7381ddebcc022119794872abce99475345c5a61aa18c45ad"}, {file = "black-22.6.0-cp38-cp38-win_amd64.whl", hash = "sha256:b9fd45787ba8aa3f5e0a0a98920c1012c884622c6c920dbe98dbd05bc7c70fbf"}, {file = "black-22.6.0-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:7ba9be198ecca5031cd78745780d65a3f75a34b2ff9be5837045dce55db83d1c"}, {file = "black-22.6.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:a3db5b6409b96d9bd543323b23ef32a1a2b06416d525d27e0f67e74f1446c8f2"}, {file = "black-22.6.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:560558527e52ce8afba936fcce93a7411ab40c7d5fe8c2463e279e843c0328ee"}, {file = "black-22.6.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b154e6bbde1e79ea3260c4b40c0b7b3109ffcdf7bc4ebf8859169a6af72cd70b"}, {file = "black-22.6.0-cp39-cp39-win_amd64.whl", hash = "sha256:4af5bc0e1f96be5ae9bd7aaec219c901a94d6caa2484c21983d043371c733fc4"}, {file = "black-22.6.0-py3-none-any.whl", hash = "sha256:ac609cf8ef5e7115ddd07d85d988d074ed00e10fbc3445aee393e70164a2219c"}, {file = "black-22.6.0.tar.gz", hash = "sha256:6c6d39e28aed379aec40da1c65434c77d75e65bb59a1e1c283de545fb4e7c6c9"}, ] build = [ {file = "build-0.8.0-py3-none-any.whl", hash = "sha256:19b0ed489f92ace6947698c3ca8436cb0556a66e2aa2d34cd70e2a5d27cd0437"}, {file = "build-0.8.0.tar.gz", hash = "sha256:887a6d471c901b1a6e6574ebaeeebb45e5269a79d095fe9a8f88d6614ed2e5f0"}, ] click = [ {file = "click-8.1.3-py3-none-any.whl", hash = "sha256:bb4d8133cb15a609f44e8213d9b391b0809795062913b383c62be0ee95b1db48"}, {file = "click-8.1.3.tar.gz", hash = "sha256:7682dc8afb30297001674575ea00d1814d808d6a36af415a82bd481d37ba7b8e"}, ] colorama = [ {file = "colorama-0.4.5-py2.py3-none-any.whl", hash = "sha256:854bf444933e37f5824ae7bfc1e98d5bce2ebe4160d46b5edf346a89358e99da"}, {file = "colorama-0.4.5.tar.gz", hash = "sha256:e6c6b4334fc50988a639d9b98aa429a0b57da6e17b9a44f0451f930b6967b7a4"}, ] defusedxml = [ {file = "defusedxml-0.7.1-py2.py3-none-any.whl", hash = "sha256:a352e7e428770286cc899e2542b6cdaedb2b4953ff269a210103ec58f6198a61"}, {file = "defusedxml-0.7.1.tar.gz", hash = "sha256:1bb3032db185915b62d7c6209c5a8792be6a32ab2fedacc84e01b52c51aa3e69"}, ] flake8 = [ {file = "flake8-4.0.1-py2.py3-none-any.whl", hash = "sha256:479b1304f72536a55948cb40a32dce8bb0ffe3501e26eaf292c7e60eb5e0428d"}, {file = "flake8-4.0.1.tar.gz", hash = "sha256:806e034dda44114815e23c16ef92f95c91e4c71100ff52813adf7132a6ad870d"}, ] importlib-metadata = [ {file = "importlib_metadata-4.2.0-py3-none-any.whl", hash = "sha256:057e92c15bc8d9e8109738a48db0ccb31b4d9d5cfbee5a8670879a30be66304b"}, {file = "importlib_metadata-4.2.0.tar.gz", hash = "sha256:b7e52a1f8dec14a75ea73e0891f3060099ca1d8e6a462a4dff11c3e119ea1b31"}, ] iniconfig = [ {file = "iniconfig-1.1.1-py2.py3-none-any.whl", hash = "sha256:011e24c64b7f47f6ebd835bb12a743f2fbe9a26d4cecaa7f53bc4f35ee9da8b3"}, {file = "iniconfig-1.1.1.tar.gz", hash = "sha256:bc3af051d7d14b2ee5ef9969666def0cd1a000e121eaea580d4a313df4b37f32"}, ] mccabe = [ {file = "mccabe-0.6.1-py2.py3-none-any.whl", hash = "sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42"}, {file = "mccabe-0.6.1.tar.gz", hash = "sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f"}, ] mypy-extensions = [ {file = "mypy_extensions-0.4.3-py2.py3-none-any.whl", hash = "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d"}, {file = "mypy_extensions-0.4.3.tar.gz", hash = "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8"}, ] packaging = [ {file = "packaging-21.3-py3-none-any.whl", hash = "sha256:ef103e05f519cdc783ae24ea4e2e0f508a9c99b2d4969652eed6a2e1ea5bd522"}, {file = "packaging-21.3.tar.gz", hash = "sha256:dd47c42927d89ab911e606518907cc2d3a1f38bbd026385970643f9c5b8ecfeb"}, ] pathspec = [ {file = "pathspec-0.9.0-py2.py3-none-any.whl", hash = "sha256:7d15c4ddb0b5c802d161efc417ec1a2558ea2653c2e8ad9c19098201dc1c993a"}, {file = "pathspec-0.9.0.tar.gz", hash = "sha256:e564499435a2673d586f6b2130bb5b95f04a3ba06f81b8f895b651a3c76aabb1"}, ] pep517 = [ {file = "pep517-0.12.0-py2.py3-none-any.whl", hash = "sha256:dd884c326898e2c6e11f9e0b64940606a93eb10ea022a2e067959f3a110cf161"}, {file = "pep517-0.12.0.tar.gz", hash = "sha256:931378d93d11b298cf511dd634cf5ea4cb249a28ef84160b3247ee9afb4e8ab0"}, ] platformdirs = [ {file = "platformdirs-2.5.2-py3-none-any.whl", hash = "sha256:027d8e83a2d7de06bbac4e5ef7e023c02b863d7ea5d079477e722bb41ab25788"}, {file = "platformdirs-2.5.2.tar.gz", hash = "sha256:58c8abb07dcb441e6ee4b11d8df0ac856038f944ab98b7be6b27b2a3c7feef19"}, ] pluggy = [ {file = "pluggy-1.0.0-py2.py3-none-any.whl", hash = "sha256:74134bbf457f031a36d68416e1509f34bd5ccc019f0bcc952c7b909d06b37bd3"}, {file = "pluggy-1.0.0.tar.gz", hash = "sha256:4224373bacce55f955a878bf9cfa763c1e360858e330072059e10bad68531159"}, ] py = [ {file = "py-1.11.0-py2.py3-none-any.whl", hash = "sha256:607c53218732647dff4acdfcd50cb62615cedf612e72d1724fb1a0cc6405b378"}, {file = "py-1.11.0.tar.gz", hash = "sha256:51c75c4126074b472f746a24399ad32f6053d1b34b68d2fa41e558e6f4a98719"}, ] pycodestyle = [ {file = "pycodestyle-2.8.0-py2.py3-none-any.whl", hash = "sha256:720f8b39dde8b293825e7ff02c475f3077124006db4f440dcbc9a20b76548a20"}, {file = "pycodestyle-2.8.0.tar.gz", hash = "sha256:eddd5847ef438ea1c7870ca7eb78a9d47ce0cdb4851a5523949f2601d0cbbe7f"}, ] pyflakes = [ {file = "pyflakes-2.4.0-py2.py3-none-any.whl", hash = "sha256:3bb3a3f256f4b7968c9c788781e4ff07dce46bdf12339dcda61053375426ee2e"}, {file = "pyflakes-2.4.0.tar.gz", hash = "sha256:05a85c2872edf37a4ed30b0cce2f6093e1d0581f8c19d7393122da7e25b2b24c"}, ] pyparsing = [ {file = "pyparsing-3.0.9-py3-none-any.whl", hash = "sha256:5026bae9a10eeaefb61dab2f09052b9f4307d44aee4eda64b309723d8d206bbc"}, {file = "pyparsing-3.0.9.tar.gz", hash = "sha256:2b020ecf7d21b687f219b71ecad3631f644a47f01403fa1d1036b0c6416d70fb"}, ] pytest = [ {file = "pytest-7.1.2-py3-none-any.whl", hash = "sha256:13d0e3ccfc2b6e26be000cb6568c832ba67ba32e719443bfe725814d3c42433c"}, {file = "pytest-7.1.2.tar.gz", hash = "sha256:a06a0425453864a270bc45e71f783330a7428defb4230fb5e6a731fde06ecd45"}, ] tomli = [ {file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"}, {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, ] typed-ast = [ {file = "typed_ast-1.5.4-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:669dd0c4167f6f2cd9f57041e03c3c2ebf9063d0757dc89f79ba1daa2bfca9d4"}, {file = "typed_ast-1.5.4-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:211260621ab1cd7324e0798d6be953d00b74e0428382991adfddb352252f1d62"}, {file = "typed_ast-1.5.4-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:267e3f78697a6c00c689c03db4876dd1efdfea2f251a5ad6555e82a26847b4ac"}, {file = "typed_ast-1.5.4-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:c542eeda69212fa10a7ada75e668876fdec5f856cd3d06829e6aa64ad17c8dfe"}, {file = "typed_ast-1.5.4-cp310-cp310-win_amd64.whl", hash = "sha256:a9916d2bb8865f973824fb47436fa45e1ebf2efd920f2b9f99342cb7fab93f72"}, {file = "typed_ast-1.5.4-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:79b1e0869db7c830ba6a981d58711c88b6677506e648496b1f64ac7d15633aec"}, {file = "typed_ast-1.5.4-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a94d55d142c9265f4ea46fab70977a1944ecae359ae867397757d836ea5a3f47"}, {file = "typed_ast-1.5.4-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:183afdf0ec5b1b211724dfef3d2cad2d767cbefac291f24d69b00546c1837fb6"}, {file = "typed_ast-1.5.4-cp36-cp36m-win_amd64.whl", hash = "sha256:639c5f0b21776605dd6c9dbe592d5228f021404dafd377e2b7ac046b0349b1a1"}, {file = "typed_ast-1.5.4-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:cf4afcfac006ece570e32d6fa90ab74a17245b83dfd6655a6f68568098345ff6"}, {file = "typed_ast-1.5.4-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ed855bbe3eb3715fca349c80174cfcfd699c2f9de574d40527b8429acae23a66"}, {file = "typed_ast-1.5.4-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:6778e1b2f81dfc7bc58e4b259363b83d2e509a65198e85d5700dfae4c6c8ff1c"}, {file = "typed_ast-1.5.4-cp37-cp37m-win_amd64.whl", hash = "sha256:0261195c2062caf107831e92a76764c81227dae162c4f75192c0d489faf751a2"}, {file = "typed_ast-1.5.4-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:2efae9db7a8c05ad5547d522e7dbe62c83d838d3906a3716d1478b6c1d61388d"}, {file = "typed_ast-1.5.4-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:7d5d014b7daa8b0bf2eaef684295acae12b036d79f54178b92a2b6a56f92278f"}, {file = "typed_ast-1.5.4-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:370788a63915e82fd6f212865a596a0fefcbb7d408bbbb13dea723d971ed8bdc"}, {file = "typed_ast-1.5.4-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:4e964b4ff86550a7a7d56345c7864b18f403f5bd7380edf44a3c1fb4ee7ac6c6"}, {file = "typed_ast-1.5.4-cp38-cp38-win_amd64.whl", hash = "sha256:683407d92dc953c8a7347119596f0b0e6c55eb98ebebd9b23437501b28dcbb8e"}, {file = "typed_ast-1.5.4-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:4879da6c9b73443f97e731b617184a596ac1235fe91f98d279a7af36c796da35"}, {file = "typed_ast-1.5.4-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:3e123d878ba170397916557d31c8f589951e353cc95fb7f24f6bb69adc1a8a97"}, {file = "typed_ast-1.5.4-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ebd9d7f80ccf7a82ac5f88c521115cc55d84e35bf8b446fcd7836eb6b98929a3"}, {file = "typed_ast-1.5.4-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:98f80dee3c03455e92796b58b98ff6ca0b2a6f652120c263efdba4d6c5e58f72"}, {file = "typed_ast-1.5.4-cp39-cp39-win_amd64.whl", hash = "sha256:0fdbcf2fef0ca421a3f5912555804296f0b0960f0418c440f5d6d3abb549f3e1"}, {file = "typed_ast-1.5.4.tar.gz", hash = "sha256:39e21ceb7388e4bb37f4c679d72707ed46c2fbf2a5609b8b8ebc4b067d977df2"}, ] typing-extensions = [ {file = "typing_extensions-4.2.0-py3-none-any.whl", hash = "sha256:6657594ee297170d19f67d55c05852a874e7eb634f4f753dbd667855e07c1708"}, {file = "typing_extensions-4.2.0.tar.gz", hash = "sha256:f1c24655a0da0d1b67f07e17a5e6b2a105894e6824b92096378bb3668ef02376"}, ] zipp = [ {file = "zipp-3.8.0-py3-none-any.whl", hash = "sha256:c4f6e5bbf48e74f7a38e7cc5b0480ff42b0ae5178957d564d18932525d5cf099"}, {file = "zipp-3.8.0.tar.gz", hash = "sha256:56bf8aadb83c24db6c4b577e13de374ccfb67da2078beba1d037c17980bf43ad"}, ] untangle-1.2.1/pyproject.toml000066400000000000000000000007531426005006000162420ustar00rootroot00000000000000[tool.poetry] name = "untangle" version = "1.2.1" description = "Converts XML to Python objects" authors = ["Christian Stefanescu "] license = "MIT" readme = "README.md" [tool.poetry.dependencies] python = "^3.7" defusedxml = "^0.7.1" [tool.poetry.dev-dependencies] pytest = "^7.1.2" flake8 = "^4.0.1" black = "^22.6.0" build = "^0.8.0" setuptools = "^62.6.0" wheel = "^0.37.1" [build-system] requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" untangle-1.2.1/setup.py000077500000000000000000000022211426005006000150330ustar00rootroot00000000000000#!/usr/bin/env python # -*- coding: utf-8 -*- import untangle from setuptools import setup, find_packages from pathlib import Path long_description = (Path(__file__).parent / "README.md").read_text() setup( name="untangle", packages=find_packages(), version=untangle.__version__, description="Convert XML documents into Python objects", long_description_content_type="text/markdown", long_description=long_description, author="Christian Stefanescu", author_email="hello@stchris.net", url="http://github.com/stchris//untangle", py_modules=["untangle"], install_requires=["defusedxml"], include_package_data=True, license="MIT", classifiers=[ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "Natural Language :: English", "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", ], ) # vim: set expandtab ts=4 sw=4: untangle-1.2.1/tests/000077500000000000000000000000001426005006000144635ustar00rootroot00000000000000untangle-1.2.1/tests/res/000077500000000000000000000000001426005006000152545ustar00rootroot00000000000000untangle-1.2.1/tests/res/figs.xml000066400000000000000000000004001426005006000167200ustar00rootroot00000000000000 value1 value2 value untangle-1.2.1/tests/res/foo.xml000066400000000000000000000014231426005006000165610ustar00rootroot00000000000000 Target-1 0.0.0.0 cody cody cody cody 2 Target-2 0.0.0.0 cody cody cody cody 2 untangle-1.2.1/tests/res/pom.xml000066400000000000000000000055311426005006000165750ustar00rootroot00000000000000 com.atlassian.confluence.plugin.base confluence-plugin-base 17 4.0.0 com.this.that.groupId artifactId 0.1 atlassian-plugin ${pom.groupId}.${pom.artifactId} 2.9 1.4.1 2.9 untangle-1.2.1/tests/res/some.xslt000066400000000000000000000013371426005006000171370ustar00rootroot00000000000000

untangle-1.2.1/tests/res/unicode.xml000066400000000000000000000005111426005006000174210ustar00rootroot00000000000000 ðÒÉ×ÅÔ ÍÉÒ ðÕÎËÔ 1 http://example1.com ðÕÎËÔ 2 http://example2.com untangle-1.2.1/tests/res/xxe.xml000066400000000000000000000001371426005006000166030ustar00rootroot00000000000000 ]> untangle-1.2.1/tests/test_untangle.py000077500000000000000000000325041426005006000177200ustar00rootroot00000000000000#!/usr/bin/env python3 # -*- coding: utf-8 -*- import unittest import untangle import xml import defusedxml class FromStringTestCase(unittest.TestCase): """Basic parsing tests with input as string""" def test_basic(self): o = untangle.parse("") self.assertTrue(o is not None) self.assertTrue(o.a is not None) self.assertTrue(o.a.b is not None) self.assertTrue(o.a.c is not None) self.assertTrue("a" in o) self.assertTrue("b" in o.a) self.assertTrue("c" in o.a) self.assertTrue("d" not in o.a) def test_basic_with_decl(self): o = untangle.parse("") self.assertTrue(o is not None) self.assertTrue(o.a is not None) self.assertTrue(o.a.b is not None) self.assertTrue(o.a.c is not None) self.assertTrue("a" in o) self.assertTrue("b" in o.a) self.assertTrue("c" in o.a) self.assertTrue("d" not in o.a) def test_truthiness(self): o = untangle.parse("") self.assertTrue(o) self.assertTrue(o.a) self.assertTrue(o.a.b) self.assertTrue(o.a.c) def test_with_attributes(self): o = untangle.parse( """ """ ) self.assertEqual("Tomato soup", o.Soup["name"]) self.assertEqual(1, int(o.Soup["version"])) self.assertEqual("1l", o.Soup.Ingredients.Water["qty"]) self.assertTrue(o.Soup.Instructions.add_ingredients is not None) def test_grouping(self): o = untangle.parse( """ """ ) self.assertTrue(o.root) children = o.root.child self.assertEqual(3, len(children)) self.assertEqual("child1", children[0]["name"]) self.assertEqual("sub1", children[0].subchild["name"]) self.assertEqual(2, len(children[2].subchild)) self.assertEqual("sub2", children[2].subchild[0]["name"]) def test_single_root(self): self.assertTrue(untangle.parse("")) def test_attribute_protocol(self): o = untangle.parse( """ """ ) try: self.assertEqual(None, o.root.child.inexistent) self.fail("Was able to access inexistent child as None") except AttributeError: pass # this is the expected error except IndexError: self.fail("Caught IndexError quen expecting AttributeError") self.assertTrue(hasattr(o.root, "child")) self.assertFalse(hasattr(o.root, "inexistent")) self.assertEqual("child1", getattr(o.root, "child")[0]["name"]) def test_python_keyword(self): o = untangle.parse("") self.assertTrue(o is not None) self.assertTrue(o.class_ is not None) self.assertTrue(o.class_.return_ is not None) self.assertTrue(o.class_.pass_ is not None) self.assertTrue(o.class_.None_ is not None) class InvalidTestCase(unittest.TestCase): """Test corner cases""" def test_invalid_xml(self): self.assertRaises(xml.sax.SAXParseException, untangle.parse, "") def test_empty_xml(self): self.assertRaises(ValueError, untangle.parse, "") def test_none_xml(self): self.assertRaises(ValueError, untangle.parse, None) class PomXmlTestCase(unittest.TestCase): """Tests parsing a Maven pom.xml""" def setUp(self): self.o = untangle.parse("tests/res/pom.xml") def test_parent(self): project = self.o.project self.assertTrue(project) parent = project.parent self.assertTrue(parent) self.assertEqual("com.atlassian.confluence.plugin.base", parent.groupId) self.assertEqual("confluence-plugin-base", parent.artifactId) self.assertEqual("17", parent.version) self.assertEqual("4.0.0", project.modelVersion) self.assertEqual("com.this.that.groupId", project.groupId) self.assertEqual("", project.name) self.assertEqual( "${pom.groupId}.${pom.artifactId}", project.properties.atlassian_plugin_key ) self.assertEqual("1.4.1", project.properties.atlassian_product_test_lib_version) self.assertEqual("2.9", project.properties.atlassian_product_data_version) def test_lengths(self): self.assertEqual(1, len(self.o)) self.assertEqual(8, len(self.o.project)) self.assertEqual(3, len(self.o.project.parent)) self.assertEqual(4, len(self.o.project.properties)) class NamespaceTestCase(unittest.TestCase): """Tests for XMLs with namespaces""" def setUp(self): self.o = untangle.parse("tests/res/some.xslt") def test_namespace(self): self.assertTrue(self.o) stylesheet = self.o.xsl_stylesheet self.assertTrue(stylesheet) self.assertEqual("1.0", stylesheet["version"]) template = stylesheet.xsl_template[0] self.assertTrue(template) self.assertEqual("math", template["match"]) self.assertEqual("compact", template.table["class"]) self.assertEqual("compact vam", template.table.tr.xsl_for_each.td["class"]) self.assertEqual( untangle.Element("", ""), template.table.tr.xsl_for_each.td.xsl_apply_templates, ) last_template = stylesheet.xsl_template[-1] self.assertTrue(last_template) self.assertEqual("m_var", last_template["match"]) self.assertEqual("compact tac formula italic", last_template.p["class"]) self.assertEqual( untangle.Element("xsl_apply_templates", ""), last_template.p.xsl_apply_templates, ) class IterationTestCase(unittest.TestCase): """Tests various cases of iteration over child nodes.""" def test_multiple_children(self): """Regular case of iteration.""" o = untangle.parse("") cnt = 0 for i in o.a.b: cnt += 1 self.assertEqual(2, cnt) def test_single_child(self): """Special case when there is only a single child element. Does not work without an __iter__ implemented. """ o = untangle.parse("") cnt = 0 for i in o.a.b: cnt += 1 self.assertEqual(1, cnt) class TwimlTestCase(unittest.TestCase): """Github Issue #5: can't dir the parsed object""" def test_twiml_dir(self): xml = """ http://example.com/barcall_message_url.wav http://example.com/calls/1/twiml?event=start """ o = untangle.parse(xml) self.assertEqual(["Response"], dir(o)) resp = o.Response self.assertEqual(["Gather", "Redirect"], dir(resp)) gather = resp.Gather redir = resp.Redirect self.assertEqual(["Play"], dir(gather)) self.assertEqual([], dir(redir)) self.assertEqual( "http://example.com/calls/1/twiml?event=start", o.Response.Redirect.cdata ) class UnicodeTestCase(unittest.TestCase): """Github issue #8: UnicodeEncodeError""" def test_unicode_file(self): o = untangle.parse("tests/res/unicode.xml") self.assertEqual("ðÒÉ×ÅÔ ÍÉÒ", o.page.menu.name) def test_lengths(self): o = untangle.parse("tests/res/unicode.xml") self.assertEqual(1, len(o)) self.assertEqual(1, len(o.page)) self.assertEqual(2, len(o.page.menu)) self.assertEqual(2, len(o.page.menu.items)) self.assertEqual(2, len(o.page.menu.items.item)) self.assertEqual(0, len(o.page.menu.items.item[0].name)) self.assertEqual(0, len(o.page.menu.items.item[1].name)) def test_unicode_string(self): o = untangle.parse("valüé ◔‿◔") self.assertEqual("valüé ◔‿◔", o.Element.cdata) def test_unicode_element(self): o = untangle.parse("") self.assertTrue(o is not None) self.assertTrue(o.Francés is not None) class FileObjects(unittest.TestCase): """Test reading from file-like objects""" def test_file_object(self): with open("tests/res/pom.xml") as pom_file: o = untangle.parse(pom_file) project = o.project self.assertTrue(project) parent = project.parent self.assertTrue(parent) self.assertEqual("com.atlassian.confluence.plugin.base", parent.groupId) self.assertEqual("confluence-plugin-base", parent.artifactId) self.assertEqual("17", parent.version) class Foo(object): """Used in UntangleInObjectsTestCase""" def __init__(self): self.doc = untangle.parse('foo') class UntangleInObjectsTestCase(unittest.TestCase): """tests usage of untangle in classes""" def test_object(self): foo = Foo() self.assertEqual("1", foo.doc.a.b["x"]) self.assertEqual("foo", foo.doc.a.b.cdata) class UrlStringTestCase(unittest.TestCase): """tests is_url() function""" def test_is_url(self): self.assertFalse(untangle.is_url("foo")) self.assertFalse(untangle.is_url("httpfoo")) self.assertFalse(untangle.is_url(7)) self.assertTrue(untangle.is_url("http://foobar")) self.assertTrue(untangle.is_url("https://foobar")) class TestSaxHandler(unittest.TestCase): """Tests the SAX ContentHandler""" def test_empty_handler(self): h = untangle.Handler() self.assertRaises(IndexError, h.endElement, "foo") self.assertRaises(IndexError, h.characters, "bar") def test_handler(self): h = untangle.Handler() h.startElement("foo", {}) h.endElement("foo") self.assertEqual("foo", h.root.children[0]._name) def test_cdata(self): h = untangle.Handler() h.startElement("foo", {}) h.characters("baz") self.assertEqual("baz", h.root.children[0].cdata) class FigsTestCase(unittest.TestCase): def test_figs(self): doc = untangle.parse("tests/res/figs.xml") expected_pairs = [("key1", "value1"), ("key2", "value2"), ("key", "value")] pairs = [] for group in doc.props.children: for prop in group.children: pairs.append((prop["key"], prop.cdata)) assert expected_pairs == pairs class ParserFeatureTestCase(unittest.TestCase): """Tests adding xml.sax parser features via parse()""" # External DTD that will never be loadable (invalid address) bad_dtd_xml = """ """ def test_valid_feature(self): # xml.sax.handler.feature_external_ges -> load external general (text) # entities, such as DTDs with self.assertRaises(defusedxml.common.ExternalReferenceForbidden): untangle.parse(self.bad_dtd_xml) def test_invalid_feature(self): with self.assertRaises(AttributeError): untangle.parse(self.bad_dtd_xml, invalid_feature=True) def test_invalid_external_dtd(self): with self.assertRaises(defusedxml.common.ExternalReferenceForbidden): untangle.parse(self.bad_dtd_xml) class TestEquals(unittest.TestCase): def test_equals(self): a = untangle.Element("a", "1") b = untangle.Element("b", "1") self.assertTrue(a == b) def test_list_equals(self): a = untangle.Element("a", "1") b = untangle.Element("b", "1") listA = [a, b] c = untangle.Element("c", "1") self.assertTrue(c in listA) class TestExternalEntityExpansion(unittest.TestCase): def test_xxe(self): # from https://pypi.org/project/defusedxml/#external-entity-expansion-remote with self.assertRaises(defusedxml.common.EntitiesForbidden): untangle.parse("tests/res/xxe.xml") if __name__ == "__main__": unittest.main() # vim: set expandtab ts=4 sw=4 untangle-1.2.1/untangle.py000077500000000000000000000136301426005006000155160ustar00rootroot00000000000000#!/usr/bin/env python """ untangle Converts xml to python objects. The only method you need to call is parse() Partially inspired by xml2obj (http://code.activestate.com/recipes/149368-xml2obj/) Author: Christian Stefanescu (http://0chris.com) License: MIT License - http://www.opensource.org/licenses/mit-license.php """ import os import keyword from defusedxml.sax import make_parser from xml.sax import handler try: from StringIO import StringIO except ImportError: from io import StringIO try: from types import StringTypes def is_string(x): return isinstance(x, StringTypes) except ImportError: def is_string(x): return isinstance(x, str) __version__ = "1.2.1" class Element(object): """ Representation of an XML element. """ def __init__(self, name, attributes): self._name = name self._attributes = attributes self.children = [] self.is_root = False self.cdata = "" def add_child(self, element): """ Store child elements. """ self.children.append(element) def add_cdata(self, cdata): """ Store cdata """ self.cdata = self.cdata + cdata def get_attribute(self, key): """ Get attributes by key """ return self._attributes.get(key) def get_elements(self, name=None): """ Find a child element by name """ if name: return [e for e in self.children if e._name == name] else: return self.children def __getitem__(self, key): return self.get_attribute(key) def __getattr__(self, key): matching_children = [x for x in self.children if x._name == key] if matching_children: if len(matching_children) == 1: self.__dict__[key] = matching_children[0] return matching_children[0] else: self.__dict__[key] = matching_children return matching_children else: raise AttributeError("'%s' has no attribute '%s'" % (self._name, key)) def __hasattribute__(self, name): if name in self.__dict__: return True return any(x._name == name for x in self.children) def __iter__(self): yield self def __str__(self): return "Element <%s> with attributes %s, children %s and cdata %s" % ( self._name, self._attributes, self.children, self.cdata, ) def __repr__(self): return "Element(name = %s, attributes = %s, cdata = %s)" % ( self._name, self._attributes, self.cdata, ) def __bool__(self): return self.is_root or self._name is not None __nonzero__ = __bool__ def __eq__(self, val): return self.cdata == val def __dir__(self): children_names = [x._name for x in self.children] return children_names def __len__(self): return len(self.children) def __contains__(self, key): return key in dir(self) class Handler(handler.ContentHandler): """ SAX handler which creates the Python object structure out of ``Element``s """ def __init__(self): self.root = Element(None, None) self.root.is_root = True self.elements = [] def startElement(self, name, attributes): name = name.replace("-", "_") name = name.replace(".", "_") name = name.replace(":", "_") # adding trailing _ for keywords if keyword.iskeyword(name): name += "_" attrs = dict() for k, v in attributes.items(): attrs[k] = v element = Element(name, attrs) if len(self.elements) > 0: self.elements[-1].add_child(element) else: self.root.add_child(element) self.elements.append(element) def endElement(self, name): self.elements.pop() def characters(self, cdata): self.elements[-1].add_cdata(cdata) def parse(filename, **parser_features): """ Interprets the given string as a filename, URL or XML data string, parses it and returns a Python object which represents the given document. Extra arguments to this function are treated as feature values that are passed to ``parser.setFeature()``. For example, ``feature_external_ges=False`` will set ``xml.sax.handler.feature_external_ges`` to False, disabling the parser's inclusion of external general (text) entities such as DTDs. Raises ``ValueError`` if the first argument is None / empty string. Raises ``AttributeError`` if a requested xml.sax feature is not found in ``xml.sax.handler``. Raises ``xml.sax.SAXParseException`` if something goes wrong during parsing. Raises ``defusedxml.common.EntitiesForbidden`` or ``defusedxml.common.ExternalReferenceForbidden`` when a potentially malicious entity load is attempted. See also https://github.com/tiran/defusedxml#attack-vectors """ if filename is None or (is_string(filename) and filename.strip()) == "": raise ValueError("parse() takes a filename, URL or XML string") parser = make_parser() for feature, value in parser_features.items(): parser.setFeature(getattr(handler, feature), value) sax_handler = Handler() parser.setContentHandler(sax_handler) if is_string(filename) and (os.path.exists(filename) or is_url(filename)): parser.parse(filename) else: if hasattr(filename, "read"): parser.parse(filename) else: parser.parse(StringIO(filename)) return sax_handler.root def is_url(string): """ Checks if the given string starts with 'http(s)'. """ try: return string.startswith("http://") or string.startswith("https://") except AttributeError: return False # vim: set expandtab ts=4 sw=4: untangle-1.2.1/untangle.rst000066400000000000000000000007071426005006000156740ustar00rootroot00000000000000untangle -------- .. image:: https://github.com/stchris/untangle/actions/workflows/build.yml/badge.svg untangle parses an XML document and returns a Python object which makes it easy to access the data you want. Example: :: import untangle obj = untangle.parse('') assert obj.root.child['name'] == u'child1' See http://github.com/stchris/untangle and http://readthedocs.org/docs/untangle/en/latest/