Re: [Zope] Building dynamically class instances using external methods.

2000-11-14 Thread Dieter Maurer

Hannes Grund writes:
 > I have an external Method 
 > which creates dynamically an instance from of a class depending on 
 > some input to a function contained in this method.
 > In short the code (of the external method)
 > 
 > class Classname:
 > 
 > Called from Zope this does not work. The pickle module raises an 
 > error: 

The External Method documentation tells you that you may
not define a class inside the the source file and return
instances thereof into the Zope world.

Place such classes in standard Python module files
(the documentation suggests a subpackage in "Shared")
and import them in your external method source file.

 > QUESTION 3: The lifetime of an instance has should not to be longer than 
 > the current REQUEST is performed,  is there any possibility to
 > create the instance as an subobject of the current REQUEST ?? 
self.REQUEST.set('xxx', )


Dieter

___
Zope maillist  -  [EMAIL PROTECTED]
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 )




[Zope] Building dynamically class instances using external methods.

2000-11-13 Thread Hannes Grund

Question:

I am running Zope2.2.2 under python1.5.2 on a linux machine.
The following situation:

I have an external Method 
which creates dynamically an instance from of a class depending on 
some input to a function contained in this method.
In short the code (of the external method)

class Classname:
  def function1
  def function2
  ..etc.

def createInstance(argument)
 x = Classname(argument) 
 return x

Where createinstance is the method that is invoked initially from zope.
Everything works fine, the method returns something like 

using "__allow_access_to_unprotected_subobjects__ = 1" 
in the class definition it is possible to access all methods of the class
within Zope.
Among others the class holds a method 'dump' who should 'pickle' the 
objects instance (using the python 'pickle' module), more precise 
should return a string represantion of itself.
This works fine when tested in a normal python session. 
(where the method returns contrary to above:
<__main__.Classname instance at ...>) 
Called from Zope this does not work. The pickle module raises an 
error: 
  ..
  File /usr/lib/python1.5/pickle.py, line 818, in dump
  File /usr/lib/python1.5/pickle.py, line 97, in dump
  File /usr/lib/python1.5/pickle.py, line 198, in save
  File /usr/lib/python1.5/pickle.py, line 400, in save_inst
  Error type: Attribute error, Error Value: __module__

QUESTION: Is there any possibility to get these things work. ?
 (or is it really awkward stuff ???)

Maybe related questions:
 
QUESTION 2: What does the "?" mark in the generated objects string
representation means ? 
Is it neccessary to 'anchor' (sorry for my terminology) the object within some 
other object ? And:

QUESTION 3: The lifetime of an instance has should not to be longer than 
the current REQUEST is performed,  is there any possibility to
create the instance as an subobject of the current REQUEST ?? 

Any help and advice would be highly appreciated...

regards 

 Hannes.



___
Zope maillist  -  [EMAIL PROTECTED]
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 )