Re: [Zope] __getitem__ and returning a PageTemplateFile instance

2005-10-21 Thread Anders Bruun Olsen
On Thu, Oct 20, 2005 at 09:43:24PM +0200, Dieter Maurer wrote:
 asonhe is not there, but vitester has a __getitem__ method which
 executes a PageTemplateFile instance and returns it. I.e.
 Thus, it returns a string.
 However, ZPublisher requires that all intermediate traversal
 steps return an object which is not of a simple type and does
 have a docstring. A string is a simple type, you cannot use it
 during traversal...

Ahh.. that makes sense I guess. It just seems counterintuitive that you
can return a string in a normal function, but not in __getitem__.

 But that way I can't put any values in there. How can I do this then?
 Can can return a wrapper and give it a docstring.
 class Wrapper:
   '''a wrapper around a string.''' # this is the docstring
   def __init__(self, str):
 self.str = str
   def __call__(self): return self.str
 Some security declarations might be necessary as well.
 Probably, a class attribute __roles__ = None is sufficient.

Okay, that will work.

Thanks so much for your help, I really appreciated it.

-- 
Anders
-BEGIN GEEK CODE BLOCK-
Version: 3.12
GCS/O d--@ s:+ a-- C++ UL+++$ P++ L+++ E- W+ N(+) o K? w O-- M- V
PS+ PE@ Y+ PGP+ t 5 X R+ tv+ b++ DI+++ D+ G e- h !r y?
--END GEEK CODE BLOCK--
PGPKey: 
http://random.sks.keyserver.penguin.de:11371/pks/lookup?op=getsearch=0xD4DEFED0
___
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 )


Re: [Zope] __getitem__ and returning a PageTemplateFile instance

2005-10-21 Thread Chris Withers

Anders Bruun Olsen wrote:


Ahh.. that makes sense I guess. It just seems counterintuitive that you
can return a string in a normal function, but not in __getitem__.


I have a feeling you're after traverse_subpath, which is available in 
both Python Scripts and Page Templates...


cheers,

Chris

--
Simplistix - Content Management, Zope  Python Consulting
   - http://www.simplistix.co.uk
___
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 )


Re: [Zope] __getitem__ and returning a PageTemplateFile instance

2005-10-21 Thread Dieter Maurer
Anders Bruun Olsen wrote at 2005-10-21 15:06 +0200:
 ...
Ahh.. that makes sense I guess. It just seems counterintuitive that you
can return a string in a normal function, but not in __getitem__.

Can can return a string from __getitem__ (without problem),
*but* you cannot use this string during URL traversal.

By the way, it does not matter for URL traversal whether the string (or
other simple type object or object without docstring) was
returned by __getitem__, getattr or __bobo_traverse__
(these are the possibilities to obtain the subobject during URL
traversal) -- the publisher will in all cases reject it.


-- 
Dieter
___
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 )


Re: [Zope] __getitem__ and returning a PageTemplateFile instance

2005-10-20 Thread Anders Bruun Olsen
On Wed, Oct 19, 2005 at 09:47:50PM +0200, Dieter Maurer wrote:
 Zope has encountered a problem publishing your object.
 Cannot locate object at: http://localhost:8080/vitester/asonhe 
 This is a NotFound problem.
Zope is unable to locate vitester/asonhe
 Are you sure, vitester/asonhe is there?

asonhe is not there, but vitester has a __getitem__ method which
executes a PageTemplateFile instance and returns it. I.e.

return self.test(self, self.REQUEST, value=value)
(where self.test is a PageTemplateFile)

It actually works if I just do:

return self.test.__of__(self)

But that way I can't put any values in there. How can I do this then?
Do I need to make a completely new custom item to return or what?

-- 
Anders
-BEGIN GEEK CODE BLOCK-
Version: 3.12
GCS/O d--@ s:+ a-- C++ UL+++$ P++ L+++ E- W+ N(+) o K? w O-- M- V
PS+ PE@ Y+ PGP+ t 5 X R+ tv+ b++ DI+++ D+ G e- h !r y?
--END GEEK CODE BLOCK--
PGPKey: 
http://random.sks.keyserver.penguin.de:11371/pks/lookup?op=getsearch=0xD4DEFED0
___
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 )


Re: [Zope] __getitem__ and returning a PageTemplateFile instance

2005-10-20 Thread Dieter Maurer
Anders Bruun Olsen wrote at 2005-10-20 11:52 +0200:
On Wed, Oct 19, 2005 at 09:47:50PM +0200, Dieter Maurer wrote:
 Zope has encountered a problem publishing your object.
 Cannot locate object at: http://localhost:8080/vitester/asonhe 
 This is a NotFound problem.
Zope is unable to locate vitester/asonhe
 Are you sure, vitester/asonhe is there?

asonhe is not there, but vitester has a __getitem__ method which
executes a PageTemplateFile instance and returns it. I.e.

Thus, it returns a string.

However, ZPublisher requires that all intermediate traversal
steps return an object which is not of a simple type and does
have a docstring. A string is a simple type, you cannot use it
during traversal...

return self.test(self, self.REQUEST, value=value)
(where self.test is a PageTemplateFile)

