Code Monkey home page Code Monkey logo

Comments (3)

tiran avatar tiran commented on August 24, 2024

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.

dga-nagra avatar dga-nagra commented on August 24, 2024

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.

dga-nagra avatar dga-nagra commented on August 24, 2024

@tiran any update on the deprecated solution?

from defusedxml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.