Skip to content

Commit

Permalink
Fixed Python-Markdown#115. Make sure all file objects are closed.
Browse files Browse the repository at this point in the history
  • Loading branch information
Waylan Limberg committed Jul 12, 2012
1 parent 34cb482 commit f087887
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -126,7 +127,8 @@ def run(self):
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)
Expand All @@ -144,7 +146,8 @@ def run(self):
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'))
Expand Down
7 changes: 5 additions & 2 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import with_statement
import os
import markdown
import codecs
Expand Down Expand Up @@ -85,9 +86,11 @@ def __call__(self, file, config):
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.
Expand Down

0 comments on commit f087887

Please sign in to comment.