[Zope3-Users] UnpickleableError when adding object with reference

2008-01-15 Thread john saponara
I add a Limoservice object, then inside that object add a Car; then I 
add a Driver (which contains a Car), and the AddForm offers a dropdown 
with '(no value)' and my Car object.  If I select the car from the 
dropdown I get an error:


UnpickleableError: Cannot pickle type 'zope.security._proxy._Proxy' 
objects


Whereas if I leave the dropdown at '(no value)', the error does not 
occur.  What am I doing wrong?  (See attached error.txt for full error.)


Thanks yet again!
2008-01-15T06:47:39 ERROR SiteError 
http://localhost:2020/mylimo/+/limoService.Driver%3D
Traceback (most recent call last):
  File C:\Python24\Lib\site-packages\zope\publisher\publish.py, line 138, in 
publish
publication.afterCall(request, obj)
  File C:\Python24\Lib\site-packages\zope\app\publication\browser.py, line 
78, in afterCall
super(BrowserPublication, self).afterCall(request, ob)
  File C:\Python24\Lib\site-packages\zope\app\publication\zopepublication.py, 
line 167, in afterCall
txn.commit()
  File C:\Python24\Lib\site-packages\transaction\_transaction.py, line 395, 
in commit
self._commitResources()
  File C:\Python24\Lib\site-packages\transaction\_transaction.py, line 495, 
in _commitResources
rm.commit(self)
  File C:\Python24\Lib\site-packages\ZODB\Connection.py, line 498, in commit
self._commit(transaction)
  File C:\Python24\Lib\site-packages\ZODB\Connection.py, line 543, in _commit
self._store_objects(ObjectWriter(obj), transaction)
  File C:\Python24\Lib\site-packages\ZODB\Connection.py, line 570, in 
_store_objects
p = writer.serialize(obj)  # This calls __getstate__ of obj
  File C:\Python24\Lib\site-packages\ZODB\serialize.py, line 407, in serialize
return self._dump(meta, obj.__getstate__())
  File C:\Python24\Lib\site-packages\ZODB\serialize.py, line 416, in _dump
self._p.dump(state)
UnpickleableError: Cannot pickle type 'zope.security._proxy._Proxy' objects
127.0.0.1 - - [15/Jan/2008:06:47:39 -0400] POST 
/mylimo/+/limoService.Driver%3D HTTP/1.1 500 84 
http://localhost:2020/mylimo/+/limoService.Driver=; Mozilla/5.0 (Windows; U; 
Windows NT 5.1; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11

from zope.app import zapi
from zope.interface import implements
from zope.app.container.btree import BTreeContainer
from zope.app.container.contained import Contained
# from persistent import Persistent

from interfaces import ICar, IDriver, ILimoservice, ILimoserviceContained

class Car(Contained):
implements(ICar,ILimoserviceContained)
model=u''
nPassengers=0

class Driver(Contained):
implements(IDriver,ILimoserviceContained)
car=None

class Limoservice(BTreeContainer):
implements(ILimoservice)

class CarView(object):
def message(self):
return 'car model %s holds %d passengers' % (self.context.model, 
self.context.nPassengers)
class DriverView(object):
def message(self):
if self.context.car:
car=self.context.car
msg='driver drives car model %s, can carry %d 
passengers' % (car.model,car.nPassengers)
else:
print 'driver has no car!'
msg='no car info'
return msg

from zope.formlib import form
class CarEdit(form.EditForm):
form_fields = form.Fields(ICar)
class DriverEdit(form.EditForm):
form_fields = form.Fields(IDriver)

class CarAddForm(form.AddForm):
form_fields = form.Fields(ICar)
def create(self,data):
obj=Car()
form.applyChanges(obj, self.form_fields, data)
return obj
class DriverAddForm(form.AddForm):
form_fields = form.Fields(IDriver)
def create(self,data):
obj=Driver()
form.applyChanges(obj, self.form_fields, data)
return obj

from zope.schema.vocabulary import SimpleVocabulary
def carsInParent(context):
'''returns child cars __name__ for subobjects of parent as a vocabulary'''
return SimpleVocabulary.fromItems(
[(k, v) for k, v in context.__parent__.items() if ICar.providedBy(v)])

configure
xmlns=http://namespaces.zope.org/zope;
xmlns:browser=http://namespaces.zope.org/browser;
i18n_domain=limoService


  interface
  interface=.interfaces.ICar
  type=zope.app.content.interfaces.IContentType
  /
  interface
  interface=.interfaces.IDriver
  type=zope.app.content.interfaces.IContentType
  /

  class class=.classes.Car
implements
interface=zope.annotation.interfaces.IAttributeAnnotatable
/
factory
id=limoService.classes.Car
description=a car 
/
require
permission=zope.Public
interface=.interfaces.ICar
/
require
permission=zope.ManageContent
set_schema=.interfaces.ICar
/
  /class
  class class=.classes.Driver
implements

Re: [Zope3-Users] UnpickleableError when adding object with reference

2008-01-15 Thread Thierry Florac
Le mardi 15 janvier 2008 à 07:05 -0500, john saponara a écrit :
 I add a Limoservice object, then inside that object add a Car; then I 
 add a Driver (which contains a Car), and the AddForm offers a dropdown 
 with '(no value)' and my Car object.  If I select the car from the 
 dropdown I get an error:
 
 UnpickleableError: Cannot pickle type 'zope.security._proxy._Proxy' 
 objects
 
 Whereas if I leave the dropdown at '(no value)', the error does not 
 occur.  What am I doing wrong?  (See attached error.txt for full error.)

Hi, 
As explained into error message, you can't store security proxied
objects into ZODB : you have to remove proxy before they can be stored.

What I generally do is just something like this :

  ...
  from zope.security.proxy import removeSecurityProxy

  class Driver(Contained):
implements(IDriver,ILimoserviceContained)
_car = None

def _getCar(self):
  return self._car

def _setCar(self, value):
  self._car = removeSecurityProxy(value)

car = property(_getCar,_setCar)
  ...

Like that, any way the car property is modified, it's automatically
unproxied and can be stored safely.


  Thierry Florac
-- 
  Chef de projet intranet/internet
  Office National des Forêts - Département Informatique
  2, Avenue de Saint-Mandé
  75570 PARIS Cedex 12
  Mél : [EMAIL PROTECTED]
  Tél. : +33 01.40.19.59.64
  Fax. : +33 01.40.19.59.85

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


[Zope3-Users] Tutorial on Security Configuration with External DB Data

2008-01-15 Thread kevin gill

I have loaded a tutorial into the Zope3 wiki, Zope In Anger section about
how to store security configuration on your relational database.

It is essentially a second part of the How do I use SQLScript tutorial, as
storing principals is the hard part of using an external database.

If anyone has time to review the tutorial I would appreciate any feedback,

   http://wiki.zope.org/zope3/HowDoIConfigureSecurityInARelationalDatabase

The SQLScipt Tutorial is at:

   http://wiki.zope.org/zope3/HowDoIUseSQLScript

Thanks,

Kevin

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users