Mercurial > ~astiob > upreckon > hgweb
comparison upreckon/config.py @ 228:715e3525a904 2.03
Fixed crashing on testconfs inside archives on Python 3
author | Oleg Oshmyan <chortos@inbox.lv> |
---|---|
date | Wed, 06 Jun 2012 20:41:44 +0100 |
parents | d66d5823bb1a |
children |
comparison
equal
deleted
inserted
replaced
226:ebb35960b5bc | 228:715e3525a904 |
---|---|
1 # Copyright (c) 2010-2011 Chortos-2 <chortos@inbox.lv> | 1 # Copyright (c) 2010-2012 Chortos-2 <chortos@inbox.lv> |
2 | 2 |
3 from __future__ import division, with_statement | 3 from __future__ import division, with_statement |
4 | 4 |
5 from .compat import * | 5 from .compat import * |
6 from . import files | 6 from . import files |
127 if not module: | 127 if not module: |
128 try: | 128 try: |
129 with metafile.open() as f: | 129 with metafile.open() as f: |
130 module = imp.load_module('testconf', f, metafile.full_real_path, ('.py', 'r', imp.PY_SOURCE)) | 130 module = imp.load_module('testconf', f, metafile.full_real_path, ('.py', 'r', imp.PY_SOURCE)) |
131 # Handle the case when f is not a true file object but imp requires one | 131 # Handle the case when f is not a true file object but imp requires one |
132 except ValueError: | 132 # TypeError on Python 3, ValueError on Python 2 |
133 except (TypeError, ValueError): | |
133 # FIXME: 2.5 lacks the delete parameter | 134 # FIXME: 2.5 lacks the delete parameter |
134 with tempfile.NamedTemporaryFile(delete=False) as f: | 135 with tempfile.NamedTemporaryFile(delete=False) as f: |
135 inputdatafname = f.name | 136 inputdatafname = f.name |
136 metafile.copy(inputdatafname) | 137 metafile.copy(inputdatafname) |
137 with ReadDeleting(inputdatafname) as f: | 138 with ReadDeleting(inputdatafname) as f: |
239 if not module: | 240 if not module: |
240 try: | 241 try: |
241 with metafile.open() as f: | 242 with metafile.open() as f: |
242 module = imp.load_module('testconf', f, metafile.full_real_path, ('.py', 'r', imp.PY_SOURCE)) | 243 module = imp.load_module('testconf', f, metafile.full_real_path, ('.py', 'r', imp.PY_SOURCE)) |
243 # Handle the case when f is not a true file object but imp requires one | 244 # Handle the case when f is not a true file object but imp requires one |
244 except ValueError: | 245 # TypeError on Python 3, ValueError on Python 2 |
246 except (TypeError, ValueError): | |
245 # FIXME: 2.5 lacks the delete parameter | 247 # FIXME: 2.5 lacks the delete parameter |
246 with tempfile.NamedTemporaryFile(delete=False) as f: | 248 with tempfile.NamedTemporaryFile(delete=False) as f: |
247 inputdatafname = f.name | 249 inputdatafname = f.name |
248 metafile.copy(inputdatafname) | 250 metafile.copy(inputdatafname) |
249 with ReadDeleting(inputdatafname) as f: | 251 with ReadDeleting(inputdatafname) as f: |