mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
turn utils.open into actual context manager so as to better handle encoding warnings
This commit is contained in:
parent
9fb5969c59
commit
876c7f5093
1 changed files with 3 additions and 2 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
import contextlib
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import pytz
|
import pytz
|
||||||
|
|
@ -32,10 +33,10 @@ def get_date(string):
|
||||||
pass
|
pass
|
||||||
raise ValueError("'%s' is not a valid date" % string)
|
raise ValueError("'%s' is not a valid date" % string)
|
||||||
|
|
||||||
|
@contextlib.contextmanager
|
||||||
def open(filename):
|
def open(filename):
|
||||||
"""Open a file and return it's content"""
|
"""Open a file and return it's content"""
|
||||||
return _open(filename, encoding='utf-8').read()
|
yield _open(filename, encoding='utf-8').read()
|
||||||
|
|
||||||
|
|
||||||
def slugify(value):
|
def slugify(value):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue