hi ken, very often you can replace context with self. so instead of context.REQUEST you use self.REQUEST. robert Ken Winter schrieb: > I'm customizing a product. To do what I'm trying to do, I need to be able > to access REQUEST data from within a Python module (not a script; a .py file > containing class and method definitions). > >>From within a script, a line like > > req = context.REQUEST > > does the job just fine. But when I put that line into my product module, I > get a message like: > > Name "context" not defined > > and I don't see any way to import that into my module. > > At (http://www.plope.com/Books/2_7Edition/AppendixB.stx#0-8), the Zope API > Reference describes the module "HTTPRequest", which includes the class that > it calls "HTTPRequest(BaseRequest)", which apparently is the equivalent of > REQUEST as described above. I have put this line into my module: > > from ZPublisher.HTTPRequest import HTTPRequest > > but now I don't know how to reference the request's contents. I put in this > line: > > req = HTTPRequest > > and print "req" to a debug file, and it shows: > > ZPublisher.HTTPRequest.HTTPRequest > > which I don't understand. I have tried a half-dozen ways (suggested by the > Zope API Reference) to get an actual property of the current HTTPRequest, > but without success. Examples: > > req['URL'] -> "TypeError: unsubscriptable object" > req.get('URL') -> "TypeError: unbound method get() must be called > with HTTPRequest instance as first argument (got str instance > instead)" > req.keys() -> "TypeError: unbound method keys() must be called with > HTTPRequest instance as first argument (got nothing instead)" > > The last two suggest that, while I have successfully imported the > HTTPRequest *class*, I haven't successfully gotten the current HTTPRequest > *instance*. I don't know how to do that. > > So, I need an answer to any one of these questions: > > 1. How can the Zope global name "context" be defined or imported into a > non-script Python module? > > 2. How can one get the current instance of the class "HTTPRequest" into a > non-script Python module? > > 3. If I'm looking in the wrong direction, what is the right way to make the > current REQUEST's data available in a non-script Python module? > > ~ TIA > ~ Ken > > > _______________________________________________ > Zope maillist - [email protected] > 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 ) >
begin:vcard fn:Robert Rottermann n: Rottermann;Robert email;internet:[EMAIL PROTECTED] tel;work:++41 31 333 10 20 tel;fax:++41 31 333 10 23 tel;home:++41 31 333 36 03 x-mozilla-html:FALSE version:2.1 end:vcard
_______________________________________________ Zope maillist - [email protected] 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 )
