Hiding Python Source

t_e_sanders at my-deja.com t_e_sanders at my-deja.com
Wed Mar 22 23:46:52 EST 2000


Hi. I've been following the various "how do you hide Python source?" threads,
and was wondering if someone could give me a hand with a related problem. I'd
like to have my Python program import a module written by an arbitrary
end-user, without allowing the end user to use his module to display my code.

Specifically, I have a module "mainmodule.pyc" that imports and executes
"usermodule.py", (which in turn may import mainmodule to make use of its
functions.) mainmodule might look something like this:

> # mainmodule.py
> import usermodule
>
> print "This will now activate the end-user's module..."
> usermodule.do_something()

To prevent the casual observer from viewing the contents of mainmodule, I'm
only distributing mainmodule.pyc. To prevent people from easily decompiling
mymodule.pyc externally, I've reversed some of the bytecodes in Python's C
source. (Not 100% sure if this'll do the trick, either.)

However, I'd like to make it difficult for the author of usermodule.py to
reconstruct/produce mainmodule's source, (e.g., do something like
sys.modules["mainmodule"].list_all_code_muahaha().) from within
usermodule.py. Is this even a legitemate concern? Are there module methods
(or functions) that reliably decompile a module to produce the source?

I know that I could prevent users from doing this by writing a preprocessor,
(a ridiculous example of this might be writing a preprocessor to prevent
users from using anything other than the "print" statement.) But I'm not sure
as to a) what functionality I'd have to weed out, or b) if it's even a
concern. Any thoughts?

Thanks much,
Thomas Sanders
t.e.sanders at usa.net


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list