Re: [Zope-dev] More almost __call__ ;-)

2000-10-13 Thread Shane Hathaway

Jim Fulton wrote:
> The fact that ZPublisher will pass it is documented.  Whether
> or not something else calls it is up to the something else.
> The method designer specified an interface that includes RESPONSE.
> If it requires RESPONSE, by not specifying a default, then it
> requires the clients to oass it. If the clients don't, then they
> are not satisfying the interface.  Are you saying that objects
> that require that RESPONSE is passed are broken because they don't
> sufficiently advertise the fact?

I'm saying that there are some methods which expect the RESPONSE to be
passed only when called by ZPublisher.  They expect RESPONSE to be
"None" when called as a subtemplate or otherwise.  The only problem is
that this convention is not enforced.

But we've strayed... :-)

Shane

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )




Re: [Zope-dev] More almost __call__ ;-)

2000-10-13 Thread Jim Fulton

Shane Hathaway wrote:
> 
> Jim Fulton wrote:
> >
> > Shane Hathaway wrote:
> > >
> > > Jim Fulton wrote:
> > > > Note that if you get called from the web, RESPONSE will
> > > > not be none. This is a handy way to decide if you
> > > > are called from the web or as a sub-template. Of course,
> > > > someone could pass a non-None RESPONSE argument directly.
> > >
> > > This convention is helpful but not at all documented, so products (ZWiki
> > > is a good example) often break this convention.
> >
> > Which convention? The passing of arguments with names meaningful to
> > the publisher is certainly well documented.
> 
> No, I was referring to the convention of RESPONSE being passed only if
> ZPublisher is calling the method.  It is not documented and often
> broken.

The fact that ZPublisher will pass it is documented.  Whether
or not something else calls it is up to the something else.
The method designer specified an interface that includes RESPONSE.
If it requires RESPONSE, by not specifying a default, then it 
requires the clients to oass it. If the clients don't, then they
are not satisfying the interface.  Are you saying that objects
that require that RESPONSE is passed are broken because they don't
sufficiently advertise the fact?

Jim

--
Jim Fulton   mailto:[EMAIL PROTECTED]   Python Powered!
Technical Director   (888) 344-4332http://www.python.org  
Digital Creationshttp://www.digicool.com   http://www.zope.org

Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email
address may not be added to any commercial mail list with out my
permission.  Violation of my privacy with advertising or SPAM will
result in a suit for a MINIMUM of $500 damages/incident, $1500 for
repeats.

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )




Re: [Zope-dev] More almost __call__ ;-)

2000-10-13 Thread Shane Hathaway

Jim Fulton wrote:
> 
> Shane Hathaway wrote:
> >
> > Jim Fulton wrote:
> > > Note that if you get called from the web, RESPONSE will
> > > not be none. This is a handy way to decide if you
> > > are called from the web or as a sub-template. Of course,
> > > someone could pass a non-None RESPONSE argument directly.
> >
> > This convention is helpful but not at all documented, so products (ZWiki
> > is a good example) often break this convention.
> 
> Which convention? The passing of arguments with names meaningful to
> the publisher is certainly well documented.

No, I was referring to the convention of RESPONSE being passed only if
ZPublisher is calling the method.  It is not documented and often
broken.

Shane

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )




Re: [Zope-dev] More almost __call__ ;-)

2000-10-13 Thread Jim Fulton

Shane Hathaway wrote:
> 
> Jim Fulton wrote:
> >
> > Chris Withers wrote:
> > >
> > > Toby Dickenson wrote:
> > > > 
> > > >
> > > > you would use
> > > >
> > > > def a_method(self,md):
> > > > do_stuff_with(md['param1'],md['param2'])
> > > > a_method = FunctionTemplate(a_method)
> > >
> > > That looks like it'll do the trick... I wonder if there's any way you
> > > can role it up into a Product so that I don't need to have
> > > FunctionTemplate.py in each folder of a product that needs to use it?
> >
> > Is it *really* the case that you often want to method to be called directly
> > via the Web *and* and from DTML?  This doesn't seem right to me.
> 
> As I understand it, that's not the issue.  Chris wants to receive the
> DTML namespace implicitly.
> 
> > In any case, if you *just* want to get your function to be
> > called from DTML (and your class is an extension class), you can give
> > it the isDocTemp attribute like so:
> >
> >   class MyClass( include some extension class ...):
> >
> > some_methodisDocTemp=1
> > def some_method(trueself, self, REQUEST, RESPONSE=None):
> > 
> 
> That's a good idea, I wish I'd thought of it. :-)
> 
> However, the new calling convention (__render_with_namespace__, or
> something like that) might break "isDocTemp" code.

I thought of that, but I don't think so. There are obviously 
enough people using the isDocTemp thing that we'll probably need to
keep supporting it.  The use of a separate render method won't be
convenient for iplementing simple methods. Not that that is necessarily
that critical.

