Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #97239

Re: Create a .lua fle from Python

From jmp <jeanmichel@sequans.com>
Subject Re: Create a .lua fle from Python
Date 2015-09-30 11:21 +0200
References <CAMxmM6bhyHUpQXxnwO-OiesppP6mRM74=dA37VJwV212MZGyUw@mail.gmail.com> <mueeef$d31$1@ger.gmane.org> <muehno$19e$1@ger.gmane.org>
Newsgroups comp.lang.python
Message-ID <mailman.265.1443604877.28679.python-list@python.org> (permalink)

Show all headers | View raw


On 09/29/2015 07:28 PM, Peter Otten wrote:
> jmp wrote:
>> import bs4
>> import jinja2
>>
>> xml = """<cities>
>>        <city>
>>                 <name>BuenosAires</name>
>>                 <temperature>30</temperature>
>>         </city>
>> <city>
>>         <name>Seatle</name>
>>         <temperature>25</temperature>
>> </city>
>> </cities>"""
>>
>> lua_template = """
>> cities_temps ={
>> {%- for city, temp in cities.iteritems() %}
>> ["{{city}}"] = {{temp}},
>> {%- endfor %}
>> }"""
>>
>> xmlp = bs4.BeautifulSoup(xml, 'xml')
>> # from xml to python dictionary
>> data = {city.find('name').string:city.find('temperature').string for
>> city in xmlp.findAll('city')}
>> # from python dictionary to lua
>> print jinja2.Template(lua_template).render(cities=data)
>>
>>
>> will yield (python 2.7):
>>
>> cities_temps ={
>> ["BuenosAires"] = 30,
>> ["Seatle"] = 25,
>> }
>
> Is Ariel's xml file user-supplied? If so, how does your suggestion prevent
> the resulting lua script from executing arbitrary code?

It does not. Like it doesn't fulfill the millions of possible 
requirements the OP could have written but did not. What if the OP want 
a thread safe, super fast, multi core solution distributed on multiple 
remote hosts ?

jm

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: Create a .lua fle from Python jmp <jeanmichel@sequans.com> - 2015-09-30 11:21 +0200
  Re: Create a .lua fle from Python Steven D'Aprano <steve@pearwood.info> - 2015-10-02 05:12 +1000
    Re: Create a .lua fle from Python jmp <jeanmichel@sequans.com> - 2015-10-02 11:03 +0200
    Re: Create a .lua fle from Python Stefan Behnel <stefan_ml@behnel.de> - 2015-10-02 13:49 +0200

csiph-web