The traceback and 'offending' code.
Traceback (innermost last):
 Module ZPublisher.Publish, line 115, in publish
 Module ZPublisher.mapply, line 88, in mapply
 Module ZPublisher.Publish, line 41, in call_object
 Module Shared.DC.Scripts.Bindings, line 311, in __call__
 Module Shared.DC.Scripts.Bindings, line 348, in _bindAndExec
 Module Products.PythonScripts.PythonScript, line 323, in _exec
 Module None, line 7, in AMyZClass2
  - <PythonScript at /AMyZClass2>
  - Line 7
Unauthorized: You are not allowed to access 'number' in this context

--Script(Python)--
MZ = context.Zclass2.myZclass()
M2 = MZ.attribute1a
print MZ
print M2[0].number
return printed

kevin7kal wrote:
I've changed my code a bit, adding the docstring, Persistent to all classes and __allow_access_to_unprotected_attributes__ = 1 to all classes. Still, I recieve the same error.

I have changed the code so _attribute1a is a single instance of class1 instead of a list of containing multiple instances of class1 and I can access the attributes of the object without issue. Are the objects automatically unwrapped when added to a list? is there a way around this?
I can send the code again if need be.

so here is the code again, this time with only the single object in attribute1a.
--myClass.py--
import Acquisition
from persistent import Persistent

class class1(Acquisition.Explicit,Persistent):
   ''' a simple class with some attributes and methods'''
   __allow_access_to_unprotected_attributes__ = 1
   attribute1 = 'attribute 1'
   attribute2 = 'attribute 2'
   _number = ''
   def __init__(self,number2):
       '''simple init for the class'''
       self._number=number2*3
         def method1(self):
       '''return a string methd1'''
       mthd1 =  'methd1'
       return mthd1
   def method2(self):
       ''' return a string methd2'''
       mthd2 = 'method2'
       return mthd2
   def _get_number(self):
       return self._number
   number = property(fget=_get_number)
                    class class2(Acquisition.Explicit,Persistent):
   ''' a second simple class with some attributes and methods'''
   __allow_access_to_unprotected_attributes__ = 1
   _attribute1a = []
   attribute2a = []
   def __init__(self):
       '''create a list of class1 objects in attribute1a'''
       #i=1
       #while i < 5:
       #    obj = class1(i)
       #    self._attribute1a.append(obj)
       #    i=i+1
       self._attribute1a = class1(5)
   def method1a(self):
'''instantiate class1 as object and return object usable by zope'''
       obj = class1(5)
       return obj.__of__(self)
   def method2a(self):
       '''returns class1.method1()'''
       c1m1 = class1.method1()
       return c1m1
   def get_attribute1a(self):
       #if self._attribute1a != []:
           #i = len(self._attribute1a)
           #j = 0
           #while j != i-1:
           #    self._attribute1a[j] = self._attribute1a[j].__of__(self)
           #    j = j+1
       #else:
       obj = self._attribute1a
       return obj.__of__(self)
   attribute1a = property(fget=get_attribute1a)
   attribute1b = property(fget=method1a)
   attribute2b = property(fget=method2a)



Alexis Roda wrote:
En/na kevin7kal ha escrit:
Ok, thank you for that.
I can create the list of objects from the __of__(self) attribute without the wrapper error now,
but I still cannot access that attribute through zope.
Here is my code again, along with my zope content.

Another thing I've missed, class1 isn't persistent, but you store instances in Zclass2.attribute1a. This can explain the "can't pickle" error.



HTH
_______________________________________________
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 )

_______________________________________________
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 )

_______________________________________________
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 )

Reply via email to