Python's eval() function

All other Source.Python topics and issues.
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Python's eval() function

Postby BackRaw » Thu Jun 04, 2015 11:57 pm

Hi all,

I remember back in the EventScripts days that the use of Python's eval() function was a 'potential risk' or something like that. I wonder if this is still true for SP because I want to make a calculator lol :D
My Github repositories:

Source.Python: https://github.com/backraw
necavi
Developer
Posts: 129
Joined: Wed Jan 30, 2013 9:51 pm

Postby necavi » Fri Jun 05, 2015 12:03 am

It absolutely is. There's no true way to sandbox it, but you can do things to help restrict it if you like.
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Postby BackRaw » Fri Jun 05, 2015 12:15 am

necavi wrote:It absolutely is. There's no true way to sandbox it, but you can do things to help restrict it if you like.


True, but I'm not sure how I would go about that one tho :D
My Github repositories:

Source.Python: https://github.com/backraw
necavi
Developer
Posts: 129
Joined: Wed Jan 30, 2013 9:51 pm

Postby necavi » Fri Jun 05, 2015 12:20 am

Read up on it? SourcePython's eval is the same as any other python eval, to my knowledge. There's a fuckton of information on the internet for you.
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Postby BackRaw » Fri Jun 05, 2015 12:22 am

Maybe sometime.
My Github repositories:

Source.Python: https://github.com/backraw
User avatar
Mahi
Senior Member
Posts: 236
Joined: Wed Aug 29, 2012 8:39 pm
Location: Finland

Postby Mahi » Fri Jun 05, 2015 1:00 pm

You're better off parsing a string, looking for calculations, rather than trying to use eval on it.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Fri Jun 05, 2015 1:25 pm

Not 100% sure of what you are looking to do, but you 'could' also create a temp.py file within your plugins directory with a variable equaling the equation and try to import that value.
Image
stonedegg
Senior Member
Posts: 141
Joined: Sun Aug 12, 2012 11:45 am

Postby stonedegg » Fri Jun 05, 2015 6:56 pm

I heard ast.literal_eval() is better
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Fri Jun 05, 2015 7:14 pm

Well, it does not allow you to use operators.

Check the docs: https://docs.python.org/3.4/library/ast.html#ast.literal_eval
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Postby BackRaw » Fri Jun 05, 2015 10:58 pm

I'll go with parsing the string i have an idea

Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 11 guests