Changeset 795
- Timestamp:
- 05/30/06 12:42:49 (2 years ago)
- Files:
-
- tracrewriteplugin/0.9/tracrewrite/web_ui.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
tracrewriteplugin/0.9/tracrewrite/web_ui.py
r794 r795 31 31 so any changes to the config will require a reload.""" 32 32 33 self.rewrites = {}33 self.rewrites = [] 34 34 # Config format: tag = /match/rewrite/[options] 35 35 # Data format: { tag: [ match, rewrite, options ], ... } … … 37 37 md = config_re.match(v) 38 38 if md: 39 tag = int(k.strip()) 39 40 try: 40 match = re.compile(md.group('match')) 41 delim = md.group('delim') 42 match_pat = re.sub('\\'+delim,delim,md.group('match')) 43 match = re.compile(match_pat) 41 44 except re.error: 42 self.log.warn("TracRewrite: Unable to compile pattern '%s'"%md.group( 1))45 self.log.warn("TracRewrite: Unable to compile pattern '%s'"%md.group('match')) 43 46 continue 44 47 rewrite = md.group('rewrite') 45 options = md.group('opts') or ' l'48 options = md.group('opts') or 'r' 46 49 self.log.debug("TracRewrite: Loaded rewrite ('%s', '%s', %s')"%( match.pattern, rewrite, options.lower() ) ) 47 self.rewrites [k.strip()] = ( match, rewrite, options.lower() )50 self.rewrites.append( (tag, match, rewrite, options.lower()) ) 48 51 else: 49 52 self.log.warn("TracRewrite: Unable to parse value '%s'"%v) 53 self.rewrites.sort(lambda a,b: cmp(a[0],b[0])) 54 55 # Generate tag location cache 56 i = 0 57 self.tag_index = {} 58 for t,_,_,_ in self.rewrites: 59 self.tag_index[t] = i 60 i += 1 50 61 51 62 # IRequestHandler methods 52 63 def match_request(self, req): 53 64 path = req.path_info 54 for k,v in self.rewrites.iteritems():55 md = v[0].match(path)65 for t,m,_,_ in self.rewrites: 66 md = m.match(path) 56 67 if md: 57 req.tag = k68 req.tag = t 58 69 req.md = md 59 70 return True … … 61 72 62 73 def process_request(self, req): 63 _, rewrite, options = self.rewrites[req.tag]74 _, _, rewrite, options = self.rewrites[self.tag_index[req.tag]] 64 75 try: 65 76 new_path = req.md.expand(rewrite) … … 72 83 raise RewriteError, "TracRewrite doesn't support proxying yet. Sorry" 73 84 elif 'l' in options: 85 raise RewriteError, "Internal rewrites don't actually work yet. Check back after 0.10 get finalized a bit more" 74 86 dispatch_request(new_path, req, self.env) 75 87 return False # This indicates that a response has already been sent