This results in a string (a simple type)...

It actually works if I just do:

return self.test.__of__(self)

This results in a PageTemplateFile, which has a docstring
and is not of simple type.

But that way I can't put any values in there. How can I do this then?

Can can return a wrapper and give it a docstring.

class Wrapper:
  '''a wrapper around a string.''' # this is the docstring

  def __init__(self, str):
self.str = str

  def __call__(self): return self.str

Some security declarations might be necessary as well.
Probably, a class attribute __roles__ = None is sufficient.

-- 
Dieter
___
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 )


Re: [Zope] __getitem__ and returning a PageTemplateFile instance

2005-10-19 Thread Anders Bruun Olsen
On Tue, Oct 18, 2005 at 08:47:23PM -0500, J Cameron Cooper wrote:
 error_log is by default set to ignore three common types of exceptions. 
 You should remove NotFound from the list if you're getting NotFound 
 exceptions and want to see them.
 Ahhh.. Thanks, now I have a traceback, unfortunately it didn't make it any
 more clear to me what the problem is.
 Traceback (innermost last):
   Module ZPublisher.Publish, line 104, in publish
   Module ZPublisher.BaseRequest, line 355, in traverse
   Module ZPublisher.HTTPResponse, line 651, in debugError
 In Zope 2.7, I see that line raising a debug error. Why it doesn't get 
 through I don't know, but here's what it says::
  The object at %s has an empty or missing  \
  docstring. Objects must have a docstring to be  \
  published. % URL
 That should help you, I think. All Zope objects that are to be published 
 to the web must have a docstring.

Thanks, but I do have a docstring on the __getitem__ in question.
This error is really starting to annoy me :-/.
If I return a custom object (i.e. a SimpleItem based class instance)
from __getitem__ it works fine, but if I return a PageTemplateFile
instance it screws up.

-- 
Anders
-BEGIN GEEK CODE BLOCK-
Version: 3.12
GCS/O d--@ s:+ a-- C++ UL+++$ P++ L+++ E- W+ N(+) o K? w O-- M- V
PS+ PE@ Y+ PGP+ t 5 X R+ tv+ b++ DI+++ D+ G e- h !r y?
--END GEEK CODE BLOCK--
PGPKey: 
http://random.sks.keyserver.penguin.de:11371/pks/lookup?op=getsearch=0xD4DEFED0
___
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 )


Re: [Zope] __getitem__ and returning a PageTemplateFile instance

2005-10-19 Thread Dieter Maurer
Anders Bruun Olsen wrote at 2005-10-17 00:59 +0200:
 
Zope has encountered a problem publishing your object.

Cannot locate object at: http://localhost:8080/vitester/asonhe 

This is a NotFound problem.

   Zope is unable to locate vitester/asonhe

Are you sure, vitester/asonhe is there?


Note, that ObjectManager.__getitem__ just locates
its ObjectManager items...

-- 
Dieter
___
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 )


Re: [Zope] __getitem__ and returning a PageTemplateFile instance

2005-10-18 Thread J Cameron Cooper

Anders Bruun Olsen wrote:

On Sun, Oct 16, 2005 at 06:50:09PM +0200, Dieter Maurer wrote:


I am trying to make a product where-in I want to be able to return a
page based on the url, think something like /product/username
which would return a page with the users details.
For this purpose I am using __getitem__, but when I return a
PageTemplateFile instance it just tells me it has encountered a problem
publishing the object.


I such a case, you look at the traceback (which you can find in
the error_log object in your Zope Root Folder (ZMI)). 



It just says No exceptions logged. So it does not log any errors in
error_log. 
The error message I am getting is:


Site Error

An error was encountered while publishing this resource.

Debugging Notice
Zope has encountered a problem publishing your object.

Cannot locate object at: http://localhost:8080/vitester/asonhe 




If it does not solve the problem directly, you include
the full error information (at least Error Type, Error Value
*AND* traceback) in your post.



If there had been a better error description I would of course have
included it, but the thing that has made this difficult to understand is
that I haven't been able to find any real error messages. I have enabled
debug-mode and am running Zope in the foreground, but it reports no
errors at all.


error_log is by default set to ignore three common types of exceptions. 
You should remove NotFound from the list if you're getting NotFound 
exceptions and want to see them.


--jcc
--
Building Websites with Plone
http://plonebook.packtpub.com/

Enfold Systems, LLC
http://www.enfoldsystems.com
___
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 )


Re: [Zope] __getitem__ and returning a PageTemplateFile instance

2005-10-18 Thread Anders Bruun Olsen
On Tue, Oct 18, 2005 at 03:30:42PM -0500, J Cameron Cooper wrote:
 error_log is by default set to ignore three common types of exceptions. 
 You should remove NotFound from the list if you're getting NotFound 
 exceptions and want to see them.

Ahhh.. Thanks, now I have a traceback, unfortunately it didn't make it any
more clear to me what the problem is.

Traceback (innermost last):
  Module ZPublisher.Publish, line 104, in publish
  Module ZPublisher.BaseRequest, line 355, in traverse
  Module ZPublisher.HTTPResponse, line 651, in debugError
