From fccffe9c468ec652e07c13991cb340e76e82166d Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Sat, 24 Sep 2011 07:48:12 -0400 Subject: squash some open file warnings --- pyramid/fixers/fix_bfg_imports.py | 1 + pyramid/i18n.py | 11 ++++++----- pyramid/tests/test_integration.py | 6 +++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/pyramid/fixers/fix_bfg_imports.py b/pyramid/fixers/fix_bfg_imports.py index 8fd32a797..d9a4a6dfb 100644 --- a/pyramid/fixers/fix_bfg_imports.py +++ b/pyramid/fixers/fix_bfg_imports.py @@ -199,6 +199,7 @@ def fix_zcml(path): newf.write(newt) newf.flush() newf.close() + text.close() for dir in dirs: if dir.startswith('.'): diff --git a/pyramid/i18n.py b/pyramid/i18n.py index 040e581b5..082723cd3 100644 --- a/pyramid/i18n.py +++ b/pyramid/i18n.py @@ -180,10 +180,10 @@ def make_localizer(current_locale_name, translation_directories): mopath = os.path.realpath(os.path.join(messages_dir, mofile)) if mofile.endswith('.mo') and os.path.isfile(mopath): - mofp = open(mopath, 'rb') - domain = mofile[:-3] - dtrans = Translations(mofp, domain) - translations.add(dtrans) + with open(mopath, 'rb') as mofp: + domain = mofile[:-3] + dtrans = Translations(mofp, domain) + translations.add(dtrans) return Localizer(locale_name=current_locale_name, translations=translations) @@ -257,7 +257,8 @@ class Translations(gettext.GNUTranslations, object): filename = gettext.find(domain, dirname, locales) if not filename: return gettext.NullTranslations() - return cls(fileobj=open(filename, 'rb'), domain=domain) + with open(filename, 'rb') as fp: + return cls(fileobj=fp, domain=domain) def __repr__(self): return '<%s: "%s">' % (type(self).__name__, diff --git a/pyramid/tests/test_integration.py b/pyramid/tests/test_integration.py index 2bd060ac1..286e1146b 100644 --- a/pyramid/tests/test_integration.py +++ b/pyramid/tests/test_integration.py @@ -228,7 +228,7 @@ class TestStaticPermApp(IntegrationBase, unittest.TestCase): result = self.testapp.get('/allowed/index.html', status=200) self.assertEqual( result.body.replace(b'\r', b''), - open(os.path.join(here, 'fixtures/static/index.html'), 'rb').read()) + read_(os.path.join(here, 'fixtures/static/index.html'))) def test_denied_via_acl_global_root_factory(self): self.testapp.extra_environ = {'REMOTE_USER':'bob'} @@ -239,7 +239,7 @@ class TestStaticPermApp(IntegrationBase, unittest.TestCase): result = self.testapp.get('/protected/index.html', status=200) self.assertEqual( result.body.replace(b'\r', b''), - open(os.path.join(here, 'fixtures/static/index.html'), 'rb').read()) + read_(os.path.join(here, 'fixtures/static/index.html'))) def test_denied_via_acl_local_root_factory(self): self.testapp.extra_environ = {'REMOTE_USER':'fred'} @@ -250,7 +250,7 @@ class TestStaticPermApp(IntegrationBase, unittest.TestCase): result = self.testapp.get('/factory_protected/index.html', status=200) self.assertEqual( result.body.replace(b'\r', b''), - open(os.path.join(here, 'fixtures/static/index.html'), 'rb').read()) + read_(os.path.join(here, 'fixtures/static/index.html'))) class TestCCBug(IntegrationBase, unittest.TestCase): # "unordered" as reported in IRC by author of -- cgit v1.2.3