Mercurial > piecrust2
comparison piecrust/serving/util.py @ 853:f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
The asset pipeline is still the only function pipeline at this point.
* No more `QualifiedPage`, and several other pieces of code deleted.
* Data providers are simpler and more focused. For instance, the page iterator
doesn't try to support other types of items.
* Route parameters are proper known source metadata to remove the confusion
between the two.
* Make the baker and pipeline more correctly manage records and record
histories.
* Add support for record collapsing and deleting stale outputs in the asset
pipeline.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 21 May 2017 00:06:59 -0700 |
parents | 4850f8c21b6e |
children | 08e02c2a2a1a |
comparison
equal
deleted
inserted
replaced
852:4850f8c21b6e | 853:f070a4fc033c |
---|---|
3 import hashlib | 3 import hashlib |
4 import logging | 4 import logging |
5 import datetime | 5 import datetime |
6 from werkzeug.wrappers import Response | 6 from werkzeug.wrappers import Response |
7 from werkzeug.wsgi import wrap_file | 7 from werkzeug.wsgi import wrap_file |
8 from piecrust.page import QualifiedPage, PageNotFoundError | 8 from piecrust.page import PageNotFoundError |
9 from piecrust.routing import RouteNotFoundError | 9 from piecrust.routing import RouteNotFoundError |
10 from piecrust.uriutil import split_sub_uri | 10 from piecrust.uriutil import split_sub_uri |
11 | 11 |
12 | 12 |
13 logger = logging.getLogger(__name__) | 13 logger = logging.getLogger(__name__) |
20 return app | 20 return app |
21 | 21 |
22 | 22 |
23 class RequestedPage(object): | 23 class RequestedPage(object): |
24 def __init__(self): | 24 def __init__(self): |
25 self.qualified_page = None | 25 self.page = None |
26 self.sub_num = 1 | |
26 self.req_path = None | 27 self.req_path = None |
27 self.not_found_errors = [] | 28 self.not_found_errors = [] |
28 | 29 |
29 | 30 |
30 def find_routes(routes, uri, sub_num=1): | 31 def find_routes(routes, uri, sub_num=1): |
60 for route, route_params, route_sub_num in routes: | 61 for route, route_params, route_sub_num in routes: |
61 cur_req_path = req_path | 62 cur_req_path = req_path |
62 if route_sub_num > 1: | 63 if route_sub_num > 1: |
63 cur_req_path = req_path_no_num | 64 cur_req_path = req_path_no_num |
64 | 65 |
65 qp = _get_requested_page_for_route(app, route, route_params, | 66 page = _get_requested_page_for_route(app, route, route_params, |
66 route_sub_num) | 67 route_sub_num) |
67 if qp is not None: | 68 if page is not None: |
68 req_page.qualified_page = qp | 69 req_page.page = page |
70 req_page.sub_num = route_sub_num | |
69 req_page.req_path = cur_req_path | 71 req_page.req_path = cur_req_path |
70 break | 72 break |
71 | 73 |
72 req_page.not_found_errors.append(PageNotFoundError( | 74 req_page.not_found_errors.append(PageNotFoundError( |
73 "No path found for '%s' in source '%s'." % | 75 "No path found for '%s' in source '%s'." % |
74 (cur_req_path, route.source_name))) | 76 (cur_req_path, route.source_name))) |
75 | 77 |
76 return req_page | 78 return req_page |
77 | 79 |
78 | 80 |
79 def _get_requested_page_for_route(app, route, route_params, sub_num): | 81 def _get_requested_page_for_route(app, route, route_params): |
80 source = app.getSource(route.source_name) | 82 source = app.getSource(route.source_name) |
81 item = source.findContent(route_params) | 83 item = source.findContent(route_params) |
82 if item is None: | 84 if item is not None: |
83 return None | 85 return app.getPage(item) |
84 | 86 return None |
85 # Build the page. | |
86 page = app.getPage(item) | |
87 qp = QualifiedPage(page, route, route_params, sub_num) | |
88 return qp | |
89 | 87 |
90 | 88 |
91 def load_mimetype_map(): | 89 def load_mimetype_map(): |
92 mimetype_map = {} | 90 mimetype_map = {} |
93 sep_re = re.compile(r'\s+') | 91 sep_re = re.compile(r'\s+') |