Skip to content

Commit

Permalink
Modified Route.dynamic to be re-created completely each time
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Vanhoren committed Jun 15, 2013
1 parent 16942ca commit 663bad8
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions bottle.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ def __init__(self, strict=False):
self._groups = {}
self.builder = {} # Data structure for the url builder
self.static = {} # Search structure for static routes
self.dyna_routes = []
self.dynamic = [] # Search structure for dynamic routes
#: If true, static routes are no longer checked first.
self.strict_order = strict
Expand Down Expand Up @@ -372,13 +373,18 @@ def getargs(path):
return

mdict = self._groups[flatpat] = {method: (target, getargs)}

try:
combined = '%s|(^%s$)' % (self.dynamic[-1][0].pattern, flatpat)
self.dynamic[-1] = (re.compile(combined), self.dynamic[-1][1])
self.dynamic[-1][1].append(mdict)
except (AssertionError, IndexError): # AssertionError: Too many groups
self.dynamic.append((re.compile('(^%s$)' % flatpat), [mdict]))

self.dyna_routes.append((rule, flatpat, mdict))

self._regen_dynamic()

def _regen_dynamic(self):
combined_l = []
mdicts = []
for rule, flatpat, mdict in self.dyna_routes:
combined_l.append('(^%s$)' % flatpat)
mdicts.append(mdict)
self.dynamic = [(re.compile('|'.join(combined_l)), mdicts)]

def build(self, _name, *anons, **query):
''' Build an URL by filling the wildcards in a rule. '''
Expand Down

0 comments on commit 663bad8

Please sign in to comment.