Newbie questions about OOBTree, persistence
Try to do this inside an externmal method. You are not allowed to import such module into PythonScript since PythonScripts are executed within a sandbox with tons of restrictions. -aj --On Freitag, 25. April 2003 9:58 Uhr -0500 Glen Ecklund <Glen@TheGeoGroup.com> wrote:
Hello. I am have trouble accessing an OOBTree. I have found several clues that indicate several different syntaxes, none of which work. Here are some of the things I've tried:
===============================================================
from BTrees.OOBTree import OOBTree
tree = OOBTree() tree['a'] = 'AAA'
Gets:
Error Type: TypeError Error Value: object does not support item or slice assignment
===============================================================
from BTrees.OOBTree import OOBTree
tree = OOBTree() tree.insert['a'] = 'AAA'
Gets:
Error Type: Unauthorized Error Value: You are not allowed to access insert in this context
===============================================================
from BTrees.OOBTree import OOBTree
tree = OOBTree() insert(tree, 'a', 'AAA')
Gets:
Error Type: NameError Error Value: global name 'insert' is not defined
===============================================================
from BTrees.OOBTree import OOBTree
tree = OOBTree() OOBTree.insert(tree, 'a', 'AAA')
Gets:
Error Type: Unauthorized Error Value: You are not allowed to access insert in this context
===============================================================
Also, I need to be able to access elements of the tree. Do I use has_key to check for existence of an element? I haven't been able to get it working either. Do I use Val = tree['a'] to retrieve the value?
Third, how do I make my object persistent? I know that there is a Persistent package, but I don't know how to make my tree persistent.
Thank you very much, Glen
_______________________________________________ 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 )
Thank you. I have tried to provide the necessary import permissions: allow_module('BTrees') allow_module('BTrees.OOBTree') plus a bunch of others that were probably not useful. Is there some reason that OOBTree is a security risk? Glen Andreas Jung wrote:
Try to do this inside an externmal method. You are not allowed to import such module into PythonScript since PythonScripts are executed within a sandbox with tons of restrictions.
-aj
--On Freitag, 25. April 2003 9:58 Uhr -0500 Glen Ecklund <Glen@TheGeoGroup.com> wrote:
Hello. I am have trouble accessing an OOBTree. I have found several clues that indicate several different syntaxes, none of which work. Here are some of the things I've tried:
===============================================================
from BTrees.OOBTree import OOBTree
tree = OOBTree() tree['a'] = 'AAA'
Gets:
Error Type: TypeError Error Value: object does not support item or slice assignment
===============================================================
from BTrees.OOBTree import OOBTree
tree = OOBTree() tree.insert['a'] = 'AAA'
Gets:
Error Type: Unauthorized Error Value: You are not allowed to access insert in this context
===============================================================
from BTrees.OOBTree import OOBTree
tree = OOBTree() insert(tree, 'a', 'AAA')
Gets:
Error Type: NameError Error Value: global name 'insert' is not defined
===============================================================
from BTrees.OOBTree import OOBTree
tree = OOBTree() OOBTree.insert(tree, 'a', 'AAA')
Gets:
Error Type: Unauthorized Error Value: You are not allowed to access insert in this context
===============================================================
Also, I need to be able to access elements of the tree. Do I use has_key to check for existence of an element? I haven't been able to get it working either. Do I use Val = tree['a'] to retrieve the value?
Third, how do I make my object persistent? I know that there is a Persistent package, but I don't know how to make my tree persistent.
Thank you very much, Glen
_______________________________________________ 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 )
-- Glen Ecklund The Geo Group 6 Odana Court Madison, WI 53719 USA glen@TheGeoGroup.com +1 608 230 1000
Glen Ecklund wrote:
===============================================================
from BTrees.OOBTree import OOBTree
tree = OOBTree() tree['a'] = 'AAA'
Gets:
Error Type: TypeError Error Value: object does not support item or slice assignment
Not sure why that doesn't work, actually. OIBTrees sure allow you to use tree['a'] syntax, so so should OOBTrees, and I don't see why you shouldnt be able to assign 'AAA' to it. Hang on....<testing>...the above code works for me, so maybe there is some weirdness in accessing these from a Python script? I don't see why though. Maybe you need to specially admit access to __getitem__? I'm no good at the Python script security...
tree.insert['a'] = 'AAA'
Insert is a method, not a dictionary.
insert(tree, 'a', 'AAA')
Well:
Error Value: global name 'insert' is not defined
Explains that very well.
from BTrees.OOBTree import OOBTree
tree = OOBTree() OOBTree.insert(tree, 'a', 'AAA')
Insert is not a class method, but an object method, you should call it on the object.
Do I use Val = tree['a'] to retrieve the value?
Yes.
Third, how do I make my object persistent?
The Zope BTrees are persistent, you only need to assign the BTree to an attribute and you are done.
Lennart Regebro wrote
tree.insert['a'] = 'AAA'
Insert is a method, not a dictionary.
Oops. That should be: tree.insert('a', 'AAA') which also gets an authorization error. Actually, it keeps asking me for my password, over and over, until I cancel the password dialog. then it says, Error Type:Unauthorized Error Value:You are not allowed to access insert in this context Glen
participants (3)
-
Andreas Jung -
Glen Ecklund -
Lennart Regebro