Jochen Knuth  <[EMAIL PROTECTED]> wrote:
>i have a ZClass with a property which is renderd as structured text. 
>Because i designed this ZClass before there was a standard for including 
>images, i made my own extension of structured text formating.
>Short: I used __imageobject__ as markup for the image.
>Now i want to update all my zclass instances to the new syntax (while 
>upgrading to Zope 2.5.1).
>I have a Python Script listKBE, which call an External Method updateKBE. 
>If i use it with a path with only a few ZClass instances (about 10) it 
>works (slowly). If i use it with a path with about 550 instances it 
>crashes or is extreme slow.
>Anyone to suggest a faster method?
>Thank you,

replying to myself:

i now do a ZopeFind (or correct: two nested ZopeFinds) in the External 
Method (attached) and give the result to the converter function. It 
works now reasonably fast, even with all my ZClass instances (about 600).

Is there so much overhead in Python Scripts calling an External method? 
(i used also ZopeFind in the PythonScript, in a variation of my previous 
Or is it the getObject() call in the Python Scripts?

Jochen Knuth          WebMaster http://www.ipro.de
IPRO GmbH             Phone ++49-7152-93330
Steinbeisstr. 6       Fax ++49-7152-933340
71229 Leonberg        EMail: [EMAIL PROTECTED]
import string
import re

def punc_func(exclude):
    punc = r''
    for char in string.punctuation:
        if char not in exclude:
            punc = punc + r'\%s' % char
    return punc

digits      = string.digits
letters     = string.letters
literal_punc = punc_func("'")
dbl_quoted_punc = punc_func("\"")
strongem_punc = punc_func('*')
under_punc = punc_func('_<>')
phrase_delimiters = r'\s\.\,\?\/\!\&\(\)' 

def kbeimage_search_replace(text):

    expr = re.compile(r'__([%s%s%s\s]+?)__' % (letters, digits, strongem_punc)).search
    if r:
        #print r
        start, end = r.span(1)
        newtext=text[:start-2]+newtext+text[start:end]+' '+text[end+2:]
        #print start,end
        #print newtext
        return kbeimage_search_replace(newtext)
        return text

def updateKBE(self,path):
    resultbases=self.ZopeFind(pathobj, obj_metatypes=['IPRO Knowledge 
    for fid,fobj in resultbases:
        results=self.ZopeFind(pathobj, obj_metatypes=['IPRO Knowledge Base Entry'])
        for id,obj in results:
            issue = obj.Issue
            newissue = kbeimage_search_replace(issue)
    return resultlist

Reply via email to