comparison piecrust/routing.py @ 854:08e02c2a2a1a

core: Keep refactoring, this time to prepare for generator sources. - Make a few APIs simpler. - Content pipelines create their own jobs, so that generator sources can keep aborting in `getContents`, but rely on their pipeline to generate pages for baking.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 04 Jun 2017 23:34:28 -0700
parents 4850f8c21b6e
children 45ad976712ec
comparison
equal deleted inserted replaced
853:f070a4fc033c 854:08e02c2a2a1a
1 import re 1 import re
2 import os.path 2 import os.path
3 import copy
3 import logging 4 import logging
4 import urllib.parse 5 import urllib.parse
5 from werkzeug.utils import cached_property 6 from werkzeug.utils import cached_property
6 7
7 8
39 Each route defines the "shape" of an URL and how it maps to 40 Each route defines the "shape" of an URL and how it maps to
40 content sources. 41 content sources.
41 """ 42 """
42 def __init__(self, app, cfg): 43 def __init__(self, app, cfg):
43 self.app = app 44 self.app = app
45 self.config = copy.deepcopy(cfg)
44 46
45 self.source_name = cfg['source'] 47 self.source_name = cfg['source']
46 self.uri_pattern = cfg['url'].lstrip('/') 48 self.uri_pattern = cfg['url'].lstrip('/')
49 self.pass_num = cfg['pass']
47 50
48 self.supported_params = self.source.getSupportedRouteParameters() 51 self.supported_params = self.source.getSupportedRouteParameters()
49 52
50 self.pretty_urls = app.config.get('site/pretty_urls') 53 self.pretty_urls = app.config.get('site/pretty_urls')
51 self.trailing_slash = app.config.get('site/trailing_slash') 54 self.trailing_slash = app.config.get('site/trailing_slash')
228 route_params = {} 231 route_params = {}
229 for arg_name, arg_val in zip(self.uri_params, coerced_args): 232 for arg_name, arg_val in zip(self.uri_params, coerced_args):
230 route_params[arg_name] = self._coerceRouteParameter( 233 route_params[arg_name] = self._coerceRouteParameter(
231 arg_name, arg_val) 234 arg_name, arg_val)
232 235
233 self.source.onRouteFunctionUsed(self, route_params) 236 self.source.onRouteFunctionUsed(route_params)
234 237
235 return self.getUri(route_params) 238 return self.getUri(route_params)
236 239
237 def _uriFormatRepl(self, m): 240 def _uriFormatRepl(self, m):
238 if m.group('qual') or m.group('var'): 241 if m.group('qual') or m.group('var'):
308 def __init__(self, route): 311 def __init__(self, route):
309 self._route = route 312 self._route = route
310 313
311 def __call__(self, *args, **kwargs): 314 def __call__(self, *args, **kwargs):
312 return self._route.execTemplateFunc(*args, **kwargs) 315 return self._route.execTemplateFunc(*args, **kwargs)
316
317 def _isCompatibleRoute(self, route):
318 return self._route.uri_pattern == route.uri_pattern