Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #97239
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'resulting': 0.04; 'subject:Python': 0.05; '"""': 0.05; '(python': 0.05; 'hosts': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'thread': 0.10; 'python': 0.10; 'code?': 0.16; 'jmp': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'temp': 0.16; 'wrote:': 0.16; 'prevent': 0.20; 'subject: .': 0.22; 'import': 0.24; 'xml': 0.24; 'written': 0.24; 'header:In-Reply- To:1': 0.24; 'script': 0.25; 'header:User-Agent:1': 0.26; "doesn't": 0.26; 'header:X-Complaints-To:1': 0.26; 'not.': 0.27; 'executing': 0.27; 'yield': 0.27; 'dictionary': 0.29; 'print': 0.30; 'skip:[ 10': 0.31; 'core': 0.32; 'file': 0.34; 'requirements': 0.35; 'so,': 0.35; 'could': 0.35; 'remote': 0.35; 'but': 0.36; 'possible': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'suggestion': 0.37; 'data': 0.39; 'does': 0.39; 'subject:from': 0.39; 'to:addr:python.org': 0.40; 'your': 0.60; 'skip:u 10': 0.61; 'received:194': 0.61; '30,': 0.63; 'city': 0.65; 'fulfill': 0.66; 'fast,': 0.84; 'otten': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | jmp <jeanmichel@sequans.com> |
| Subject | Re: Create a .lua fle from Python |
| Date | Wed, 30 Sep 2015 11:21:07 +0200 |
| References | <CAMxmM6bhyHUpQXxnwO-OiesppP6mRM74=dA37VJwV212MZGyUw@mail.gmail.com> <mueeef$d31$1@ger.gmane.org> <muehno$19e$1@ger.gmane.org> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | paris.sequans.com |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 |
| In-Reply-To | <muehno$19e$1@ger.gmane.org> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.265.1443604877.28679.python-list@python.org> (permalink) |
| Lines | 49 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1443604877 news.xs4all.nl 23842 [2001:888:2000:d::a6]:46889 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:97239 |
Show key headers only | 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 | Next — Next in thread | Find similar | Unroll 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