> > Note that if you get called from the web, RESPONSE will
> > not be none. This is a handy way to decide if you
> > are called from the web or as a sub-template. Of course,
> > someone could pass a non-None RESPONSE argument directly.
> 
> This convention is helpful but not at all documented, so products (ZWiki
> is a good example) often break this convention.

Which convention? The passing of arguments with names meaningful to
the publisher is certainly well documented.

Jim

--
Jim Fulton   mailto:[EMAIL PROTECTED]   Python Powered!
Technical Director   (888) 344-4332http://www.python.org  
Digital Creationshttp://www.digicool.com   http://www.zope.org

Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email
address may not be added to any commercial mail list with out my
permission.  Violation of my privacy with advertising or SPAM will
result in a suit for a MINIMUM of $500 damages/incident, $1500 for
repeats.

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )




Re: [Zope-dev] More almost __call__ ;-)

2000-10-13 Thread Jim Fulton

Chris Withers wrote:
> 
> Jim Fulton wrote:
> 
> > In any case, if you *just* want to get your function to be
> > called from DTML (and your class is an extension class), you can give
> > it the isDocTemp attribute like so:
> >
> >   class MyClass( include some extension class ...):
> >
> > some_methodisDocTemp=1
> > def some_method(self, ignored, md):
> 
> great :-) that did the trick, thanks...
> 
> I can't help but feel this woudl all be so much simpler if it was
> documented somewhere for idiots like me :-S

Well, it *is* documented somewhere. (In the ExtensionClass
documentation), but not somewhere where you were likely to find it.

Jim


--
Jim Fulton   mailto:[EMAIL PROTECTED]   Python Powered!
Technical Director   (888) 344-4332http://www.python.org  
Digital Creationshttp://www.digicool.com   http://www.zope.org

Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email
address may not be added to any commercial mail list with out my
permission.  Violation of my privacy with advertising or SPAM will
result in a suit for a MINIMUM of $500 damages/incident, $1500 for
repeats.

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )




Re: [Zope-dev] More almost __call__ ;-)

2000-10-13 Thread Shane Hathaway

Toby Dickenson wrote:
> 
> > Is it *really* the case that you often want to method to be
> > called directly
> > via the Web *and* and from DTML?  This doesn't seem right to me.
> 
> Im suprised that you are suprised. Consider a method called 'summary' that
> returns a plain-text summary of an object. Thats useful to call from DTML
> (maybe assembling a summary of several objects), via xmlrpc, and directly
> from ZPublisher (by browsing to the url of the method).

I'd like to refer you to a discussion we're having.

http://dev.zope.org/Wikis/DevSite/Projects/CacheManager/Architecture

The issue is that since a called object has no idea who called it (nor
should it know IMHO), it has no idea whether it is appropriate to set
response headers that apply to HTTP caches.  Headers should be set only
if the object was invoked by ZPublisher.

In most cases this is not an issue since cache setup is performed by a
human who knows which objects are supposed to be published and which are
not.  However, I think the possibility for side effects (where a piece
of a page inappropriately generates response headers) is great enough to
warrant a separate API call.  This can happen when an object is set up
with a cache manager but later repurposed.

Consider that in the current version of PythonMethod, the document_src()
method sets the Content-Type header whether it was invoked through
ZPublisher or not.  When DTML invokes document_src(), this has the
effect of causing all HTML on the resulting page to be rendered as
"text/plain".  Note that cache headers can be harder to debug than
content-type headers, and that this mistake was made by one of the
brightest hackers I know. :-)

Shane

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )




Re: [Zope-dev] More almost __call__ ;-)

2000-10-13 Thread Shane Hathaway

Jim Fulton wrote:
> 
> Chris Withers wrote:
> >
> > Toby Dickenson wrote:
> > > 
> > >
> > > you would use
> > >
> > > def a_method(self,md):
> > > do_stuff_with(md['param1'],md['param2'])
> > > a_method = FunctionTemplate(a_method)
> >
> > That looks like it'll do the trick... I wonder if there's any way you
> > can role it up into a Product so that I don't need to have
> > FunctionTemplate.py in each folder of a product that needs to use it?
> 
> Is it *really* the case that you often want to method to be called directly
> via the Web *and* and from DTML?  This doesn't seem right to me.

As I understand it, that's not the issue.  Chris wants to receive the
DTML namespace implicitly.

> In any case, if you *just* want to get your function to be
> called from DTML (and your class is an extension class), you can give
> it the isDocTemp attribute like so:
> 
>   class MyClass( include some extension class ...):
> 
> some_methodisDocTemp=1
> def some_method(trueself, self, REQUEST, RESPONSE=None):
> 

That's a good idea, I wish I'd thought of it. :-)

However, the new calling convention (__render_with_namespace__, or
something like that) might break "isDocTemp" code.

