[Zope-dev] Import Libraries into Python Script

Itai Tavor itai@optusnet.com.au
Fri, 16 Feb 2001 11:14:31 +1100


What's wrong with:

    import imaplib
     imaplib.__allow_access_to_unprotected_subobjects__ = 1

And, if the above is somehow bad or insecure, how would you use your 
method to allow access to specific methods in a module, as in:

    import re
     re.__allow_access_to_unprotected_subobjects__ = {
         'sub': 1,
     }

Itai


Brian Lloyd wrote:

>This needs to be documented (and made a little easier), but
>heres a quick primer:
>
>
>   o Create a new directory in your 'Products' directory
>     (called ModuleAssertions or something like that - the
>     name is unimportant).
>
>   o Create an '__init__.py' file in the new directory.
>
>   o Add module assertions like the example below to __init__.py:
>
># Site-wide module security assertions
>
>from AccessControl.SecurityInfo import ModuleSecurityInfo
>import string
>
>def allow_module(module_name):
>     module  = __import__(module_name)
>     sec_info=ModuleSecurityInfo(module)
>     sec_info.setDefaultAccess(1)
>     sec_info.apply(module.__dict__)
>     for part in string.split(module_name, '.')[1:]:
>         module=getattr(module, part)
>         sec_info=ModuleSecurityInfo(module)
>         sec_info.setDefaultAccess(1)
>         sec_info.apply(module.__dict__)
>
>
># Allow access to base64 module
>allow_module('base64')
>
># Allow access to imaplib
>allow_module('imaplib')
>
>
>   o Restart Zope
>
>
>
>
>
>Brian Lloyd        brian@digicool.com
>Software Engineer  540.371.6909
>Digital Creations  www.digicool.com
>
>>  -----Original Message-----
>>  From: zope-dev-admin@zope.org [mailto:zope-dev-admin@zope.org]On Behalf
>>  Of Chris Withers
>>  Sent: Thursday, February 15, 2001 6:49 AM
>>  To: zope-dev@zope.org
>>  Subject: [Zope-dev] Import Libraries into Python Script
>>
>>
>>  Hi,
>>
>>  What's the 'approved' way of validating standard python modules
>>  so they can be
>>  imported in Python Scripts?
>>
>>  I want to import imaplib but can't find out how :-(
>>
>>  cheers,
>>
>  > Chris
-- 
--
Itai Tavor                      -- "Je sautille, donc je suis."    --
itai@optusnet.com.au            --               - Kermit the Frog --
-- "What he needs now is understanding... and a confederate victory" --
-- Dr. Jacobi, Twin Peaks         --