ZPatterns: __getitem__ on a DataSkin instance
Let's say I have a DataSkin-derived ZClass that has the attribute "forename" (in a dataskin attribute propertysheet). If I get an instance of this ZClass from the ZODB (set up to use a Folder w/ customizer suppport), I can refer to the "forename" attribute using <dtml-var "this()['forename']">. However, if I get an instance of the same class from a Specialist, <dtml-var "this()['forename']"> gives me Error Type: AttributeError Error Value: __getitem__ Any idea why there's the difference? Can the latter case be fixed? -- Steve Alexander Software Engineer Cat-Box limited http://www.cat-box.net
Steve Alexander wrote:
Let's say I have a DataSkin-derived ZClass that has the attribute "forename" (in a dataskin attribute propertysheet).
If I get an instance of this ZClass from the ZODB (set up to use a Folder w/ customizer suppport), I can refer to the "forename" attribute using <dtml-var "this()['forename']">.
However, if I get an instance of the same class from a Specialist, <dtml-var "this()['forename']"> gives me
Error Type: AttributeError Error Value: __getitem__
Any idea why there's the difference?
Can the latter case be fixed?
A workaround, using the ever-flexible skinscript: I've defined __getitem__ through skinscript and a PythonScript. SkinScript: WITH SELF COMPUTE __getitem__=getattr PythonScript: parameter list: index return getattr(index) -- Steve Alexander Software Engineer Cat-Box limited http://www.cat-box.net
Hi Steve, Hmm.. is the 'id' of your PythonScript also getattr? thanks, -steve
"Steve" == Steve Alexander <steve@cat-box.net> writes:
Steve> Steve Alexander wrote: >> Let's say I have a DataSkin-derived ZClass that has the >> attribute "forename" (in a dataskin attribute propertysheet). >> >> If I get an instance of this ZClass from the ZODB (set up to >> use a Folder w/ customizer suppport), I can refer to the >> "forename" attribute using <dtml-var "this()['forename']">. >> >> However, if I get an instance of the same class from a >> Specialist, <dtml-var "this()['forename']"> gives me >> >> Error Type: AttributeError Error Value: __getitem__ >> >> Any idea why there's the difference? >> >> Can the latter case be fixed? Steve> A workaround, using the ever-flexible skinscript: Steve> I've defined __getitem__ through skinscript and a Steve> PythonScript. Steve> SkinScript: WITH SELF COMPUTE __getitem__=getattr Steve> PythonScript: parameter list: index Steve> return getattr(index) Steve> -- Steve Alexander Software Engineer Cat-Box limited Steve> http://www.cat-box.net Steve> _______________________________________________ Zope-Dev Steve> maillist - Zope-Dev@zope.org Steve> http://lists.zope.org/mailman/listinfo/zope-dev ** No cross Steve> posts or HTML encoding! ** (Related lists - Steve> http://lists.zope.org/mailman/listinfo/zope-announce Steve> http://lists.zope.org/mailman/listinfo/zope )
Steve Spicklemire wrote:
Hi Steve,
Hmm.. is the 'id' of your PythonScript also getattr?
Yes. I forgot to mention that. And, I realized just after posting the email to the list that calling a method "getattr" is asking for trouble :-) Actually, my workaround doesn't work except in the most trivial cases. My code was making more errors as Zope tried to look up the _ variable via __getitem__ and thus via my PythonScript. I've ended up using a dtml-if to choose whether to use a <dtml-with stuff mapping> block or just a plain <dtml-with stuff> block. I'd still like to know why a Dataskin from a specialist is behaving differently from one in the ZODB in this respect. -- Steve Alexander Software Engineer Cat-Box limited http://www.cat-box.net
Zopists, I finally got Splitter.c to let me index numbers and 'C++' in a TextIndex. I have about 50,000 objects in that index, and search performance is nearly instantaneous still. I am running on a big machine though. If anyone wants those changes there's really easy. Just mail me directly, since it's a long file to post. All my best, Jason Spisak
Jason Spisak wrote:
Zopists,
I finally got Splitter.c to let me index numbers and 'C++' in a TextIndex. I have about 50,000 objects in that index, and search performance is nearly instantaneous still. I am running on a big machine though. If anyone wants those changes there's really easy. Just mail me directly, since it's a long file to post.
Could you maybe post just the diff for poserity? -- | Casey Duncan | Kaivo, Inc. | cduncan@kaivo.com `------------------>
Casey Duncan: It truely is nothing more than cutting out the two parts that eliminate single letter words and numbers: *** Zope-2.2.4-src/lib/python/SearchIndex/Splitter.c --- Zope-2.2.4-src/lib/python/SearchIndex/Splitter_Old.c *************** *** 169,192 **** len = PyString_Size(word) - 1; len = PyString_Size(word); - /*if(len < 2) Single-letter words are stop words! - { - Py_INCREF(Py_None); - return Py_None; - } */ - - /************************************************************* - Test whether a word has any letters. */ for (; --len >= 0 && ! isalpha((unsigned char)cword[len]); ); - /*if (len < 0) - { - Py_INCREF(Py_None); - return Py_None; - } - - * If no letters, treat it as a stop word. - *************************************************************/ Py_INCREF(word); --- 169,176 ---- All my best, Jason Spisak CIO __ ___ ______ __ / // (_)_____/_ __/__ ____/ / ___ _______ __ _ / _ / / __/ -_) / / -_) __/ _ \(_-<_/ __/ _ \/ ' \ /_//_/_/_/ \__/_/ \__/\__/_//_/___(_)__/\___/_/_/_/ 6151 West Century Boulevard Suite 900 Los Angeles, CA 90045 P. 310.665.3444 F. 310.665.3544 Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email address may not be added to any commercial mail list with out my permission. Violation of my privacy with advertising or SPAM will result in a suit for a MINIMUM of $500 damages/incident, $1500 for repeats.
participants (4)
-
Casey Duncan -
Jason Spisak -
Steve Alexander -
Steve Spicklemire