Hi, Jochen Knuth schrieb: [...] if i use re.search in the kbeimage_search_replace function, then Zope will crash with signal 11. if i use the deprecated regex and gsub, then it works. Does anyone know a reason for this behaviour? Ciao, Jochen
#!/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\.\,\?\/\!\&\(\)'
not working:
def kbeimage_search_replace(text):
expr = re.compile(r'__([%s%s%s\s]+?)__' % (letters, digits, strongem_punc)).search r=expr(text) if r: start, end = r.span(1) newtext1='"bild":img:' newtext=text[:start-2]+newtext1+text[start:end]+' '+text[end+2:] return kbeimage_search_replace(newtext) else: return text
working:
import ts_regex, regex from ts_regex import gsub ctag_prefix="\([\0- (]\|^\)" ctag_suffix="\([\0- ,.:;!?)]\|$\)" ctag_middl2="[%s][%s]\([^\0- %s][^%s]*[^\0- %s]\|[^%s]\)[%s][%s]"
def kbeimage_search_replace(text): bild = regex.compile(ctag_prefix+(ctag_middl2 % (("_",)*8))+ctag_suffix) s=gsub(bild, '\\1"\\2":img:\\2 \\3',text) return s
def updateKBE(self,path): pathobj=self.restrictedTraverse(path) resultbases=self.ZopeFind(pathobj, obj_metatypes=['IPRO Knowledge Base'],search_sub=1) resultlist=[] for fid,fobj in resultbases: results=self.ZopeFind(fobj, obj_metatypes=['IPRO Knowledge Base Entry']) for id,obj in results: resultlist.append(id) issue = obj.Issue newissue = kbeimage_search_replace(issue) obj.propertysheets.properties.manage_changeProperties({'Issue':newissue}) return resultlist
-------------------------------------------------- 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