Changeset 1357

Show
Ignore:
Timestamp:
10/09/06 04:53:17 (2 years ago)
Author:
dfaerch
Message:

RegexIncludeMacro:

Added regex match functionallity + match_seperator

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • regexincludemacro/RegexInclude.py

    r1342 r1357  
    11""" 
    2 $Id$ 
    32 
    43I've added my own comments here. The original text is attached below my comments. 
     4Also, please forgive any stupid errors i might have made. My i started on python 1 week ago. 
    55 
    66use_vars:  
     
    7474        regex = None 
    7575        argstring = '' 
     76        match_seperator = ' ' 
     77        dotall = '' 
    7678        db = env.get_db_cnx() 
    7779        cursor = db.cursor() 
     
    9597        if regex != '':  
    9698                regex = regex.split('\',\'') 
     99 
    97100 
    98101        #Get URL 
     
    118121           argstring.index(',no_dotall,') 
    119122        except: 
    120            re.DOTALL 
     123           re.DOTALL #Aparantly this doesnt always work.. 
     124           dotall = '(?s)' # So we use this regex equivilant 
     125           #buf.write('DOTALL') 
    121126         
    122127        #Should we only include pages for authenticated users? 
     
    127132        except: 
    128133          1 #Sorry.. Dont know python at all, and this was the only way i could solve that except: requires at least 1 line 
     134        #Should we only include pages for authenticated users? 
    129135 
     136        if re.search(',match_seperator(?:=[^,]+)?,',argstring): 
     137              match_seperator = re.search(',match_seperator(?:=([^,]+))?,',argstring).group(1) 
     138 
     139        #Or allow the match seperator to be in quotes 
     140        if re.search(',match_seperator="[^"]+?"?,',argstring): 
     141              match_seperator = re.search(',match_seperator="([^"]+?)"?,',argstring).group(1) 
     142               
     143               
     144               
    130145        #Should we replace $USER with logged-in username, in URL? 
    131146        if re.search(',use_vars(?:=\w+)?,',argstring): 
     
    163178        #Do the regex replacements 
    164179        for ex in regex: 
    165                 ex = ex.strip("'") 
    166                 ex = ex.split('\'/\'') 
    167                 txt = re.sub(ex[0],ex[1],txt) 
     180                #Detect replace or search 
     181                ex = ex.strip("'") 
     182                 
     183                try:  
     184                        ex.index("'/'") #Check If this is a replacement 
     185                        ex = ex.split('\'/\'') 
     186                        txt = re.sub(dotall+ex[0],ex[1],txt) 
     187                except: #If this is a search 
     188                        tmp = '' 
     189                        for m in re.finditer(dotall+ex, txt): 
     190                                tmp = "".join([tmp,match_seperator,m.group(1)]) 
     191                        txt = tmp[1:] 
     192                 
    168193                         
    169194        if formatter == 'wiki':