I've a program distributed with py2exe.
Users want the ability to run plugin python scripts.
For the plugins to be useful, they need access to data and functions of the
but at the same time there are program internals, and 3rd party data, that
need to be protected.
I haven't been able to figure out how to do this.
__import__ (scriptname, None, None) sets globals() and locals(),
and a single 'scriptHelpers' module import is documented,
which module gives the plugins access to data and functions that are
However, it's possible for a knowledgeable Python programmer to crack things
What I haven't figured out how to do in this situation is to hook the import
inside a py2exe app, so that imports inside the plugin are restricted.
I've tried the various import hooks / meta_path, etc, none of these get
executed in the py2exe/zipextimporter architecture.
How can I hook the import statement for a python script that is being
__import__'d and run inside a py2exe program ?
I want to restrict what a script __import__'d by a p2exe program can itself
On 12/06/2010 03:08 AM, H.R.Gartenbauer wrote:
> I've a program distributed with py2exe.
> Users want the ability to run plugin python scripts.
> For the plugins to be useful, they need access to data and functions of the
> hosting program,
> but at the same time there are program internals, and 3rd party data, that
> need to be protected.
Py2exe doesn't protect anything, it just packs.
In a nutshell py2exe does following:
- it compiles all python files into .pyc / .pyo files
pyc files pyo files are contain the python byte code,
which can be decompiled by any person motivated enough.
- optionally py2exe puts all the byte code files in once zip files and
copies all (most) required dlls and some generated .exe
files in one directory.
The question about protecting the code is more a python question than a
py2exe question, as py2exe just packs up what was build by python.
You could try to get more info in the python groups, though I'm afraid,
that there's no real way to protect any code.
Your best protection is probably legal protection through your license