summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2011-09-24 07:48:12 -0400
committerChris McDonough <chrism@plope.com>2011-09-24 07:48:12 -0400
commitfccffe9c468ec652e07c13991cb340e76e82166d (patch)
tree1b4141f96c5530e0741bfc6bce4e6d8274176810
parenta0e8dfbc0ebcb45ac6b286cca8c08f9e6c5e9739 (diff)
downloadpyramid-fccffe9c468ec652e07c13991cb340e76e82166d.tar.gz
pyramid-fccffe9c468ec652e07c13991cb340e76e82166d.tar.bz2
pyramid-fccffe9c468ec652e07c13991cb340e76e82166d.zip
squash some open file warnings
-rw-r--r--pyramid/fixers/fix_bfg_imports.py1
-rw-r--r--pyramid/i18n.py11
-rw-r--r--pyramid/tests/test_integration.py6
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