Creating a reliable sandboxed Python environment

Chris Angelico rosuav at gmail.com
Fri May 29 03:41:10 EDT 2015


On Fri, May 29, 2015 at 4:18 PM, Stefan Behnel <stefan_ml at behnel.de> wrote:
>> Lua's a much weaker language than Python is, though. Can it handle
>> arbitrary-precision integers? Unicode? Dare I even ask,
>> arbitrary-precision rationals (fractions.Fraction)?
>
> All of those and way more, as long as you use it embedded in Python.

Okay, so how would you go about using Lua-embedded-in-Python to
manipulate Unicode text? I'm not talking about things like the
unicodedata module and the name/codepoint lookups, I'm talking about
the basics of working with international text and the fundamental need
for your native string type to cope with that. Do you have to keep
bouncing back and forth between Python and Lua? And if you do
arithmetic in the single most obvious way, what happens?

http://www.lua.org/pil/2.3.html

Looks to me as if Lua doesn't have integers at all, and so the obvious
form of arithmetic will be equivalent to doing everything in Python
floats. That's not arbitrary precision. There's also a comment that
you can use some other type for numbers, but I suspect that's still
"some other C type", so you still can't do arbitrary precision. (Plus
you get one type for ints and floats, so even if you did select some
magic type that bounces through to a Python int, it'd stop you from
doing any non-integral arithmetic at all.)

http://www.lua.org/pil/2.4.html

Likewise, eight-bit strings, not Unicode. While I could accept some
sort of inter-language thunk for something uncommon, like
fractions.Fraction, forcing people to thunk back and forth for basic
arithmetic and string manipulation is way too much hassle - which
means they won't do it, which means strings will be eight-bit and
numbers will be doubles. And eight-bit strings might be treated as
UTF-8, or might be treated as some arbitrary codepage, or might be
both at once in different contexts, so you can't really depend on them
being anything more than ASCII.

Or can you change all this when you embed Lua?

ChrisA



More information about the Python-list mailing list