> Note that if you get called from the web, RESPONSE will
> not be none. This is a handy way to decide if you
> are called from the web or as a sub-template. Of course,
> someone could pass a non-None RESPONSE argument directly.

This convention is helpful but not at all documented, so products (ZWiki
is a good example) often break this convention.

Shane

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )




Re: [Zope-dev] More almost __call__ ;-)

2000-10-13 Thread Chris Withers

Jim Fulton wrote:

> In any case, if you *just* want to get your function to be
> called from DTML (and your class is an extension class), you can give
> it the isDocTemp attribute like so:
> 
>   class MyClass( include some extension class ...):
> 
> some_methodisDocTemp=1
> def some_method(self, ignored, md):

great :-) that did the trick, thanks...

I can't help but feel this woudl all be so much simpler if it was
documented somewhere for idiots like me :-S

cheers,

Chris

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )




RE: [Zope-dev] More almost __call__ ;-)

2000-10-13 Thread Toby Dickenson

> Is it *really* the case that you often want to method to be 
> called directly
> via the Web *and* and from DTML?  This doesn't seem right to me.

Im suprised that you are suprised. Consider a method called 'summary' that
returns a plain-text summary of an object. Thats useful to call from DTML
(maybe assembling a summary of several objects), via xmlrpc, and directly
from ZPublisher (by browsing to the url of the method).

Maybe this 'summary' method lets you pass some parameters to control the
level of detail of this summary.

These requirements are probably best satisfied using a plain python method,
which uses plain python parameters. So why use the dtml namespace at? The
only good reason is if the method was *previously* implemented in DTML (it
seemed a good idea at the time) and you want to replace it with python
without having to change all the dtml that uses it.


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )




Re: [Zope-dev] More almost __call__ ;-)

2000-10-13 Thread Chris Withers

Toby Dickenson wrote:
> 
> 
> you would use
> 
> def a_method(self,md):
> do_stuff_with(md['param1'],md['param2'])
> a_method = FunctionTemplate(a_method)

Okay, spoke too soon... when I do the above and then call the method
with:



I get:

Error type: exceptions.AttributeError
Error value: __len__ 

Traceback (innermost last):
  File E:\Zope\2271B4~1.2\lib\python\ZPublisher\Publish.py, line 222, in
publish_module
  File E:\Zope\2271B4~1.2\lib\python\ZPublisher\Publish.py, line 187, in
publish
  File E:\Zope\2271B4~1.2\lib\python\Zope\__init__.py, line 221, in
zpublisher_exception_hook
(Object: testdefiner)
  File E:\Zope\2271B4~1.2\lib\python\ZPublisher\Publish.py, line 171, in
publish
  File E:\Zope\2271B4~1.2\lib\python\ZPublisher\mapply.py, line 160, in
mapply
(Object: index_html)
  File E:\Zope\2271B4~1.2\lib\python\ZPublisher\Publish.py, line 112, in
call_object
(Object: index_html)
  File E:\Zope\2271B4~1.2\lib\python\App\special_dtml.py, line 120, in
__call__
(Object: index_html)
(Info: E:\Zope\2.2.2\lib\python\Products\A_product\Form.dtml)
  File E:\Zope\2.2.1\lib\python\Products\ZDebug\DTMLLocator.py, line
103, in __call__
(Object: index_html)
  File E:\Zope\2271B4~1.2\lib\python\DocumentTemplate\DT_String.py, line
528, in __call__
(Object: index_html)
  File E:\Zope\2.2.1\lib\python\Products\ZDebug\DTMLDebug.py, line 288,
in debug_render_blocks
  File E:\Zope\2.2.1\lib\python\Products\ZDebug\DTMLDebug.py, line 286,
in debug_render_blocks
  File E:\Zope\2271B4~1.2\lib\python\DocumentTemplate\DT_In.py, line
691, in renderwob
(Object: _.range(1,11))
  File E:\Zope\2.2.1\lib\python\Products\ZDebug\DTMLDebug.py, line 288,
in debug_render_blocks
  File E:\Zope\2.2.1\lib\python\Products\ZDebug\DTMLDebug.py, line 286,
in debug_render_blocks
  File E:\Zope\2271B4~1.2\lib\python\DocumentTemplate\DT_Let.py, line
147, in render
(Object: row=sequence-item)
  File E:\Zope\2.2.1\lib\python\Products\ZDebug\DTMLDebug.py, line 242,
in debug_render_blocks
  File E:\Zope\2.2.1\lib\python\Products\ZDebug\DTMLDebug.py, line 221,
in debugException
  File E:\Zope\2.2.1\lib\python\Products\ZDebug\DTMLDebug.py, line 239,
in debug_render_blocks
  File E:\Zope\2.2.2\lib\python\Products\A_product\FunctionTemplate.py,
