From b6f3cb8e7cb7fd24fbe91d87fdd38cf060b8947a Mon Sep 17 00:00:00 2001 From: Jeryn Mathew Date: Mon, 17 Mar 2014 10:26:53 +0530 Subject: [PATCH] Fix for issue #693 - Added changes to file read, as per review comments --- gunicorn/six.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/gunicorn/six.py b/gunicorn/six.py index e47a289a..f4fb9b86 100644 --- a/gunicorn/six.py +++ b/gunicorn/six.py @@ -315,11 +315,13 @@ def _get_codeobj(pyfile): # WARNING: # fp.read() can blowup if the module is extremely large file. # Lookout for overflow errors. - if result is PY_COMPILED: - # This is a .pyc file. Treat accordingly. + try: data = fileobj.read() + finally: fileobj.close() + # This is a .pyc file. Treat accordingly. + if result is PY_COMPILED: # .pyc format is as follows: # 0 - 4 bytes: Magic number, which changes with each create of .pyc file. # First 2 bytes change with each marshal of .pyc file. Last 2 bytes is "\r\n". @@ -331,8 +333,7 @@ def _get_codeobj(pyfile): elif result is PY_SOURCE: # This is a .py file. - code_obj = compile(fileobj.read(), fullpath, 'exec') - fileobj.close() + code_obj = compile(data, fullpath, 'exec') else: # Unsupported extension