[Zope-dev] Help needed: why is this DTML not working in zope 2 ?

Steve Alexander steve@cat-box.net
Tue, 04 Jul 2000 20:09:44 +0100


Steve Alexander wrote:
> 
> 
> An external method for automated change from old syntax to new syntax
> follows.
> 
>  * Use at your own risk
>  * No warranty implied or given
>  * Use on a copy of your main Zope site
>  * Back up data.fs three times before starting
>  * Not guarenteed not to spin your processor and never terminate
>  * Run on a copy of Zope in debug mode (-D) to see the print statements
>  * Barely tested, if at all
> 
> _convert_regex = re.compile('<!--#(/?)(([^"-]+?|"[^"]*?"|-[^-])+?)-->')

Actually, I missed something in the original regex, above. (Funny how I
noticed just after I pressed the 'send' button!)

It should read like this:

_convert_regex =
re.compile('''<!--#(/?)(([^"-]+?|"[^"]*?"|'[^']*?'|-[^-])+?)-->''')


The whole thing again -- same disclaimers apply, only more so :-)

--------

import re

def convert_dtml(self):
    """Convert DTML Methods and DTML Documents from old syntax to 
       new syntax.
       Warning: recursive!
       This assumes that DTML Method and DTML Document haven't been
       subclassed.
    """
    print 'convert_dtml: id=%s' % self.title_and_id()
    if hasattr(self, 'meta_type') and \
          (self.meta_type == 'DTML Method' or \
           self.meta_type == 'DTML Document'):
        convert(self)
        
    # should this be "isPrincipiaFolderish"?        
    if hasattr(self, 'isAnObjectManager') and self.isAnObjectManager:
        for v in self.objectValues():
            v.convert_dtml()
            
_convert_regex =
re.compile('''<!--#(/?)(([^"-]+?|"[^"]*?"|'[^']*?'|-[^-])+?)-->''')

def convert(dtml_item):
    print 'converting...'
    title = dtml_item.title
           # like document_src, but doesn't require RESPONSE
    data = dtml_item.PrincipiaSearchSource()
    print '----data----'
    print data
    newdata = _convert_regex.sub('<\g<1>dtml-\g<2>>', data)
    print '----newdata----'
    print newdata    
    print '----end----'    
    dtml_item.manage_edit(newdata, title)
    

--------

--
Steve Alexander
Software Engineer
Cat-Box limited
http://www.cat-box.net