From 876c7f509392d6c245a81e26fd5fd2a81851281f Mon Sep 17 00:00:00 2001 From: dave mankoff Date: Sun, 10 Jun 2012 18:26:53 -0400 Subject: [PATCH] turn utils.open into actual context manager so as to better handle encoding warnings --- pelican/utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pelican/utils.py b/pelican/utils.py index d4e34842..db15a343 100644 --- a/pelican/utils.py +++ b/pelican/utils.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +import contextlib import os import re import pytz @@ -32,10 +33,10 @@ def get_date(string): pass raise ValueError("'%s' is not a valid date" % string) - +@contextlib.contextmanager def open(filename): """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):