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: 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 Subject: Re: Create a .lua fle from Python Date: Wed, 30 Sep 2015 11:21:07 +0200 References: 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: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On 09/29/2015 07:28 PM, Peter Otten wrote: > jmp wrote: >> import bs4 >> import jinja2 >> >> xml = """ >> >> BuenosAires >> 30 >> >> >> Seatle >> 25 >> >> """ >> >> 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