[Zope-dev] updating homebrew extension of structured text to standard

Jochen Knuth jok-zope@ipro.de
Mon, 15 Jul 2002 20:37:05 +0200


Hi,

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,
Jochen

---------------------------listKBE--------------------------------------
## Script (Python) "listKBE"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=
##

results=context.Catalog(meta_type='IPRO Knowledge Base 
Entry',path='/web/Services/knowledge/KnowledgeBase/TechnischesHandbuch/')
for result in results:
   obj = result.getObject()
   print obj.id
   #print obj.propertyItems()
   #for id,val in obj.propertyItems():
   #  print id
   issue = obj.Issue
   newissue = context.updateKBE(issue)
   obj.propertysheets.properties.manage_changeProperties({'Issue':newissue})
return printed

-------------------updateKBE points to kbeimage_search_replace --------
#!/usr/local/bin/python
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
     r=expr(text)
     if r:
         #print r
         start, end = r.span(1)
         newtext='"bild":img:'
         newtext=text[:start-2]+newtext+text[start:end]+' '+text[end+2:]
         #print start,end
         #print newtext
         return kbeimage_search_replace(newtext)
     else:
         #pass
         return text



-- 
--------------------------------------------------
Jochen Knuth          WebMaster http://www.ipro.de
IPRO GmbH             Phone ++49-7152-93330
Steinbeisstr. 6       Fax ++49-7152-933340
71229 Leonberg        EMail: J.Knuth@ipro.de