(self)
Prepare static and dynamic search structures.
Prepare static and dynamic search structures.
Prepare static and dynamic search structures .
def _compile(self):
        ''' Prepare static and dynamic search structures. '''
        self.static = {}
        self.dynamic = []
        def fpat_sub(m):
            return m.group(0) if len(m.group(1)) % 2 else m.group(1) + '(?:'
        for rule in self.rules:
            target = self.routes[rule]
            if not self.syntax.search(rule):
                self.static[rule.replace('\\:',':')] = target
                continue
            gpat = self._compile_pattern(rule)
            fpat = re.sub(r'(\\*)(\(\?P<[^>]*>|\((?!\?))', fpat_sub, gpat.pattern)
            gpat = gpat if gpat.groupindex else None
            try:
                combined = '%s|(%s)' % (self.dynamic[-1][0].pattern, fpat)
                self.dynamic[-1] = (re.compile(combined), self.dynamic[-1][1])
                self.dynamic[-1][1].append((gpat, target))
            except (AssertionError, IndexError), e: # AssertionError: Too many groups
                self.dynamic.append((re.compile('(^%s$)'%fpat),
                                    [(gpat, target)]))
            except re.error, e:
                raise RouteSyntaxError("Could not add Route: %s (%s)" % (rule, e))
def _compile ( self ) : self . static = { } self . dynamic = [ ] def fpat_sub ( m ) : return m . group ( 0 ) if len ( m . group ( 1 ) ) % 2 else m . group ( 1 ) + '(?:' for rule in self . rules : target = self . routes [ rule ] if not self . syntax . search ( rule ) : self . static [ rule . replace ( '\\:' , ':' ) ] = target continue gpat = self . _compile_pattern ( rule ) fpat = re . sub ( r'(\\*)(\(\?P<[^>]*>|\((?!\?))' , fpat_sub , gpat . pattern ) gpat = gpat if gpat . groupindex else None try : combined = '%s|(%s)' % ( self . dynamic [ - 1 ] [ 0 ] . pattern , fpat ) self . dynamic [ - 1 ] = ( re . compile ( combined ) , self . dynamic [ - 1 ] [ 1 ] ) self . dynamic [ - 1 ] [ 1 ] . append ( ( gpat , target ) ) except ( AssertionError , IndexError ) , e : # AssertionError: Too many groups self . dynamic . append ( ( re . compile ( '(^%s$)' % fpat ) , [ ( gpat , target ) ] ) ) except re . error , e : raise RouteSyntaxError ( "Could not add Route: %s (%s)" % ( rule , e ) )