# -*- coding: utf-8 -*-
from setuptools import setup

packages = \
['django_html_xml_validator']

package_data = \
{'': ['*']}

install_requires = \
['Django>=3,<5', 'lxml>=4,<5']

setup_kwargs = {
    'name': 'django-html-xml-validator',
    'version': '1.0.0',
    'description': 'Django middleware to validate HTML and XML responses',
    'long_description': '[![PyPI](https://img.shields.io/pypi/v/django_html_xml_validator)](https://pypi.org/project/django_html_xml_validator/)\n[![Python Versions](https://img.shields.io/pypi/pyversions/django_html_xml_validator.svg)](https://www.python.org/downloads/)\n[![Build Status](https://github.com/itell-solutions/django_html_xml_validator/actions/workflows/build.yaml/badge.svg)](https://github.com/itell-solutions/django_html_xml_validator/actions/workflows/build.yaml)\n[![Black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![License](https://img.shields.io/github/license/itell-solutions/django_html_xml_validator)](https://opensource.org/licenses/MIT)\n\n# Django HTML and XML Validator\n\n`Django_html_xml_validator` is a Django middleware to validate HTML and XML\nresponses generated by your application. This includes but is not limited to\nDjango views using `render()` and Django HTML templates.\n\nFeatures:\n\n- **Specific error locations** in case validation finds issues.\n- **Runs locally** without the need to upload your page to an external\n  validation service.\n- **Uses only Python packages** without the need to install external tools\n  from other ecosystems.\n- **Fast** because based on [lxml](https://lxml.de/) and its native components.\n\nThis makes it feasible to perform validation while running your test suite.\n\n## Installation\n\nTo install, depending on your package manager, run:\n\n```bash\npip install --update django_html_xml_validator\n```\n\nor\n\n```bash\npoetry add django_html_xml_validator\n```\n\n## Usage\n\nTo add validation to your project, add it to `settings.MIDDLEWARE`.\n\n```python\nMIDDLEWARE = [\n    ...,\n    "django_html_xml_validator.middleware.HtmlXmlValidatorMiddleware",\n]\n```\n\nIn most cases you only want it to validate the HTML generated by your views\ndirectly, so it would be the last entry. Especially if you have other\nmiddleware installed that modifies your HTML like adding the Django Debug\ntoolbar or minifying it.\n\nFor example:\n\n```python\nMIDDLEWARE = [\n    # Possible middleware your project requires.\n    ...,\n     # Example middleware that modifies the HTML.\n    "django_minify_html.middleware.MinifyHtmlMiddleware",\n    "debug_toolbar.middleware.DebugToolbarMiddleware",\n    ...,\n    # Put validation middleware toward the end to ensure only your HTML/XML is validated.\n    "django_html_xml_validator.middleware.HtmlXmlValidatorMiddleware",\n]\n```\n\nAfter that, responses with a matching content type are validated:\n\n- HTML:\n  - application/xhtml+xml\n  - text/html\n- XML:\n  - application/xml\n  - text/xml\n\nIn case the response is valid, the middleware returns the original response\nand HTTP status code verbatim.\n\nIn case errors have been found, the response includes an HTML page detailing\nthe errors with an HTTP status code of 500 (internal server error).\n\n## Configuration\n\nBy default, validation is active when the Django `DEBUG` mode is enabled in\n`settings.py`. In a reasonably configured project this means during local\ndevelopment and while running the test suite, but not once deployed to a\nserver.\n\nFor more granular control, add the following to `settings.py`:\n\n```python\nVALIDATE_HTML = True\nVALIDATE_XML = True\n```\n\nIf you are sure all your HTML pages are actually XHTML (which sadly will not\nbe the case as soon as your code contains forms based on standard Django\nforms), you can enforce HTML to be validated as XHTML:\n\n```python\nVALIDATE_HTML_AS_XHTML = True  # WARNING: Will fail with standard form templates\n```\n\n## Disabling validation for specific tests\n\nIn case validation is not useful for selected tests (for example when\nprocessing deliberately huge documents), it can be disabled with the\n[override_settings](https://docs.djangoproject.com/en/4.0/topics/testing/tools/#django.test.override_settings)\nannotation. For example:\n\n```python\nfrom django.test import override_settings\n\n@override_settings(VALIDATE_XML=False)\ndef test_can_build_huge_xml():\n    ...\n```\n\n## Limitations\n\n- Validation does not apply to stream responses.\n- Validation of HTML5 uses a hack to ignore errors about invalid tags on\n  sectioning elements like `<nav>` or `<article>`.\n- Validation of XML only checks if the document is well-formed but does not\n  validate against a schema or DTD. Technically lxml could do all this but\n  would require more setup. If you need such a feature, feel free to submit a\n  pull request.\n\n## License\n\nCopyright (c) 2022 ITELL.SOLUTIONS GmbH, Graz, Austria.\n\nDistributed under the\n[MIT license](https://en.wikipedia.org/wiki/MIT_License). For details refer to\nthe file `LICENSE`.\n\nThe source code is available from\n<https://github.com/itell-solutions/django_html_xml_validator>.\n',
    'author': 'ITELL.SOLUTIONS GmbH',
    'author_email': None,
    'maintainer': None,
    'maintainer_email': None,
    'url': 'https://github.com/itell-solutions/django_html_xml_validator',
    'packages': packages,
    'package_data': package_data,
    'install_requires': install_requires,
    'python_requires': '>=3.7,<4.0',
}


setup(**setup_kwargs)
