Nuxeo mailing list archives
RE : [CPS-devel] breaking code up into seperate files
Winterflood, Jonathan
jonathan.winterflood at capgemini.com
Mon Mar 19 14:28:40 CET 2007
Thanks, it works now :)
I think I'd done all of those last week, but not all at the same time... oh well
Indeed I'd looked at CPSUtil too.
For list reference:
file foo.py:
from AccessControl import ModuleSecurityInfo
ModuleSecurityInfo('Products.bazProduct.foo).declarePublic('bar')
def bar():
return 'fred & barney'
EOF
file __init__.py:
# Making sure that the ModuleSecurityInfo info statements of the following modules are taken into account.
import foo
EOF
to import, do
from Products.bazProduct.foo import bar
(and not from foo import bar)
And that's it, you're up and running.
Thanks a lot,
Jonathan
________________________________
De: Florent Guillaume [mailto:fg at nuxeo.com]
Date: sam. 17/03/2007 01:47
À: Winterflood, Jonathan
Cc: cps-devel at lists.nuxeo.com
Objet : Re: [CPS-devel] breaking code up into seperate files
Please have a look at CPSUtil, where a lot of functions are provided
the way you want.
1. put the function in a foo.py file
2. put the proper ModuleSecurityInfo(...).declarePublic(...) to make
it importable by restricted code
3. import foo.py from your __init__.py so that the security
declaration is read by zope.
Florent
On 16 Mar 2007, at 18:12, Winterflood, Jonathan wrote:
> Hi all,
>
> I have a number of .py files in my product that need to use the
> same set of functions; So far i've been resorting to copy/paste to
> make them work...
>
> Obviously this isn't a good idea, so i created a file containing
> (so far) one function
> this file is placed at the root of my product, and is organised as
> such:
>
> """ my file's comment
> """
>
> def myfunc():
> """myfunc's comment
> """
> etc...
>
> EOF(myfile.py)
>
> To use this, I'm trying to import it in the .py that's using it:
> from myfile import myfunc
>
> This gives me a traceback whenever I try to use it...:
> ImportError: import of "csv_render" is unauthorized
>
> What should I do to allow the import?
>
> TIA,
> Jonathan
> This message contains information that may be privileged or
> confidential and is the property of the Capgemini Group. It is
> intended only for the person to whom it is addressed. If you are
> not the intended recipient, you are not authorized to read, print,
> retain, copy, disseminate, distribute, or use this message or any
> part thereof. If you receive this message in error, please notify
> the sender immediately and delete all copies of this message.
>
> _______________________________________________
> cps-devel mailing list
> http://lists.nuxeo.com/mailman/listinfo/cps-devel
--
Florent Guillaume, Director of R&D, Nuxeo
Open Source Enterprise Content Management (ECM)
http://www.nuxeo.com <http://www.nuxeo.com/> http://www.nuxeo.org <http://www.nuxeo.org/> +33 1 40 33 79 87
This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.nuxeo.com/pipermail/cps-devel/attachments/20070319/eec867ef/attachment.html
This list archive provided by Nuxeo, the
leaders of open source ECM.
Check out the Nuxeo 5 open source,
standards-based ECM project.