aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWaylan Limberg <waylan@gmail.com>2012-07-12 09:56:42 -0400
committerWaylan Limberg <waylan@gmail.com>2012-07-12 09:56:42 -0400
commitf087887ab9d18d55c686da366fa3a23b303272a0 (patch)
tree1b5a92ee3c04cd53b9269927652c4b2fb4dabd78
parent34cb4827da7eee2310ab285110cdadfdfbc85993 (diff)
downloadmarkdown-f087887ab9d18d55c686da366fa3a23b303272a0.tar.gz
markdown-f087887ab9d18d55c686da366fa3a23b303272a0.tar.bz2
markdown-f087887ab9d18d55c686da366fa3a23b303272a0.zip
Fixed #115. Make sure all file objects are closed.
-rwxr-xr-xsetup.py7
-rw-r--r--tests/__init__.py7
2 files changed, 10 insertions, 4 deletions
diff --git a/setup.py b/setup.py
index c666920..3491300 100755
--- a/setup.py
+++ b/setup.py
@@ -1,5 +1,6 @@
#!/usr/bin/env python
+from __future__ import with_statement
import sys, os
from distutils.core import setup
from distutils.command.install_scripts import install_scripts
@@ -126,7 +127,8 @@ class build_docs(Command):
except ImportError:
print ('skipping build_docs: Markdown "import" failed!')
else:
- template = codecs.open('docs/_template.html', encoding='utf-8').read()
+ with codecs.open('docs/_template.html', encoding='utf-8') as f:
+ template = f.read()
self.md = markdown.Markdown(extensions=['extra', 'toc', 'meta'])
for infile in self.docs:
outfile, ext = os.path.splitext(infile)
@@ -144,7 +146,8 @@ class build_docs(Command):
if self.verbose:
print ('Converting %s -> %s' % (infile, outfile))
if not self.dry_run:
- src = codecs.open(infile, encoding='utf-8').read()
+ with codecs.open(infile, encoding='utf-8') as f:
+ src = f.read()
out = template % self._get_context(src, outfile)
doc = open(outfile, 'wb')
doc.write(out.encode('utf-8'))
diff --git a/tests/__init__.py b/tests/__init__.py
index 26cc0d0..c790b09 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -1,3 +1,4 @@
+from __future__ import with_statement
import os
import markdown
import codecs
@@ -85,9 +86,11 @@ class CheckSyntax(object):
if config.get(cfg_section, 'skip'):
raise nose.plugins.skip.SkipTest, 'Test skipped per config.'
input_file = file + config.get(cfg_section, 'input_ext')
- input = codecs.open(input_file, encoding="utf-8").read()
+ with codecs.open(input_file, encoding="utf-8") as f:
+ input = f.read()
output_file = file + config.get(cfg_section, 'output_ext')
- expected_output = codecs.open(output_file, encoding="utf-8").read()
+ with codecs.open(output_file, encoding="utf-8") as f:
+ expected_output = f.read()
output = markdown.markdown(input, **get_args(file, config))
if tidy and config.get(cfg_section, 'normalize'):
# Normalize whitespace before comparing.