Mercurial > piecrust2
comparison piecrust/page.py @ 979:45ad976712ec
tests: Big push to get the tests to pass again.
- Lots of fixes everywhere in the code.
- Try to handle debug logging in the multiprocessing worker pool when running in pytest. Not perfect, but usable for now.
- Replace all `.md` test files with `.html` since now a auto-format extension always sets the format.
- Replace `out` with `outfiles` in most places since now blog archives are added to the bake output and I don't want to add expected outputs for blog archives everywhere.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 29 Oct 2017 22:51:57 -0700 |
parents | 84d8fadf9e67 |
children | 1857dbd4580f |
comparison
equal
deleted
inserted
replaced
978:7e51d14097cb | 979:45ad976712ec |
---|---|
1 import re | 1 import re |
2 import json | 2 import json |
3 import hashlib | 3 import hashlib |
4 import logging | 4 import logging |
5 import datetime | 5 import datetime |
6 import dateutil.parser | |
7 import collections | 6 import collections |
8 from werkzeug.utils import cached_property | 7 from werkzeug.utils import cached_property |
9 from piecrust.configuration import ( | 8 from piecrust.configuration import ( |
10 Configuration, ConfigurationError, | 9 Configuration, ConfigurationError, |
11 parse_config_header, | 10 parse_config_header, |
174 def _parse_config_date(page_date): | 173 def _parse_config_date(page_date): |
175 if page_date is None: | 174 if page_date is None: |
176 return None | 175 return None |
177 | 176 |
178 if isinstance(page_date, str): | 177 if isinstance(page_date, str): |
178 import dateutil.parser | |
179 try: | 179 try: |
180 parsed_d = dateutil.parser.parse(page_date) | 180 parsed_d = dateutil.parser.parse(page_date) |
181 except Exception as ex: | 181 except Exception as ex: |
182 logger.exception(ex) | 182 logger.exception(ex) |
183 raise ConfigurationError("Invalid date: %s" % page_date) from ex | 183 raise ConfigurationError("Invalid date: %s" % page_date) from ex |
195 | 195 |
196 if isinstance(page_time, datetime.timedelta): | 196 if isinstance(page_time, datetime.timedelta): |
197 return page_time | 197 return page_time |
198 | 198 |
199 if isinstance(page_time, str): | 199 if isinstance(page_time, str): |
200 import dateutil.parser | |
200 try: | 201 try: |
201 parsed_t = dateutil.parser.parse(page_time) | 202 parsed_t = dateutil.parser.parse(page_time) |
202 except Exception as ex: | 203 except Exception as ex: |
203 logger.exception(ex) | 204 logger.exception(ex) |
204 raise ConfigurationError("Invalid time: %s" % page_time) from ex | 205 raise ConfigurationError("Invalid time: %s" % page_time) from ex |
304 def _count_lines(txt, start=0, end=-1): | 305 def _count_lines(txt, start=0, end=-1): |
305 cur = start | 306 cur = start |
306 line_count = 1 | 307 line_count = 1 |
307 while True: | 308 while True: |
308 nex = txt.find('\n', cur) | 309 nex = txt.find('\n', cur) |
309 if nex < 0: | 310 if nex < 0 or (end >= 0 and nex >= end): |
310 break | 311 break |
311 | 312 |
312 cur = nex + 1 | 313 cur = nex + 1 |
313 line_count += 1 | 314 line_count += 1 |
314 | 315 |
372 contents[m1.group('name')] = seg | 373 contents[m1.group('name')] = seg |
373 | 374 |
374 # Handle text past the last match. | 375 # Handle text past the last match. |
375 lastm = matches[-1] | 376 lastm = matches[-1] |
376 | 377 |
377 last_seg_start = lastm.end() | 378 last_seg_start = lastm.end() + 1 |
378 | 379 |
379 seg = ContentSegment( | 380 seg = ContentSegment( |
380 raw[last_seg_start:], | 381 raw[last_seg_start:], |
381 lastm.group('fmt'), | 382 lastm.group('fmt'), |
382 last_seg_start, | 383 last_seg_start, |