comparison piecrust/sources/posts.py @ 281:0641fe5c3ef9

serve: Don't crash when a post URL doesn't match our expectations. It can happen that a posts source's URL pattern matches that of something else, like a taxonomy page. In this case, don't crash when what we think will be integers turn out to be something else. Instead, just return that no page has been found.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 01 Mar 2015 21:41:05 -0800
parents ba857c693c72
children dd25bd3ce1f9
comparison
equal deleted inserted replaced
280:8c0c53a315ae 281:0641fe5c3ef9
36 year = metadata.get('year') 36 year = metadata.get('year')
37 month = metadata.get('month') 37 month = metadata.get('month')
38 day = metadata.get('day') 38 day = metadata.get('day')
39 slug = metadata.get('slug') 39 slug = metadata.get('slug')
40 40
41 if year is not None: 41 try:
42 year = int(year) 42 if year is not None:
43 if month is not None: 43 year = int(year)
44 month = int(month) 44 if month is not None:
45 if day is not None: 45 month = int(month)
46 day = int(day) 46 if day is not None:
47 day = int(day)
48 except ValueError:
49 return None, None
47 50
48 ext = metadata.get('ext') 51 ext = metadata.get('ext')
49 if ext is None: 52 if ext is None:
50 if len(self.supported_extensions) == 1: 53 if len(self.supported_extensions) == 1:
51 ext = self.supported_extensions[0] 54 ext = self.supported_extensions[0]