line 38, in __call__
AttributeError: (see above)

What's going on?

cheers,

Chris

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )




Re: [Zope-dev] More almost __call__ ;-)

2000-10-13 Thread Jim Fulton

Chris Withers wrote:
> 
> Toby Dickenson wrote:
> > 
> >
> > you would use
> >
> > def a_method(self,md):
> > do_stuff_with(md['param1'],md['param2'])
> > a_method = FunctionTemplate(a_method)
> 
> That looks like it'll do the trick... I wonder if there's any way you
> can role it up into a Product so that I don't need to have
> FunctionTemplate.py in each folder of a product that needs to use it?

Is it *really* the case that you often want to method to be called directly
via the Web *and* and from DTML?  This doesn't seem right to me.

In any case, if you *just* want to get your function to be
called from DTML (and your class is an extension class), you can give
it the isDocTemp attribute like so:

  class MyClass( include some extension class ...):

some_methodisDocTemp=1
def some_method(self, ignored, md):


Methods in extension classes can have (read-only) attributes
by defining an attribute whose name is the concatenation of the
method name and the attribute name.  Note that the method is
also callable from the web as usual. If you want it to be called
the same way as a template, you'd need to use:

  class MyClass( include some extension class ...):

some_methodisDocTemp=1
def some_method(trueself, self, REQUEST, RESPONSE=None):


In this example, 'trueself' is bound by Python and is the traditional
python self. The 'self' argument gets bound by the publisher
to the object the method was invoked on.  

Note that if you get called from the web, RESPONSE will
not be none. This is a handy way to decide if you
are called from the web or as a sub-template. Of course,
someone could pass a non-None RESPONSE argument directly.

Jim

--
Jim Fulton   mailto:[EMAIL PROTECTED]   Python Powered!
Technical Director   (888) 344-4332http://www.python.org  
Digital Creationshttp://www.digicool.com   http://www.zope.org

Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email
address may not be added to any commercial mail list with out my
permission.  Violation of my privacy with advertising or SPAM will
result in a suit for a MINIMUM of $500 damages/incident, $1500 for
repeats.

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )




Re: [Zope-dev] More almost __call__ ;-)

2000-10-13 Thread Chris Withers

Toby Dickenson wrote:
> 
> > That looks like it'll do the trick... I wonder if there's any way you
> > can role it up into a Product so that I don't need to have
> > FunctionTemplate.py in each folder of a product that needs to use it?
> 
> Im working on a set of tools to aid my transition to a dtml-free Zope.
> Eventually I will package them all as a whole.



swt

Chris ;-)

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )




RE: [Zope-dev] More almost __call__ ;-)

2000-10-13 Thread Toby Dickenson

> That looks like it'll do the trick... I wonder if there's any way you
> can role it up into a Product so that I don't need to have
> FunctionTemplate.py in each folder of a product that needs to use it?

Im working on a set of tools to aid my transition to a dtml-free Zope.
Eventually I will package them all as a whole.

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )




Re: [Zope-dev] More almost __call__ ;-)

2000-10-13 Thread Chris Withers

Toby Dickenson wrote:
> 
> 
> you would use
> 
> def a_method(self,md):
> do_stuff_with(md['param1'],md['param2'])
> a_method = FunctionTemplate(a_method)

That looks like it'll do the trick... I wonder if there's any way you
can role it up into a Product so that I don't need to have
FunctionTemplate.py in each folder of a product that needs to use it?

cheers,

Chris

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )




Re: [Zope-dev] More almost __call__ ;-)

2000-10-13 Thread Toby Dickenson

On Fri, 13 Oct 2000 11:48:39 +0100, Chris Withers <[EMAIL PROTECTED]>
wrote:

>I have a Python Product Class, with a method, a_method, that gets called
>from some of the Python Product's management screens (encapsulation is
>good ;-)
>
>This method needs several parameters from the namespace, so when it's
>called I was hoping I wouldn't have to do something nasty and clunky
>like:
>
>
>
>Given my recently acquired __call__ Zen, I thought 'No problem...' and
>tried to define the method as follows:
>
>isDocTemplate = 1
>
>def a_method(self, ignored=None, md=None):
>
>...with the hope I'd just be able to do  and pluck
>the stuff from md.
>
>No dice.
>
>md and ignored turn up as None from all the  calls.
>:-(
>
>What am I doing wrong? How can I get access to the namespace in a method
>of a class like this?

You need to have the isDocTemplate=1 as an attribute of the method
object itself, not the class that contains the method.

You also need some extra voodoo if you want to call the method
directly from ZPublisher (by including the method name in a url). Here
a link to a wrapper that does it all



you would use

def a_method(self,md):
do_stuff_with(md['param1'],md['param2'])
a_method = FunctionTemplate(a_method)




Toby Dickenson
[EMAIL PROTECTED]

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )