mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Fix bug with MacOS in utils.strftime
Force using C89 directives (i.e. mentioned in the Python documentation).
This commit is contained in:
parent
598cbeb3be
commit
3aea29fb2b
2 changed files with 7 additions and 14 deletions
|
|
@ -39,7 +39,7 @@ def strftime(date, date_format):
|
|||
'''
|
||||
|
||||
# grab candidate format options
|
||||
format_options = '%+.?'
|
||||
format_options = '%.'
|
||||
candidates = re.findall(format_options, date_format)
|
||||
|
||||
# replace candidates with placeholders for later % formatting
|
||||
|
|
@ -51,19 +51,14 @@ def strftime(date, date_format):
|
|||
|
||||
formatted_candidates = []
|
||||
for candidate in candidates:
|
||||
try:
|
||||
# a valid format string should be ascii
|
||||
candidate.encode('ascii')
|
||||
except UnicodeEncodeError:
|
||||
# if it fails, it's not a valid format option
|
||||
# put the candidate back as it was
|
||||
formatted = candidate
|
||||
else:
|
||||
# if it's ascii, pass it to strftime to format
|
||||
# test for valid C89 directives only
|
||||
if candidate[1] in 'aAbBcdfHIjmMpSUwWxXyYzZ%':
|
||||
formatted = date.strftime(candidate)
|
||||
# convert Py2 result to unicode
|
||||
if not six.PY3 and enc is not None:
|
||||
formatted = formatted.decode(enc)
|
||||
else:
|
||||
formatted = candidate
|
||||
formatted_candidates.append(formatted)
|
||||
|
||||
# put formatted candidates back and return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue