Non-secure execution environment

2009-04-16 Thread rogeeff
Hi,

I am C++ guy for the most part and don't know much of Python, so,
please, bear with me if I am asking errrm..idiotic question.

Old rexec module provided kinda 'secure' execution environment. I am
not looking for security at this point. What I need an execution
environment which almost like rexec, but is non-secure.
  What I want is:
  separate global dictionary,
  separate list of imported modules,
  separate sys.path
  (optionaly) separate __builtins__

I might be able to get away without my own builtins, but the rest I
need.

If  it's any help, I plan to use it to execute embedded Python scripts
from C++.

Thanks,

Gennadiy
--
http://mail.python.org/mailman/listinfo/python-list


Re: Non-secure execution environment

2009-04-17 Thread rogeeff
On Apr 17, 7:06 am, Aaron Brady  wrote:
> On Apr 17, 1:47 am, roge...@gmail.com wrote:
>
>
>
> > Hi,
>
> > I am C++ guy for the most part and don't know much of Python, so,
> > please, bear with me if I am asking errrm..idiotic question.
>
> > Old rexec module provided kinda 'secure' execution environment. I am
> > not looking for security at this point. What I need an execution
> > environment which almost like rexec, but is non-secure.
> >   What I want is:
> >   separate global dictionary,
> >   separate list of imported modules,
> >   separate sys.path
> >   (optionaly) separate __builtins__
>
> > I might be able to get away without my own builtins, but the rest I
> > need.
>
> > If  it's any help, I plan to use it to execute embedded Python scripts
> > from C++.
>
> > Thanks,
>
> > Gennadiy
>
> It depends what you mean by secure environment.  One option is to
> create a subprocess, to just limit access your variables.  Another is
> to compile and examine their code yourself, and prohibit things like
> access to the file class, the os module, etc.

I actually need *non-secure* execution environment. I just want
several independent ones.

Gennadiy
--
http://mail.python.org/mailman/listinfo/python-list


Re: Non-secure execution environment

2009-04-17 Thread rogeeff
On Apr 17, 3:16 am, Ken Seehart  wrote:
> roge...@gmail.com wrote:
> > Hi,
>
> > I am C++ guy for the most part and don't know much of Python, so,
> > please, bear with me if I am asking errrm..idiotic question.
>
> > Old rexec module provided kinda 'secure' execution environment. I am
> > not looking for security at this point. What I need an execution
> > environment which almost like rexec, but is non-secure.
> >   What I want is:
> >   separate global dictionary,
> >   separate list of imported modules,
> >   separate sys.path
> >   (optionaly) separate __builtins__

> As far as I know, you can't make multiple instances of the python
> environment from within python,

How about rexec? It's almost there. It just enforces some restrictions
I do not need. The problem as I see it is that I need custom import
operator to maintain separate "imported modules" list. The custom
import required separate __builtins__ dictionary and that cause the
Python C implementation to choke on access to the restricted
attributes.

Would I be able to have custom import without updating builtins, I'd
get what I need. But I do not know how to achieve this.

> but there is an easier way to get what
> you want, given that this is an embedding situation.

> See:http://wingware.com/psupport/python-manual/1.5/api/initialization.html

I am using Python 2.4, if it's matter

> You can use Py_NewInterpreter() to create multiple instances of python,
> which should give you the desired effect (though I have not tried this).

What do I do with pointer generated by this function? How do I execute
anything inside this interpreter?

Also I am not sure how will this work with Boost.Python I am
employing.

Gennadiy
--
http://mail.python.org/mailman/listinfo/python-list


Re: Non-secure execution environment

2009-04-20 Thread rogeeff
If anyone is interested I end up using rexec kinda class with only
difference that i am using native __builtin__ and resetting __import__
hook to and from local r_import implementation before and after I am
executing code in my environment.

Gennadiy
--
http://mail.python.org/mailman/listinfo/python-list


Re: Non-secure execution environment

2009-04-20 Thread rogeeff
If anyone is interested I end up using rexec kinda class with only
difference that i am using native __builtin__ and resetting __import__
hook to and from local r_import implementation before and after I am
executing code in my environment.

Gennadiy
--
http://mail.python.org/mailman/listinfo/python-list


How to replace constructor with factory method

2009-05-11 Thread rogeeff
Hi,

Just wonder if it's possible in Python.

what I want is to tweak an existing Python class A with no
constructor, so that A() results in fuctory method call?

so o = A() instead being equivalent to:

s = object()
A.__init__(s)
o = s

becomes:

o = my_factory_function( A )

Thanks,

Gennadiy
-- 
http://mail.python.org/mailman/listinfo/python-list