FQ Path Names in container
Goal: Serve 'protected' documents via a Python Script in Zope. The concept is that you'll actually access the script and, if it decides you're authorized, will give you the documents. Problem: Returning a document that's in the same directory as the script is a no-brainer -- return container['docname'] works perfectly well. Returning a document that is in a relative directory is also not a problem -- Assuming this directory structure: / A B C.pdf (1) D A B C.pdf (2) C.pdf (3) script Then if we're accessing /D/script and returning 'container['C.pdf']' we'll return C.pdf(3); if we return 'container['A/B/C.pdf'] then we'll return C.pdf(2) (acquisition is a beautiful thing). However, returning 'container['A/B/C.pdf'] gives me a key error. This makes it rather difficult to access C.pdf(1). I have two possibilities: A) Figure out how to use fully qualified paths in my return statement; B) Do something interesting with acquisition and URLs -- something like calling /A/B/D/script, having script figure out its context is actually /A/B, and then return the C.pdf in that directory. Unfortunately, reading both the Zope book and the Zope Web Application Development and Content Management book did not reveal to me how I'd go about doing it, and my random stumbling around and attempts to get this done have not worked successfully. Suggestions? -roy Content-Type: text/plain; charset="iso-8859-1" ------------------------------------------------- PLEASE READ THIS WARNING: All e-mail sent to or from this address will be received or otherwise recorded by the Fisher Investments corporate e-mail system and is subject to archival, monitoring or review by, and/or disclosure to, someone other than the recipient.
Then if we're accessing /D/script and returning 'container['C.pdf']' we'll return C.pdf(3); if we return 'container['A/B/C.pdf'] then we'll return C.pdf(2) (acquisition is a beautiful thing).
However, returning 'container['A/B/C.pdf'] gives me a key error. This makes it rather difficult to access C.pdf(1).
Naturally. You're trying to access a thing called ay-slash-be-slash-see-dot-pee-dee-eff. And it's not there. If you want to get substructures in Python, you can do one of these things: container.A.B.C # can't go to something with a dot in the name container.A.B['C.pdf'] container['A']['B']['C.pdf'] container.restrictedTraverse('A/B/C.pdf') Restricted traverse is probably the best way to deal with a variable path, as you seem to have. See also: http://www.zopelabs.com/cookbook/1001104105 http://www.zopelabs.com/cookbook/1032051886 --jcc
participants (2)
-
J Cameron Cooper -
Roy Rapoport