home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_2388 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  19.5 KB  |  745 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import re
  5. import sys
  6. import threading
  7. from routes import request_config
  8. from routes.lru import LRUCache
  9. from routes.util import controller_scan, MatchException, RoutesException
  10. from routes.route import Route
  11. COLLECTION_ACTIONS = [
  12.     'index',
  13.     'create',
  14.     'new']
  15. MEMBER_ACTIONS = [
  16.     'show',
  17.     'update',
  18.     'delete',
  19.     'edit']
  20.  
  21. def strip_slashes(name):
  22.     if name.startswith('/'):
  23.         name = name[1:]
  24.     
  25.     if name.endswith('/'):
  26.         name = name[:-1]
  27.     
  28.     return name
  29.  
  30.  
  31. class SubMapperParent(object):
  32.     
  33.     def submapper(self, **kargs):
  34.         return SubMapper(self, **kargs)
  35.  
  36.     
  37.     def collection(self, collection_name, resource_name, path_prefix = None, member_prefix = '/{id}', controller = None, collection_actions = COLLECTION_ACTIONS, member_actions = MEMBER_ACTIONS, member_options = None, **kwargs):
  38.         if controller is None:
  39.             if not resource_name:
  40.                 pass
  41.             controller = collection_name
  42.         
  43.         if path_prefix is None:
  44.             path_prefix = '/' + collection_name
  45.         
  46.         collection = SubMapper(self, collection_name = collection_name, resource_name = resource_name, path_prefix = path_prefix, controller = controller, actions = collection_actions, **kwargs)
  47.         if not member_options:
  48.             pass
  49.         collection.member = SubMapper(collection, path_prefix = member_prefix, actions = member_actions, **{ })
  50.         return collection
  51.  
  52.  
  53.  
  54. class SubMapper(SubMapperParent):
  55.     
  56.     def __init__(self, obj, resource_name = None, collection_name = None, actions = None, formatted = None, **kwargs):
  57.         self.kwargs = kwargs
  58.         self.obj = obj
  59.         self.collection_name = collection_name
  60.         self.member = None
  61.         if not resource_name and getattr(obj, 'resource_name', None) and kwargs.get('controller', None):
  62.             pass
  63.         self.resource_name = getattr(obj, 'controller', None)
  64.         if formatted is not None:
  65.             self.formatted = formatted
  66.         else:
  67.             self.formatted = getattr(obj, 'formatted', None)
  68.             if self.formatted is None:
  69.                 self.formatted = True
  70.             
  71.         if not actions:
  72.             pass
  73.         self.add_actions([])
  74.  
  75.     
  76.     def connect(self, *args, **kwargs):
  77.         newkargs = { }
  78.         newargs = args
  79.         for key, value in self.kwargs.items():
  80.             if key == 'path_prefix':
  81.                 if len(args) > 1:
  82.                     newargs = (args[0], self.kwargs[key] + args[1])
  83.                 else:
  84.                     newargs = (self.kwargs[key] + args[0],)
  85.             len(args) > 1
  86.             if key in kwargs:
  87.                 if isinstance(value, dict):
  88.                     newkargs[key] = dict(value, **kwargs[key])
  89.                 else:
  90.                     newkargs[key] = value + kwargs[key]
  91.             isinstance(value, dict)
  92.             newkargs[key] = self.kwargs[key]
  93.         
  94.         for key in kwargs:
  95.             if key not in self.kwargs:
  96.                 newkargs[key] = kwargs[key]
  97.                 continue
  98.         
  99.         return self.obj.connect(*newargs, **newkargs)
  100.  
  101.     
  102.     def link(self, rel = None, name = None, action = None, method = 'GET', formatted = None, **kwargs):
  103.         if (formatted or formatted is None) and self.formatted:
  104.             suffix = '{.format}'
  105.         else:
  106.             suffix = ''
  107.         if not name:
  108.             pass
  109.         if not rel:
  110.             pass
  111.         if not action and rel:
  112.             pass
  113.         return self.connect(rel + '_' + self.resource_name, '/' + name + suffix, action = name, **_kwargs_with_conditions(kwargs, method))
  114.  
  115.     
  116.     def new(self, **kwargs):
  117.         return self.link(rel = 'new', **kwargs)
  118.  
  119.     
  120.     def edit(self, **kwargs):
  121.         return self.link(rel = 'edit', **kwargs)
  122.  
  123.     
  124.     def action(self, name = None, action = None, method = 'GET', formatted = None, **kwargs):
  125.         if (formatted or formatted is None) and self.formatted:
  126.             suffix = '{.format}'
  127.         else:
  128.             suffix = ''
  129.         if not name:
  130.             pass
  131.         if not action:
  132.             pass
  133.         return self.connect(action + '_' + self.resource_name, suffix, action = name, **_kwargs_with_conditions(kwargs, method))
  134.  
  135.     
  136.     def index(self, name = None, **kwargs):
  137.         if not name:
  138.             pass
  139.         return self.action(name = self.collection_name, action = 'index', method = 'GET', **kwargs)
  140.  
  141.     
  142.     def show(self, name = None, **kwargs):
  143.         if not name:
  144.             pass
  145.         return self.action(name = self.resource_name, action = 'show', method = 'GET', **kwargs)
  146.  
  147.     
  148.     def create(self, **kwargs):
  149.         return self.action(action = 'create', method = 'POST', **kwargs)
  150.  
  151.     
  152.     def update(self, **kwargs):
  153.         return self.action(action = 'update', method = 'PUT', **kwargs)
  154.  
  155.     
  156.     def delete(self, **kwargs):
  157.         return self.action(action = 'delete', method = 'DELETE', **kwargs)
  158.  
  159.     
  160.     def add_actions(self, actions):
  161.         [ getattr(self, action)() for action in actions ]
  162.  
  163.     
  164.     def __enter__(self):
  165.         return self
  166.  
  167.     
  168.     def __exit__(self, type, value, tb):
  169.         pass
  170.  
  171.  
  172.  
  173. def _kwargs_with_conditions(kwargs, method):
  174.     if method and 'conditions' not in kwargs:
  175.         newkwargs = kwargs.copy()
  176.         newkwargs['conditions'] = {
  177.             'method': method }
  178.         return newkwargs
  179.     return kwargs
  180.  
  181.  
  182. class Mapper(SubMapperParent):
  183.     
  184.     def __init__(self, controller_scan = controller_scan, directory = None, always_scan = False, register = True, explicit = True):
  185.         self.matchlist = []
  186.         self.maxkeys = { }
  187.         self.minkeys = { }
  188.         self.urlcache = LRUCache(1600)
  189.         self._created_regs = False
  190.         self._created_gens = False
  191.         self._master_regexp = None
  192.         self.prefix = None
  193.         self.req_data = threading.local()
  194.         self.directory = directory
  195.         self.always_scan = always_scan
  196.         self.controller_scan = controller_scan
  197.         self._regprefix = None
  198.         self._routenames = { }
  199.         self.debug = False
  200.         self.append_slash = False
  201.         self.sub_domains = False
  202.         self.sub_domains_ignore = []
  203.         self.domain_match = '[^\\.\\/]+?\\.[^\\.\\/]+'
  204.         self.explicit = explicit
  205.         self.encoding = 'utf-8'
  206.         self.decode_errors = 'ignore'
  207.         self.hardcode_names = True
  208.         self.minimization = False
  209.         self.create_regs_lock = threading.Lock()
  210.         if register:
  211.             config = request_config()
  212.             config.mapper = self
  213.         
  214.  
  215.     
  216.     def __str__(self):
  217.         
  218.         def format_methods(r):
  219.             if r.conditions:
  220.                 method = r.conditions.get('method', '')
  221.                 if not type(method) is str or method:
  222.                     pass
  223.                 return ', '.join(method)
  224.             return ''
  225.  
  226.         table = [] + [ ('', format_methods(r), '') for r in self.matchlist ]
  227.         widths = [ (max,)((lambda .0: for row in .0:
  228. len(row[col]))(table)) for None in range(len(table[0])) ]
  229.         return ('\n'.join,)((lambda .0: for None in .0:
  230. row = None(None, ' '.join)((lambda .0: for col in .0:
  231. row[col].ljust(widths[col]))(range(len(widths))))
  232.             
  233. )(table))
  234.  
  235.     
  236.     def _envget(self):
  237.         
  238.         try:
  239.             return self.req_data.environ
  240.         except AttributeError:
  241.             return None
  242.  
  243.  
  244.     
  245.     def _envset(self, env):
  246.         self.req_data.environ = env
  247.  
  248.     
  249.     def _envdel(self):
  250.         del self.req_data.environ
  251.  
  252.     environ = property(_envget, _envset, _envdel)
  253.     
  254.     def extend(self, routes, path_prefix = ''):
  255.         for route in routes:
  256.             if path_prefix and route.minimization:
  257.                 routepath = '/'.join([
  258.                     path_prefix,
  259.                     route.routepath])
  260.             elif path_prefix:
  261.                 routepath = path_prefix + route.routepath
  262.             else:
  263.                 routepath = route.routepath
  264.             self.connect(route.name, routepath, **route._kargs)
  265.         
  266.  
  267.     
  268.     def connect(self, *args, **kargs):
  269.         routename = None
  270.         if len(args) > 1:
  271.             routename = args[0]
  272.         else:
  273.             args = (None,) + args
  274.         if '_explicit' not in kargs:
  275.             kargs['_explicit'] = self.explicit
  276.         
  277.         if '_minimize' not in kargs:
  278.             kargs['_minimize'] = self.minimization
  279.         
  280.         route = Route(*args, **kargs)
  281.         if (self.encoding != 'utf-8' or self.decode_errors != 'ignore') and '_encoding' not in kargs:
  282.             route.encoding = self.encoding
  283.             route.decode_errors = self.decode_errors
  284.         
  285.         if not route.static:
  286.             self.matchlist.append(route)
  287.         
  288.         if routename:
  289.             self._routenames[routename] = route
  290.             route.name = routename
  291.         
  292.         if route.static:
  293.             return None
  294.         exists = False
  295.         for key in self.maxkeys:
  296.             if key == route.maxkeys:
  297.                 self.maxkeys[key].append(route)
  298.                 exists = True
  299.                 break
  300.                 continue
  301.             route.static
  302.         
  303.         if not exists:
  304.             self.maxkeys[route.maxkeys] = [
  305.                 route]
  306.         
  307.         self._created_gens = False
  308.  
  309.     
  310.     def _create_gens(self):
  311.         controllerlist = { }
  312.         actionlist = { }
  313.         for route in self.matchlist:
  314.             if route.static:
  315.                 continue
  316.             
  317.             if route.defaults.has_key('controller'):
  318.                 controllerlist[route.defaults['controller']] = True
  319.             
  320.             if route.defaults.has_key('action'):
  321.                 actionlist[route.defaults['action']] = True
  322.                 continue
  323.         
  324.         controllerlist = controllerlist.keys() + [
  325.             '*']
  326.         actionlist = actionlist.keys() + [
  327.             '*']
  328.         gendict = { }
  329.         for route in self.matchlist:
  330.             if route.static:
  331.                 continue
  332.             
  333.             clist = controllerlist
  334.             alist = actionlist
  335.             if 'controller' in route.hardcoded:
  336.                 clist = [
  337.                     route.defaults['controller']]
  338.             
  339.             if 'action' in route.hardcoded:
  340.                 alist = [
  341.                     unicode(route.defaults['action'])]
  342.             
  343.             for controller in clist:
  344.                 for action in alist:
  345.                     actiondict = gendict.setdefault(controller, { })
  346.                     actiondict.setdefault(action, ([], { }))[0].append(route)
  347.                 
  348.             
  349.         
  350.         self._gendict = gendict
  351.         self._created_gens = True
  352.  
  353.     
  354.     def create_regs(self, *args, **kwargs):
  355.         self.create_regs_lock.acquire()
  356.         
  357.         try:
  358.             self._create_regs(*args, **kwargs)
  359.         finally:
  360.             self.create_regs_lock.release()
  361.  
  362.  
  363.     
  364.     def _create_regs(self, clist = None):
  365.         if clist is None:
  366.             if self.directory:
  367.                 clist = self.controller_scan(self.directory)
  368.             elif callable(self.controller_scan):
  369.                 clist = self.controller_scan()
  370.             elif not self.controller_scan:
  371.                 clist = []
  372.             else:
  373.                 clist = self.controller_scan
  374.         
  375.         for key, val in self.maxkeys.iteritems():
  376.             for route in val:
  377.                 route.makeregexp(clist)
  378.             
  379.         
  380.         regexps = []
  381.         routematches = []
  382.         for route in self.matchlist:
  383.             if not route.static:
  384.                 routematches.append(route)
  385.                 regexps.append(route.makeregexp(clist, include_names = False))
  386.                 continue
  387.         
  388.         self._routematches = routematches
  389.         if self.prefix:
  390.             self._regprefix = re.compile(self.prefix + '(.*)')
  391.         
  392.         regexp = []([ '(?:%s)' % x for x in regexps ])
  393.         self._master_reg = regexp
  394.         self._master_regexp = re.compile(regexp)
  395.         self._created_regs = True
  396.  
  397.     
  398.     def _match(self, url, environ):
  399.         if not (self._created_regs) and self.controller_scan:
  400.             self.create_regs()
  401.         elif not self._created_regs:
  402.             raise RoutesException('You must generate the regular expressions before matching.')
  403.         
  404.         if self.always_scan:
  405.             self.create_regs()
  406.         
  407.         matchlog = []
  408.         if self.prefix:
  409.             if re.match(self._regprefix, url):
  410.                 url = re.sub(self._regprefix, '\\1', url)
  411.                 if not url:
  412.                     url = '/'
  413.                 
  414.             else:
  415.                 return (None, None, matchlog)
  416.         re.match(self._regprefix, url)
  417.         if not environ:
  418.             pass
  419.         environ = self.environ
  420.         sub_domains = self.sub_domains
  421.         sub_domains_ignore = self.sub_domains_ignore
  422.         domain_match = self.domain_match
  423.         debug = self.debug
  424.         valid_url = re.match(self._master_regexp, url)
  425.         if not valid_url:
  426.             return (None, None, matchlog)
  427.         for route in self.matchlist:
  428.             match = route.match(url, environ, sub_domains, sub_domains_ignore, domain_match)
  429.             if debug:
  430.                 matchlog.append(dict(route = route, regexp = bool(match)))
  431.             
  432.             if isinstance(match, dict) or match:
  433.                 return (match, route, matchlog)
  434.         
  435.         return (None, None, matchlog)
  436.  
  437.     
  438.     def match(self, url = None, environ = None):
  439.         if not url and not environ:
  440.             raise RoutesException('URL or environ must be provided')
  441.         not environ
  442.         if not url:
  443.             url = environ['PATH_INFO']
  444.         
  445.         result = self._match(url, environ)
  446.         if self.debug:
  447.             return (result[0], result[1], result[2])
  448.         if isinstance(result[0], dict) or result[0]:
  449.             return result[0]
  450.  
  451.     
  452.     def routematch(self, url = None, environ = None):
  453.         if not url and not environ:
  454.             raise RoutesException('URL or environ must be provided')
  455.         not environ
  456.         if not url:
  457.             url = environ['PATH_INFO']
  458.         
  459.         result = self._match(url, environ)
  460.         if self.debug:
  461.             return (result[0], result[1], result[2])
  462.         if isinstance(result[0], dict) or result[0]:
  463.             return (result[0], result[1])
  464.  
  465.     
  466.     def generate(self, *args, **kargs):
  467.         if not self._created_gens:
  468.             self._create_gens()
  469.         
  470.         if self.append_slash:
  471.             kargs['_append_slash'] = True
  472.         
  473.         if not self.explicit:
  474.             if 'controller' not in kargs:
  475.                 kargs['controller'] = 'content'
  476.             
  477.             if 'action' not in kargs:
  478.                 kargs['action'] = 'index'
  479.             
  480.         
  481.         controller = kargs.get('controller', None)
  482.         action = kargs.get('action', None)
  483.         cache_key = unicode(args).encode('utf8') + unicode(kargs).encode('utf8')
  484.         if self.urlcache is not None:
  485.             if self.environ:
  486.                 cache_key_script_name = '%s:%s' % (self.environ.get('SCRIPT_NAME', ''), cache_key)
  487.             else:
  488.                 cache_key_script_name = cache_key
  489.             for key in [
  490.                 cache_key,
  491.                 cache_key_script_name]:
  492.                 if key in self.urlcache:
  493.                     return self.urlcache[key]
  494.             
  495.         
  496.         if not self._gendict.get(controller):
  497.             pass
  498.         actionlist = self._gendict.get('*', { })
  499.         if not actionlist and not args:
  500.             return None
  501.         if not actionlist.get(action):
  502.             pass
  503.         (keylist, sortcache) = actionlist.get('*', (None, { }))
  504.         if not keylist and not args:
  505.             return None
  506.         keys = frozenset(kargs.keys())
  507.         cacheset = False
  508.         cachekey = unicode(keys)
  509.         cachelist = sortcache.get(cachekey)
  510.         if args:
  511.             keylist = args
  512.         elif cachelist:
  513.             keylist = cachelist
  514.         else:
  515.             cacheset = True
  516.             newlist = []
  517.             for route in keylist:
  518.                 if len(route.minkeys - route.dotkeys - keys) == 0:
  519.                     newlist.append(route)
  520.                     continue
  521.             
  522.             keylist = newlist
  523.             
  524.             def keysort(a, b):
  525.                 am = a.minkeys
  526.                 a = a.maxkeys
  527.                 b = b.maxkeys
  528.                 lendiffa = len(keys ^ a)
  529.                 lendiffb = len(keys ^ b)
  530.                 if lendiffa == 0 and lendiffb == 0:
  531.                     return 0
  532.                 if lendiffa == 0:
  533.                     return -1
  534.                 if lendiffb == 0:
  535.                     return 1
  536.                 if cmp(lendiffa, lendiffb) != 0:
  537.                     return cmp(lendiffa, lendiffb)
  538.                 if len(keys & b) == len(keys & a):
  539.                     return cmp(len(a), len(b))
  540.                 return cmp(len(keys & b), len(keys & a))
  541.  
  542.             keylist.sort(keysort)
  543.             if cacheset:
  544.                 sortcache[cachekey] = keylist
  545.             
  546.         for route in keylist:
  547.             fail = False
  548.             for key in route.hardcoded:
  549.                 kval = kargs.get(key)
  550.                 if not kval:
  551.                     continue
  552.                 
  553.                 if isinstance(kval, str):
  554.                     kval = kval.decode(self.encoding)
  555.                 else:
  556.                     kval = unicode(kval)
  557.                 if kval != route.defaults[key] and not callable(route.defaults[key]):
  558.                     fail = True
  559.                     break
  560.                     continue
  561.             
  562.             if fail:
  563.                 continue
  564.             
  565.             path = route.generate(**kargs)
  566.             if path:
  567.                 if self.prefix:
  568.                     path = self.prefix + path
  569.                 
  570.                 if route.static:
  571.                     pass
  572.                 external_static = route.external
  573.                 if self.environ and self.environ.get('SCRIPT_NAME', '') != '' and not (route.absolute) and not external_static:
  574.                     path = self.environ['SCRIPT_NAME'] + path
  575.                     key = cache_key_script_name
  576.                 else:
  577.                     key = cache_key
  578.                 if self.urlcache is not None:
  579.                     self.urlcache[key] = str(path)
  580.                 
  581.                 return str(path)
  582.         
  583.  
  584.     
  585.     def resource(self, member_name, collection_name, **kwargs):
  586.         collection = kwargs.pop('collection', { })
  587.         member = kwargs.pop('member', { })
  588.         new = kwargs.pop('new', { })
  589.         path_prefix = kwargs.pop('path_prefix', None)
  590.         name_prefix = kwargs.pop('name_prefix', None)
  591.         parent_resource = kwargs.pop('parent_resource', None)
  592.         if parent_resource is not None:
  593.             if path_prefix is None:
  594.                 path_prefix = '%s/:%s_id' % (parent_resource['collection_name'], parent_resource['member_name'])
  595.             
  596.             if name_prefix is None:
  597.                 name_prefix = '%s_' % parent_resource['member_name']
  598.             
  599.         elif path_prefix is None:
  600.             path_prefix = ''
  601.         
  602.         if name_prefix is None:
  603.             name_prefix = ''
  604.         
  605.         member['edit'] = 'GET'
  606.         new.update({
  607.             'new': 'GET' })
  608.         
  609.         def swap(dct, newdct):
  610.             for key, val in dct.iteritems():
  611.                 newdct.setdefault(val.upper(), []).append(key)
  612.             
  613.             return newdct
  614.  
  615.         collection_methods = swap(collection, { })
  616.         member_methods = swap(member, { })
  617.         new_methods = swap(new, { })
  618.         collection_methods.setdefault('POST', []).insert(0, 'create')
  619.         member_methods.setdefault('PUT', []).insert(0, 'update')
  620.         member_methods.setdefault('DELETE', []).insert(0, 'delete')
  621.         controller = strip_slashes(collection_name)
  622.         path_prefix = strip_slashes(path_prefix)
  623.         path_prefix = '/' + path_prefix
  624.         if path_prefix and path_prefix != '/':
  625.             path = path_prefix + '/' + controller
  626.         else:
  627.             path = '/' + controller
  628.         collection_path = path
  629.         new_path = path + '/new'
  630.         member_path = path + '/:(id)'
  631.         options = {
  632.             'controller': kwargs.get('controller', controller),
  633.             '_member_name': member_name,
  634.             '_collection_name': collection_name,
  635.             '_parent_resource': parent_resource,
  636.             '_filter': kwargs.get('_filter') }
  637.         
  638.         def requirements_for(meth):
  639.             opts = options.copy()
  640.             if method != 'any':
  641.                 opts['conditions'] = {
  642.                     'method': [
  643.                         meth.upper()] }
  644.             
  645.             return opts
  646.  
  647.         for method, lst in collection_methods.iteritems():
  648.             if not method != 'GET' or lst.pop(0):
  649.                 pass
  650.             primary = None
  651.             route_options = requirements_for(method)
  652.             for action in lst:
  653.                 route_options['action'] = action
  654.                 route_name = '%s%s_%s' % (name_prefix, action, collection_name)
  655.                 self.connect('formatted_' + route_name, '%s/%s.:(format)' % (collection_path, action), **route_options)
  656.                 self.connect(route_name, '%s/%s' % (collection_path, action), **route_options)
  657.             
  658.             if primary:
  659.                 route_options['action'] = primary
  660.                 self.connect('%s.:(format)' % collection_path, **route_options)
  661.                 self.connect(collection_path, **route_options)
  662.                 continue
  663.             (None, None)
  664.         
  665.         self.connect('formatted_' + name_prefix + collection_name, collection_path + '.:(format)', action = 'index', conditions = {
  666.             'method': [
  667.                 'GET'] }, **options)
  668.         self.connect(name_prefix + collection_name, collection_path, action = 'index', conditions = {
  669.             'method': [
  670.                 'GET'] }, **options)
  671.         for method, lst in new_methods.iteritems():
  672.             route_options = requirements_for(method)
  673.             for action in lst:
  674.                 if not action == 'new' or new_path:
  675.                     pass
  676.                 path = '%s/%s' % (new_path, action)
  677.                 name = 'new_' + member_name
  678.                 if action != 'new':
  679.                     name = action + '_' + name
  680.                 
  681.                 route_options['action'] = action
  682.                 if not action == 'new' or new_path + '.:(format)':
  683.                     pass
  684.                 formatted_path = '%s/%s.:(format)' % (new_path, action)
  685.                 self.connect('formatted_' + name_prefix + name, formatted_path, **route_options)
  686.                 self.connect(name_prefix + name, path, **route_options)
  687.             
  688.         
  689.         requirements_regexp = '[^\\/]+'
  690.         for method, lst in member_methods.iteritems():
  691.             route_options = requirements_for(method)
  692.             route_options['requirements'] = {
  693.                 'id': requirements_regexp }
  694.             if method not in ('POST', 'GET', 'any'):
  695.                 primary = lst.pop(0)
  696.             else:
  697.                 primary = None
  698.             for action in lst:
  699.                 route_options['action'] = action
  700.                 self.connect('formatted_%s%s_%s' % (name_prefix, action, member_name), '%s/%s.:(format)' % (member_path, action), **route_options)
  701.                 self.connect('%s%s_%s' % (name_prefix, action, member_name), '%s/%s' % (member_path, action), **route_options)
  702.             
  703.             if primary:
  704.                 route_options['action'] = primary
  705.                 self.connect('%s.:(format)' % member_path, **route_options)
  706.                 self.connect(member_path, **route_options)
  707.                 continue
  708.         
  709.         route_options = requirements_for('GET')
  710.         route_options['action'] = 'show'
  711.         route_options['requirements'] = {
  712.             'id': requirements_regexp }
  713.         self.connect('formatted_' + name_prefix + member_name, member_path + '.:(format)', **route_options)
  714.         self.connect(name_prefix + member_name, member_path, **route_options)
  715.  
  716.     
  717.     def redirect(self, match_path, destination_path, *args, **kwargs):
  718.         both_args = [
  719.             '_encoding',
  720.             '_explicit',
  721.             '_minimize']
  722.         gen_args = [
  723.             '_filter']
  724.         status_code = kwargs.pop('_redirect_code', '302 Found')
  725.         gen_dict = { }
  726.         match_dict = { }
  727.         for key in both_args + gen_args:
  728.             if key in kwargs:
  729.                 gen_dict[key] = kwargs[key]
  730.                 continue
  731.         
  732.         gen_dict['_static'] = True
  733.         for key in kwargs:
  734.             if key not in gen_args:
  735.                 match_dict[key] = kwargs[key]
  736.                 continue
  737.         
  738.         self.connect(match_path, **match_dict)
  739.         match_route = self.matchlist[-1]
  740.         self.connect('_redirect_%s' % id(match_route), destination_path, **gen_dict)
  741.         match_route.redirect = True
  742.         match_route.redirect_status = status_code
  743.  
  744.  
  745.