NotFound: TABLE BORDER=0 WIDTH=100%
TR VALIGN=TOP

TD WIDTH=10% ALIGN=CENTER
nbsp;
/TD

TD WIDTH=90%
  H2Site Error/H2
  PAn error was encountered while publishing this resource.
  /P
  PSTRONGDebugging Notice/STRONG/P

  Zope has encountered a problem publishing your object.p
Cannot locate object at: http://localhost:8080/vitester/asonhe
  HR NOSHADE

  PTroubleshooting Suggestions/P

  UL
  LIThe URL may be incorrect./LI
  LIThe parameters passed to this resource may be incorrect./LI
  LIA resource that this resource relies on may be
  encountering an error./LI
  /UL

  PFor more detailed information about the error, please
  refer to error log.
  /P

  PIf the error persists please contact the site maintainer.
  Thank you for your patience.
  /P
/TD/TR
/TABLE


-- 
Anders
-BEGIN GEEK CODE BLOCK-
Version: 3.12
GCS/O d--@ s:+ a-- C++ UL+++$ P++ L+++ E- W+ N(+) o K? w O-- M- V
PS+ PE@ Y+ PGP+ t 5 X R+ tv+ b++ DI+++ D+ G e- h !r y?
--END GEEK CODE BLOCK--
PGPKey: 
http://random.sks.keyserver.penguin.de:11371/pks/lookup?op=getsearch=0xD4DEFED0
___
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 )


Re: [Zope] __getitem__ and returning a PageTemplateFile instance

2005-10-18 Thread J Cameron Cooper

Anders Bruun Olsen wrote:

On Tue, Oct 18, 2005 at 03:30:42PM -0500, J Cameron Cooper wrote:

error_log is by default set to ignore three common types of exceptions. 
You should remove NotFound from the list if you're getting NotFound 
exceptions and want to see them.



Ahhh.. Thanks, now I have a traceback, unfortunately it didn't make it any
more clear to me what the problem is.

Traceback (innermost last):
  Module ZPublisher.Publish, line 104, in publish
  Module ZPublisher.BaseRequest, line 355, in traverse
  Module ZPublisher.HTTPResponse, line 651, in debugError


In Zope 2.7, I see that line raising a debug error. Why it doesn't get 
through I don't know, but here's what it says::


 The object at %s has an empty or missing  \
 docstring. Objects must have a docstring to be  \
 published. % URL

That should help you, I think. All Zope objects that are to be published 
to the web must have a docstring.


--jcc

--
Building Websites with Plone
http://plonebook.packtpub.com/

Enfold Systems, LLC
http://www.enfoldsystems.com
___
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 )


Re: [Zope] __getitem__ and returning a PageTemplateFile instance

2005-10-16 Thread Dieter Maurer
Anders Bruun Olsen wrote at 2005-10-14 11:53 +0200:
 ...
I am trying to make a product where-in I want to be able to return a
page based on the url, think something like /product/username
which would return a page with the users details.
For this purpose I am using __getitem__, but when I return a
PageTemplateFile instance it just tells me it has encountered a problem
publishing the object.

I such a case, you look at the traceback (which you can find in
the error_log object in your Zope Root Folder (ZMI)). 

If it does not solve the problem directly, you include
the full error information (at least Error Type, Error Value
*AND* traceback) in your post.

-- 
Dieter
___
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 )


Re: [Zope] __getitem__ and returning a PageTemplateFile instance

2005-10-16 Thread Anders Bruun Olsen
On Sun, Oct 16, 2005 at 06:50:09PM +0200, Dieter Maurer wrote:
 I am trying to make a product where-in I want to be able to return a
 page based on the url, think something like /product/username
 which would return a page with the users details.
 For this purpose I am using __getitem__, but when I return a
 PageTemplateFile instance it just tells me it has encountered a problem
 publishing the object.
 I such a case, you look at the traceback (which you can find in
 the error_log object in your Zope Root Folder (ZMI)). 

It just says No exceptions logged. So it does not log any errors in
error_log. 
The error message I am getting is:

Site Error

An error was encountered while publishing this resource.

Debugging Notice
Zope has encountered a problem publishing your object.

Cannot locate object at: http://localhost:8080/vitester/asonhe 

 If it does not solve the problem directly, you include
 the full error information (at least Error Type, Error Value
 *AND* traceback) in your post.

If there had been a better error description I would of course have
included it, but the thing that has made this difficult to understand is
that I haven't been able to find any real error messages. I have enabled
debug-mode and am running Zope in the foreground, but it reports no
errors at all.

-- 
Anders
-BEGIN GEEK CODE BLOCK-
Version: 3.12
GCS/O d--@ s:+ a-- C++ UL+++$ P++ L+++ E- W+ N(+) o K? w O-- M- V
PS+ PE@ Y+ PGP+ t 5 X R+ tv+ b++ DI+++ D+ G e- h !r y?
--END GEEK CODE BLOCK--
PGPKey: 
http://random.sks.keyserver.penguin.de:11371/pks/lookup?op=getsearch=0xD4DEFED0
___
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 )