Permissions, files and folders
Hi! I just started looking at zope, so this might be a pretty nooby question, but I didnt find an answere anywhere, so... I want to create a DTML Method that lists the files in a folder that the current user has access to. Problem is that the objectValues-method returns all files simultaniously, so I get a AccessControl.unauthorized.Unauthorized exception when I call the method. I did a litle python script that iterates over the objectValues and catches the errors raised from unauthorized files as folows: files = [] fileIterator = iter(container.objectValues('File')) while True: try: files.append(fileIterator.next()) except Exception, e: if isinstance(e,StopIteration): break else: files.append(e) return files This works fine, except that it's a bit clumsy and has one big error; I catch just any exception that arises from the files.append(fileIterator.next())-call, and swallow it. I've tried catching only the Unauthorized-exception, but an anonymus user does not have access to the Unauthorized-exception, so I can't specify is in my except-declaration without getting a new authorization error. All thaw it works fine to catch all exceptions for a simple directory listing like this, its defiantly nothing I wanna put into a larger application. So my question is, how do I do this in a nicer way? Thanx /Erik
Erik Billing wrote at 2006-4-10 20:38 +0200:
... This works fine, except that it's a bit clumsy and has one big error; I catch just any exception that arises from the files.append(fileIterator.next())-call, and swallow it.
In fact, you should *NEVER* do this.
I've tried catching only the Unauthorized-exception, but an anonymus user does not have access to the Unauthorized-exception, so I can't specify is in my except-declaration without getting a new authorization error.
The "README" in "Products/PythonScripts" (unmong others) tells you how to allow the import of usually protected ressources. -- Dieter
On 4/11/06, Dieter Maurer <dieter@handshake.de> wrote:
Erik Billing wrote at 2006-4-10 20:38 +0200:
... This works fine, except that it's a bit clumsy and has one big error; I catch just any exception that arises from the files.append(fileIterator.next())-call, and swallow it.
In fact, you should *NEVER* do this.
I totally agree
I've tried catching only the Unauthorized-exception, but an
anonymus user does not have access to the Unauthorized-exception, so I can't specify is in my except-declaration without getting a new authorization error.
The "README" in "Products/PythonScripts" (unmong others) tells you how to allow the import of usually protected ressources.
-- Dieter
Thanx, it worked fine when I allowed the unauthorized module, but I still wonder if this is the way I *should* do it, is there no easier way that does not incorporate an python script (or a similar clumsy dtml solution). It just feels a little overkill to write a specific script just to access the files in a directory. /Erik
Erik Billing wrote at 2006-4-16 18:55 +0200:
... Thanx, it worked fine when I allowed the unauthorized module, but I still wonder if this is the way I *should* do it, is there no easier way that does not incorporate an python script (or a similar clumsy dtml solution). It just feels a little overkill to write a specific script just to access the files in a directory.
You can use the "LazyFilter" from the "ZTUtils" package. In fact, it is defined in "ZTUtils.Zope" (but exported via "ZTUtils") and you can look there for its signature. -- Dieter
Thank you, that worked nicely. But I was unable to call the LazyFilter from the DTML document, I figure I have to import the ZTUtils module first. Is there a special DTML-tag to do import? By the way? Is there some obvious documentation about the different modules that I have missed? As I mentioned in an earlier letter I'm new to Zope and I find it very hard to get an overview of all the different modules available. It seams to me that the API Reference on the zope home page does not cover the modules completely. For example, I found ZTUtils listed, but it only contains the Batch class, not the LazyFilter or any of the other classes in the module. I feel that this is the case with many of the modules. Is there any complete api reference avalible? Best regards /Erik On 4/17/06, Dieter Maurer <dieter@handshake.de> wrote:
Erik Billing wrote at 2006-4-16 18:55 +0200:
... Thanx, it worked fine when I allowed the unauthorized module, but I still wonder if this is the way I *should* do it, is there no easier way that does not incorporate an python script (or a similar clumsy dtml solution). It just feels a little overkill to write a specific script just to access the files in a directory.
You can use the "LazyFilter" from the "ZTUtils" package. In fact, it is defined in "ZTUtils.Zope" (but exported via "ZTUtils") and you can look there for its signature.
-- Dieter
I recommend to install DocFinderTab. And there is something at http:// api.plone.org/ for those who like such things ;-) Stefan On 18. Apr 2006, at 13:21, Erik Billing wrote:
Is there any complete api reference avalible?
-- Anything that happens, happens. --Douglas Adams
Ah! Thanx! DocFinder will shore come very useful in time =) Btw, what editor would you recommend for writing python outside Zope. I've frequently used Eclipse with PyDev before, but it's a bit slow and heavy. I've looked around a bit on the free editors without finding anything I like so I'm thinking it might be worth trying a commercial editor. What do you guys use? /Erik On 4/20/06, Stefan H. Holek <stefan@epy.co.at> wrote:
I recommend to install DocFinderTab. And there is something at http:// api.plone.org/ for those who like such things ;-)
Stefan
On 18. Apr 2006, at 13:21, Erik Billing wrote:
Is there any complete api reference avalible?
-- Anything that happens, happens. --Douglas Adams
Erik Billing schrieb:
Ah! Thanx! DocFinder will shore come very useful in time =)
Btw, what editor would you recommend for writing python outside Zope. I've frequently used Eclipse with PyDev before, but it's a bit slow and heavy. I've looked around a bit on the free editors without finding anything I like so I'm thinking it might be worth trying a commercial editor. What do you guys use?
Linux/KDE: kate and/or eric3 (nice because of seamless sftp/webdav) Linux: vim, some will use (x)emacs, pida Windows: hm. I've used the ide that comes with the win32 extensions from Marc Hammond. You bend some paths and get nice module view and hinting for zope classes too. Regards Tino
On Friday 21 April 2006 10:15, Tino Wildenhain wrote:
Erik Billing schrieb:
Ah! Thanx! DocFinder will shore come very useful in time =)
Btw, what editor would you recommend for writing python outside Zope. I've frequently used Eclipse with PyDev before, but it's a bit slow and heavy. I've looked around a bit on the free editors without finding anything I like so I'm thinking it might be worth trying a commercial editor. What do you guys use?
Linux/KDE: kate and/or eric3 (nice because of seamless sftp/webdav) Linux: vim, some will use (x)emacs, pida
Windows: hm. I've used the ide that comes with the win32 extensions from Marc Hammond. You bend some paths and get nice module view and hinting for zope classes too.
I've used WingIDE a bit lately and am quite impressed by its feature set: * Good editor: Syntax coloring, folding, autocompletion, ... * Auto-lookup of documentation * Visual Debugger: watches, breakpoints, lots of goodies * Code / Class browser * Zope support Last but not least: great support staff. It uses quite a bit of resources though. Review of Python IDEs: http://spyced.blogspot.com/2005/09/review-of-6-python-ides.html peter.
Regards Tino
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
On Fri, Apr 21, 2006 at 09:54:15AM +0200, Erik Billing wrote:
Btw, what editor would you recommend for writing python outside Zope. I've frequently used Eclipse with PyDev before, but it's a bit slow and heavy. I've looked around a bit on the free editors without finding anything I like so I'm thinking it might be worth trying a commercial editor. What do you guys use?
Emacs :-) It takes a bit of work to get it set up nicely, but there are some really nice features like good pdb integration. e.g. try this: put a "pdb.set_trace()" somewhere in your code, and then run the program from a shell within emacs - e.g. you can start a shell by typing "M-x shell", and then type the command to run your program. When you enter pdb, you can step around the code and emacs shows you where you are in another buffer, opening modules as you step into them. I've said it before: All hail Ken Manheimer! I'm sure plenty of IDEs can do stuff like that, but I'm surprised how many emacs users don't seem to know it's there. (dunno if all that works on Windows, never tried.) The code-completion support is pretty rudimentary, though. It seems to only be good for repeating symbols already in your source file. And no built-in browsing of documentation afaict. -- Paul Winkler http://www.slinkp.com
participants (6)
-
Dieter Maurer -
Erik Billing -
Paul Winkler -
Peter Sabaini -
Stefan H. Holek -
Tino Wildenhain