示例#1
0
 def connect(self, *args, **kargs):
     """Create and connect a new Route to the Mapper.
     
     Usage:
     
     .. code-block:: python
     
         m = Mapper()
         m.connect(':controller/:action/:id')
         m.connect('date/:year/:month/:day', controller="blog", action="view")
         m.connect('archives/:page', controller="blog", action="by_page",
         requirements = { 'page':'\d{1,2}' })
         m.connect('category_list', 'archives/category/:section', controller='blog', action='category',
         section='home', type='list')
         m.connect('home', '', controller='blog', action='view', section='home')
     
     """
     routename = None
     if len(args) > 1:
         routename = args[0]
         args = args[1:]
     if '_explicit' not in kargs:
         kargs['_explicit'] = self.explicit
     if '_minimize' not in kargs:
         kargs['_minimize'] = self.minimization
     route = Route(*args, **kargs)
             
     # Apply encoding and errors if its not the defaults and the route 
     # didn't have one passed in.
     if (self.encoding != 'utf-8' or self.decode_errors != 'ignore') and \
        '_encoding' not in kargs:
         route.encoding = self.encoding
         route.decode_errors = self.decode_errors
     
     if not route.static:
         self.matchlist.append(route)
     
     if routename:
         self._routenames[routename] = route
         route.name = routename
     if route.static:
         return
     exists = False
     for key in self.maxkeys:
         if key == route.maxkeys:
             self.maxkeys[key].append(route)
             exists = True
             break
     if not exists:
         self.maxkeys[route.maxkeys] = [route]
     self._created_gens = False