Re: Disable certain modules

Pradeep Badiger <[email protected]>
Newsgroups gmane.comp.lang.jython.devel
Message-ID <DDFE6B42B194104F903A334F685DC89919443CF3@mbx025-wd-ca-2.exch025.domain.local>
I was trying import using "from" syntax and this logic doesn't seem to work. I mean I get import error from oldImport module.

from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart

Exception in thread "main" javax.script.ScriptException: ImportError: cannot import name MIMEImage in <script> at line number 122
       at org.python.jsr223.PyScriptEngine.scriptException(PyScriptEngine.java:202)
       at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:42)
       at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:31)

Thanks,
Pradeep V.B.

From: Pradeep Badiger
Sent: Thursday, February 12, 2015 2:21 PM
To: 'Jeff Emanuel'; [email protected]
Subject: RE: [Jython-dev] Disable certain modules

Interesting.. I will see if this fits my requirements.

Thanks,
Pradeep V.B.

From: Jeff Emanuel [mailto:[email protected]]
Sent: Thursday, February 12, 2015 1:53 PM
To: [email protected]<mailto:[email protected]>; Pradeep Badiger
Subject: Re: [Jython-dev] Disable certain modules

I don't know that this is fool-proof, but you can replace __builtin__.__import__ with your own implementation that checks the module name.

>>> import __builtin__
>>> oldImport = __builtin__.__import__
>>> def myImport(*args):
...   if args[0]=='symbol':  # Disallowing symbol module
...     raise ImportError("Import denied")
...   return oldImport(*args)
...
>>> __builtin__.__import__=myImport
>>> import symbol  # fails
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "<input>", line 3, in myImport
ImportError: Import denied
>>> import traceback # works
>>>


On 2/12/2015 8:37 AM, Pradeep Badiger wrote:
Hi,

I am trying to disable certain modules which I don't want my users to use. How can I do that?

I tried del function to delete the module programmatically. But this doesn't work if you import the module again.

Can someone provide me the pointers?

Thanks,
Pradeep V.B.


This email and any files transmitted with it are confidential, proprietary and intended solely for the individual or entity to whom they are addressed. If you have received this email in error please delete it immediately.


------------------------------------------------------------------------------

Dive into the World of Parallel Programming. The Go Parallel Website,

sponsored by Intel and developed in partnership with Slashdot Media, is your

hub for all things parallel software development, from weekly thought

leadership blogs to news, videos, case studies, tutorials and more. Take a

look and join the conversation now. http://goparallel.sourceforge.net/



_______________________________________________

Jython-dev mailing list

[email protected]<mailto:[email protected]>

https://lists.sourceforge.net/lists/listinfo/jython-dev


This email and any files transmitted with it are confidential, proprietary and intended solely for the individual or entity to whom they are addressed. If you have received this email in error please delete it immediately.

------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/

_______________________________________________
Jython-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jython-dev
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.