Comments (3)
You have to construct a XMLParser
a custom parser with lxml.etree.XMLParser
and pass it to defusedxml.lxml.XML
. You should at least set resolve_entities=False
. The custom element lookup is optional.
>>> import lxml.etree
>>> import defusedxml.lxml
>>>
>>> parser = lxml.etree.Parser(remove_blank_text=True, resolve_entities=False)
>>> lookup = lxml.etree.ElementDefaultClassLookup(defusedxml.lxml.RestrictedElement)
>>> parser.set_element_class_lookup(lookup)
>>> e = defusedxml.lxml.XML("<root><el/> </root>", parser=parser)
>>> lxml.etree.tostring(e)
b'<root><el/></root>'
from defusedxml.
Hi @tiran, you said in #33 that
I have deprecated the defusedxml.lxml module and will remove it in a future release.
So I shouldn't be using the solution you provide, or have you changed your mind? Because I already have the deprecation warning when following your recommendation and it doesn't seem that RestrictedElement
is available anywhere else.
Could you please not close this issue right away considering the solution you provide is supposed to be deprecated.
from defusedxml.
@tiran any update on the deprecated solution?
from defusedxml.
Related Issues (20)
- [Question] Correct way to parse HTML with defusedxml? HOT 1
- Missing XMLParser options WITHOUT deprecated solution HOT 1
- type stubs for mypy HOT 2
- defusedxml does not work with `rich` library to print exceptions
- Ignore DTD when parsing with SAX HOT 1
- LXML Support and XML Validator HOT 1
- [Feature request] Automatically detect imports of vulnerable xml parsers in projects HOT 1
- equivalent of lxml.objectify cleanup_namespaces in defusedxml HOT 1
- defusedxml 0.7.1 & Python 3.9 -- TypeError: __init__() takes 1 positional argument but 4 were given HOT 1
- Please add compatibility with xmlschema HOT 3
- ElementTree.fromstring() does not accept parser as an argument HOT 2
- defusedxml has no method of registering namespaces. HOT 3
- Missing Element class xml.etree.ElementTree.Element HOT 1
- Want to know the estimated time of the next version update HOT 1
- defusedxml reads bytes, not str HOT 3
- Cannot use `xpath` and any other functionality from `lxml` HOT 2
- Missing indent function HOT 1
- Calling defuse_stdlib() raises a DeprecationWarning error with python -W
- [Question] When can we expect to support Python 3.10? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from defusedxml.