[Zope] Can't access a method 'in this context'
Tim Hicks
tim@sitefusion.co.uk
Thu, 15 Aug 2002 20:23:26 +0100
> What are the base classes of your class? Perhaps it is not traversable.
Try
> subclassing OFS.SimpleItem.SimpleItem (unless you subclass something
> equivilant already)
Spot on - I mixed in SimpleItem and that error went away. Thanks very much.
*However*, the plot thickens ;-).
So 'fireNextConversion()' now gets successfully called. After a getting the
next item in a queue, a further method _doConversion() is then called by
fireNextConversion. In _doConversion, I get hold of some html then I want
to pass as argument to a zope python script (.zpy for ease of description
here). The .zpy (named 'handleFiles') is 'contained' in the parent object
of the plugin ( - the parent object subclasses ObjectManager). To get hold
of this parent object (called 'zoffice' here), I use;
zoffice = self.superValues(['ZOffice Converter'])[0]
from _doConversion. This works, and I then call my .zpy like so;
zoffice.handleFiles(...args...)
handleFiles makes various 'manage_addFile|Folder|etc' calls successfully.
It also calls some of its siblings (DTML Methods and zpy's) within zoffice.
*However*, when it tries to call any (well, I've tried 2) class defined
methods of zoffice, I get an error saying I can't access that method
('getBody' in this case) in this context again. Aaargh! See the full
traceback below.
That might be a bit of a complicated description (but I'm just trying to
give you the 'context' ;-) ), so here's some pseudo-code to try to give you
the idea of what I'm doing.
class ZOffice(ObjectManager, PropertyManager, Simplitem.Item):
...
self._pluginConverters = {'converter_name':converter_object} # e.g.
def getConverterByName(self, converterName):
""" returns wrapped Converter object """
def getBody(self, html):
""" returns some edited html """
#And has the following defined in the ZODB
handleFiles.zpy
class Converter(SimpleItem, Implicit):
def fireNextConversion(self):
""" calls _doConversion """
def _doConversion(self, ...args...):
zoffice = self.superValues(['ZOffice Converter'])[0] # gets a ZOffice
object
zoffice.handleFiles(...args...)
I hope even some of that makes sense. So, unfortunately, my question
remains, 'why can't I access getBody in that context?'
hope you can help.
tim
Traceback (most recent call last):
File "D:\Zlave\zope251\lib\python\Products\Xron\XronDTMLMethod.py", line
141, in trigger
REQUEST=REQUEST, RESPONSE=RESPONSE, kw=kw)
File "D:\Zlave\zope251\lib\python\OFS\DTMLMethod.py", line 127, in
__call__
r=apply(HTML.__call__, (self, client, REQUEST), kw)
File "D:\Zlave\zope251\lib\python\DocumentTemplate\DT_String.py", line
473, in __call__
try: result = render_blocks(self._v_blocks, md)
File "D:\Zlave\zope251\lib\python\DocumentTemplate\DT_Let.py", line 76, in
render
return render_blocks(self.section, md)
File "D:\Zlave\zope251\lib\python\DocumentTemplate\DT_Util.py", line 159,
in eval
return eval(code, d)
File "<string>", line 2, in f
File
"D:\Zlave\zope251\lib\python\Products\ZOffice\AsyncZlaveClient\AsyncZlaveCli
ent.py", line 231, in fireNextConversion
def getQueue(self):
File
"D:\Zlave\zope251\lib\python\Products\ZOffice\AsyncZlaveClient\AsyncZlaveCli
ent.py", line 135, in _doConversion
#delete the QueueFile
File "D:\Zlave\zope251\lib\python\Shared\DC\Scripts\Bindings.py", line
252, in __call__
return self._bindAndExec(args, kw, None)
File "D:\Zlave\zope251\lib\python\Shared\DC\Scripts\Bindings.py", line
283, in _bindAndExec
return self._exec(bound_data, args, kw)
File "D:\Zlave\zope251\lib\python\Products\PythonScripts\PythonScript.py",
line 302, in _exec
result = apply(f, args, kw)
File "Script (Python)", line 9, in handleFiles
File "D:\Zlave\zope251\lib\python\AccessControl\ZopeGuards.py", line 58,
in guarded_getattr
return inst.aq_acquire(name, aq_validate, validate)
File "D:\Zlave\zope251\lib\python\AccessControl\ZopeGuards.py", line 40,
in aq_validate
return validate(inst, obj, name, v)
File "D:\Zlave\zope251\lib\python\AccessControl\SecurityManager.py", line
83, in validate
self._context)
File "D:\Zlave\zope251\lib\python\AccessControl\ZopeSecurityPolicy.py",
line 200, in validate
raise Unauthorized(name, value)
Unauthorized: You are not allowed to access getBody in this context
> -Casey
>
> On Thursday 15 August 2002 01:54 pm, Tim Hicks wrote:
> > > I suspect you have not made any security assertions on your class.
> >
> > Casey,
> >
> > you were partly right... I had copied and pasted a very similar method
(and
> > it's security) but only remembered to change the actual method
definition
> > and not the security.
> >
> > *However*, correcting this mistake seems to have made no difference at
all.
> > I still receive exactly the same error message and traceback. To be
sure, I
> > deleted my product from the Control Panel (along with all instances),
> > restarted Zope (2.5.1 btw) and then tested again... no joy though :-(
> >
> > Any more clues? I've got to say, 'context' and acquisition type stuff
(if
> > that's even relevant here) are pretty mysterious to me.
> >
> > cheers
> >
> > tim
> >
> >
> > > On Thursday 15 August 2002 10:12 am, Tim Hicks wrote:
> > > > I have a XronDTMLMethod with the following body:
> > > >
> > > > ----
> > > > <dtml-let zoffice="superValues(['ZOffice Converter'])[0]">
> > > > <dtml-call
> > > >
"zoffice.getConverterByName('AsyncZlaveClient').fireNextConversion(_)">
> > > > </dtml-let>
> > > > ----
> > > >
> > > > So, it finds the nearest 'ZOffice Converter' instance (in the
> > acquisition
> > > > chain), names it 'zoffice', then attempts to do the call in the
middle
> > line.
> > > >
> > > > My ZOffice class has the following method defined:
> > > >
> > > > ----
> > > > def getConverterByName(self, converterName):
> > > > """ """
> > > > return self._pluginConverters[converterName].__of__(self)
> > > > ----
> > > >
> > > > self._pluginConverters is a class level dictionary with keys of
> > converter
> > > > names and values of converter instances. The converter instances
> > inherit
> > > > from Acquisition.Implicit.
> > > >
> > > > However, when I 'Trigger' the XronDTMLMethod, I get the following
error:
> > > >
> > > > ----
> > > > Traceback (most recent call last):
> > > >
> > > > File
"D:\Zlave\zope251\lib\python\Products\Xron\XronDTMLMethod.py",
> > line
> > > > 141, in trigger
> > > > REQUEST=REQUEST, RESPONSE=RESPONSE, kw=kw)
> > > >
> > > > File "D:\Zlave\zope251\lib\python\OFS\DTMLMethod.py", line 127, in
> > > > __call__
> > > > r=apply(HTML.__call__, (self, client, REQUEST), kw)
> > > >
> > > > File "D:\Zlave\zope251\lib\python\DocumentTemplate\DT_String.py",
line
> > > > 473, in __call__
> > > > try: result = render_blocks(self._v_blocks, md)
> > > >
> > > > File "D:\Zlave\zope251\lib\python\DocumentTemplate\DT_Let.py",
line
> > 76, in
> > > > render
> > > > return render_blocks(self.section, md)
> > > >
> > > > File "D:\Zlave\zope251\lib\python\DocumentTemplate\DT_Util.py",
line
> > 159,
> > > > in eval
> > > > return eval(code, d)
> > > >
> > > > File "<string>", line 2, in f
> > > >
> > > > File "D:\Zlave\zope251\lib\python\AccessControl\DTML.py", line 29,
in
> > > > guarded_getattr
> > > > return guarded_getattr(*args)
> > > >
> > > > File "D:\Zlave\zope251\lib\python\AccessControl\ZopeGuards.py",
line
> > 58,
> > > > in guarded_getattr
> > > > return inst.aq_acquire(name, aq_validate, validate)
> > > >
> > > > File "D:\Zlave\zope251\lib\python\AccessControl\ZopeGuards.py",
line
> > 40,
> > > > in aq_validate
> > > > return validate(inst, obj, name, v)
> > > >
> > > > File
"D:\Zlave\zope251\lib\python\AccessControl\SecurityManager.py",
> > line
> > > > 83, in validate
> > > > self._context)
> > > >
> > > > File
> > "D:\Zlave\zope251\lib\python\AccessControl\ZopeSecurityPolicy.py",
> > > > line 145, in validate
> > > > raise Unauthorized(name, value)
> > > >
> > > > Unauthorized: You are not allowed to access fireNextConversion in
this
> > > > context
> > > > ----
> > > >
> > > > So, my question; why can't I call this method of my converter
object?
> > > >
> > > >
> > > > cheers,
> > > >
> > > > tim
> > > >
> > > >
> > > > _______________________________________________
> > > > 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 )
> > > >
> > >
> >
> >
>