Python -> ZopePython cheat sheet?
I am *so* used to just being able to explore around my Python interpreter and having everything I need documentation-wise in the global module index of the library reference manual that I am finding the whole Zope experience incredibly frustrating. Is there no equivalent of dir() or type() which I can use from a Python script to find out what the heck I've been passed? Assuming there is some way to find out what I've gote, is there something like Python's global module index where I can just click on "Formulator" or "container" and get some documentation useful to a Python programmer? frustrated-in-evanston... -- Skip Montanaro - skip@pobox.com http://www.mojam.com/ http://www.musi-cal.com/
You may want to try out Dieter Maurer's DocFinder product (http://www.dieter.handshake.de/pyprojects/zope/DocFinder.html). Otherwise the help system and the Zope Book appendices are what you've got. Note that there is a fairly extensive API reference in the help system. Were you successful at accessing your Zope objects in a Python prompt? Were you able to glean this from some of the other things that were sent your way last week: cd ZOPEHOME/lib/python python
import Zope app = Zope.app() app.objectIds() ['standard_error_message', ...]
You can explore Zope objects via a command-line this way. HTH, - C ----- Original Message ----- From: "Skip Montanaro" <skip@pobox.com> To: <zope@zope.org> Sent: Monday, November 04, 2002 6:16 PM Subject: [Zope] Python -> ZopePython cheat sheet?
I am *so* used to just being able to explore around my Python
interpreter
and having everything I need documentation-wise in the global module index of the library reference manual that I am finding the whole Zope experience incredibly frustrating. Is there no equivalent of dir() or type() which I can use from a Python script to find out what the heck I've been passed? Assuming there is some way to find out what I've gote, is there something like Python's global module index where I can just click on "Formulator" or "container" and get some documentation useful to a Python programmer?
frustrated-in-evanston...
-- Skip Montanaro - skip@pobox.com http://www.mojam.com/ http://www.musi-cal.com/
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Chris> You may want to try out Dieter Maurer's DocFinder product Chris> (http://www.dieter.handshake.de/pyprojects/zope/DocFinder.html). Thanks, I'll give it a look. Chris> Otherwise the help system and the Zope Book appendices are what Chris> you've got. Note that there is a fairly extensive API reference Chris> in the help system. This part is frustrating. Stuff seems to be scattered all over the place. Part of my frustration is that when I find something that looks promising I generally have to figure out what the page template equivalent of a dtml example is. I really don't want to wade into dtml again. I used it for a few years outside of Zope and didn't like it. Chris> Were you successful at accessing your Zope objects in a Python Chris> prompt? Yes, thanks. I can get to the static stuff without too much trouble using the medusa/monitor_client script. It's a tad frustrating to not have readline, but I guess that's the price I have to pay for using a canned install on a not-quite-yet wrung out platform (MacOSX). Perhaps I can coax IPython or pyrepl into working for me. I haven't yet tried submitting a form with several fields. I anticipate that will be tedious. Is there some way I can make dir() and type() available to scripts for development purposes and make sys importable once again? -- Skip Montanaro - skip@pobox.com http://www.mojam.com/ http://www.musi-cal.com/
On Mon, 2002-11-04 at 20:09, Skip Montanaro wrote:
This part is frustrating. Stuff seems to be scattered all over the place. Part of my frustration is that when I find something that looks promising I generally have to figure out what the page template equivalent of a dtml example is. I really don't want to wade into dtml again. I used it for a few years outside of Zope and didn't like it.
Uh huh. Stuff is scattered all over the place. The Zope Book is a best-effort attempt at bringing a lot of it together.
Chris> Were you successful at accessing your Zope objects in a Python Chris> prompt?
Yes, thanks. I can get to the static stuff without too much trouble using the medusa/monitor_client script. It's a tad frustrating to not have readline, but I guess that's the price I have to pay for using a canned install on a not-quite-yet wrung out platform (MacOSX). Perhaps I can coax IPython or pyrepl into working for me. I haven't yet tried submitting a form with several fields. I anticipate that will be tedious.
You can have readline and whatnot by following the steps I outlined in my last email instead of going in to the monitor client. If you're using ZEO, you can even be connected to a database that is currently in use by a running Zope instance. It's particularly nice if you run Zope under emacs shell-mode and have Ken Manheimer's pdbtrack installed. When a pdb session is fired up, it tracks the progress of the code in a separate window.
Is there some way I can make dir() and type() available to scripts for development purposes and make sys importable once again?
Not without hacking source, but if you go into ZOPEHOME/lib/python/RestrictedPython, you can add them to the "safe_builtins" module-level global. This is not recommended. Instead, use an external method or write a Python product. See the Zope Developer's guide on how to write a Python product and the Zope Book 2.6 edition on how to write an external method. - C
Chris> You can have readline and whatnot by following the steps I Chris> outlined in my last email instead of going in to the monitor Chris> client. The version of Python 2.1 which ships with the Plone MacOSX installer doesn't have a readline module with it, and doesn't seem to have shipped with complete sources, so it seemed like six of one half a dozeon of the other to me. I've just built a readline.so using a source version of 2.1.3. That seems to work. I don't understand how your scheme works to talk to a running Zope instance though. I don't have ZEO and by the time I can figure out how to install and use it, I suspect I will have fumbled around enough with the monitor client to figure out what I need. >> Is there some way I can make dir() and type() available to scripts >> for development purposes and make sys importable once again? Chris> Not without hacking source, That seems a helluva a lot easier than some of the other hoops I'm having to jump through. Chris> but if you go into ZOPEHOME/lib/python/RestrictedPython, you can Chris> add them to the "safe_builtins" module-level global. This is not Chris> recommended. Instead, use an external method or write a Python Chris> product. See the Zope Developer's guide on how to write a Python Chris> product and the Zope Book 2.6 edition on how to write an external Chris> method. This is as trivial as adding two strings to a list? I don't think so... I'm only interested in this for my development machine, which is a single-user machine sitting behind a NAT box. I doubt the security risk is significant.
From where I sit it seems Zope needs some serious work on its debugging capabilities. At a minimum, giving people the option of starting up Zope with a flag that returns control of their Python interpreter to them would be a good first step.
Skip
On Tue, 2002-11-05 at 11:55, Skip Montanaro wrote:
The version of Python 2.1 which ships with the Plone MacOSX installer doesn't have a readline module with it, and doesn't seem to have shipped with complete sources, so it seemed like six of one half a dozeon of the other to me. I've just built a readline.so using a source version of 2.1.3.
Ah ok.
That seems to work. I don't understand how your scheme works to talk to a running Zope instance though. I don't have ZEO and by the time I can figure out how to install and use it, I suspect I will have fumbled around enough with the monitor client to figure out what I need.
The monitor client is pretty crippled (I suspect you'll see this once you start really using it) because of its traceback output and whatnot (truncated tracebacks, from what I remember). To avoid this, I recommend "importing Zope" in an interactive Python session instead. "cd lib/python; python; import Zope; app = Zope.app()". The only problem with this is that Zope cannot be running at the time you do this unless you're running ZEO. If you really want to inspect a running Zope, I have to recommend spending the time to install ZEO. It's really very easy to install if you follow the instructions in the tarball within http://www.zope.org/Products/ZEO/ZEO-2.0.tar.gz/view .
>> Is there some way I can make dir() and type() available to scripts >> for development purposes and make sys importable once again?
Chris> Not without hacking source,
That seems a helluva a lot easier than some of the other hoops I'm having to jump through.
Hope it works out.
From where I sit it seems Zope needs some serious work on its debugging capabilities. At a minimum, giving people the option of starting up Zope with a flag that returns control of their Python interpreter to them would be a good first step.
This is the "cd lib/python; python; import Zope; app = Zope.app()" trick that I mention above and I've sent in other emails. Upcoming versions of Zope will likely ship with a utility to make this less obscure by providing a frontend controller application to Zope named "zctl" that you can run to do this by doing "./zctl debug". This feature is currently in-place in a branch of Zope I'm doing work on (chrism-install-branch). - C
Chris> The monitor client is pretty crippled (I suspect you'll see this Chris> once you start really using it) because of its traceback output Chris> and whatnot (truncated tracebacks, from what I remember). I rather like Medusa's abbreviated tracebacks. ;-) I'll look into ZEO. Skip
Is there some way I can make dir() and type() available to scripts for development purposes and make sys importable once again?
As Chris said, you need an external method (due to security concerns). Just like this: 1. Create the following script: # helpers.py def dir_this(ob): return dir(ob) def type_this(ob): return type(ob) 2. Save the preceeding script 'helpers.py' in the 'Extensions' folder of your Zope instance. 3. In the root of the Zope Management Interface (ZMI) add an External Method with the id of the first of the two methods you need. (You may use a different id as well): id: dir_this title: any title module name: helpers (without the extension) function: dir_this 4. Repeat the same thing for 'type_this' 5. Now you're ready to use dir() and type() within your code: PythonScript: context.dir_this(object) context.type_this(object) DTML: <dtml-var "dir_this(object)"> <dtml-var "type_this(object)"> 6. Last but not least, make sure only managers have access to these methods, at its 'Security' tabs. Ausum
>> Is there some way I can make dir() and type() available to scripts >> for development purposes and make sys importable once again? Thanks for the external method tutorial. Worked like a charm. Ausum> As Chris said, you need an external method (due to security Ausum> concerns). But why can't Zope let me decide what my security tradeoffs are? It's fine that I can't execute any of dir(foo) type(foo) foo.__class__ by default, but why can't there be some simple way to say, "I'm debugging and I know what the risks are. Give me an interpreter that isn't crippled." Adding dir() and type() back in were trivial edits, but making foo.__class__ available is more difficult than just messing with checkAttrName. (Thankfully, an external method worked here.) -- Skip Montanaro - skip@pobox.com http://www.mojam.com/ http://www.musi-cal.com/
You might benefit from the following: http://www.zope.org/Members/4am/XXXPythonScripts hth, -Casey On Tuesday 05 November 2002 12:17 pm, Skip Montanaro wrote:
>> Is there some way I can make dir() and type() available to scripts >> for development purposes and make sys importable once again?
Thanks for the external method tutorial. Worked like a charm.
Ausum> As Chris said, you need an external method (due to security Ausum> concerns).
But why can't Zope let me decide what my security tradeoffs are? It's fine that I can't execute any of
dir(foo) type(foo) foo.__class__
by default, but why can't there be some simple way to say, "I'm debugging and I know what the risks are. Give me an interpreter that isn't crippled." Adding dir() and type() back in were trivial edits, but making foo.__class__ available is more difficult than just messing with checkAttrName. (Thankfully, an external method worked here.)
-- Skip Montanaro - skip@pobox.com http://www.mojam.com/ http://www.musi-cal.com/
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Chris had some good suggestions. I would also suggest reading the source whenever necessary. It can be hard to find things at first but most of the code is pretty straight forward. It's also good to read the code of other products and sites, of course. And never underestimate the value of: <dtml-var REQUEST> to tell you what's going on.
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Skip Montanaro Sent: Monday, November 04, 2002 3:17 PM To: zope@zope.org Subject: [Zope] Python -> ZopePython cheat sheet?
I am *so* used to just being able to explore around my Python interpreter and having everything I need documentation-wise in the global module index of the library reference manual that I am finding the whole Zope experience incredibly frustrating. Is there no equivalent of dir() or type() which I can use from a Python script to find out what the heck I've been passed? Assuming there is some way to find out what I've gote, is there something like Python's global module index where I can just click on "Formulator" or "container" and get some documentation useful to a Python programmer?
frustrated-in-evanston...
-- Skip Montanaro - skip@pobox.com http://www.mojam.com/ http://www.musi-cal.com/
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
participants (5)
-
Ausum Studio -
Casey Duncan -
Charlie Reiman -
Chris McDonough -
Skip Montanaro