Mercurial > ~astiob > upreckon > hgweb
comparison config.py @ 70:b9d5857f7b9a
Better emulation of built-ins for testconf
Bug fix: next is now in compat.__all__.
Members of compat that do not correspond to built-ins or members of itertools are no longer added to built-ins while loading testconf.
xrange is now added to built-ins only while loading testconf and only in legacy mode.
testconf can now access the original built-ins through the CompatBuiltins context manager which is now exposed as config.builtins.
Bug fix: the default string encoding is no longer relied upon.
| author | Oleg Oshmyan <chortos@inbox.lv> |
|---|---|
| date | Mon, 03 Jan 2011 01:27:56 +0200 |
| parents | 7c6dba0b84f2 |
| children | b071ef77377c |
comparison
equal
deleted
inserted
replaced
| 69:c0f1b87013ad | 70:b9d5857f7b9a |
|---|---|
| 84 def __exit__(self, exc_type, exc_val, exc_tb): | 84 def __exit__(self, exc_type, exc_val, exc_tb): |
| 85 self.file.close() | 85 self.file.close() |
| 86 os.remove(self.name) | 86 os.remove(self.name) |
| 87 | 87 |
| 88 def load_problem(problem_name): | 88 def load_problem(problem_name): |
| 89 global builtins | |
| 89 dwb = sys.dont_write_bytecode | 90 dwb = sys.dont_write_bytecode |
| 90 sys.dont_write_bytecode = True | 91 sys.dont_write_bytecode = True |
| 91 metafile = files.File('/'.join((problem_name, 'testconf.py')), True, 'configuration') | 92 metafile = files.File('/'.join((problem_name, 'testconf.py')), True, 'configuration') |
| 92 module = None | 93 module = None |
| 93 with CompatBuiltins(): | 94 with CompatBuiltins() as builtins: |
| 94 if zipimport and isinstance(metafile.archive, files.ZipArchive): | 95 if zipimport and isinstance(metafile.archive, files.ZipArchive): |
| 95 try: | 96 try: |
| 96 module = zipimport.zipimporter(os.path.dirname(metafile.full_real_path)).load_module('testconf') | 97 module = zipimport.zipimporter(os.path.dirname(metafile.full_real_path)).load_module('testconf') |
| 97 except zipimport.ZipImportError: | 98 except zipimport.ZipImportError: |
| 98 pass | 99 pass |
| 152 if hasattr(module, name): | 153 if hasattr(module, name): |
| 153 setattr(module, name, getattr(module, name).replace('%', problem_name)) | 154 setattr(module, name, getattr(module, name).replace('%', problem_name)) |
| 154 return module | 155 return module |
| 155 | 156 |
| 156 def load_global(): | 157 def load_global(): |
| 158 global builtins | |
| 157 dwb = sys.dont_write_bytecode | 159 dwb = sys.dont_write_bytecode |
| 158 sys.dont_write_bytecode = True | 160 sys.dont_write_bytecode = True |
| 159 metafile = files.File('testconf.py', True, 'configuration') | 161 metafile = files.File('testconf.py', True, 'configuration') |
| 160 module = None | 162 module = None |
| 161 with CompatBuiltins(): | 163 with CompatBuiltins() as builtins: |
| 162 if zipimport and isinstance(metafile.archive, files.ZipArchive): | 164 if zipimport and isinstance(metafile.archive, files.ZipArchive): |
| 163 try: | 165 try: |
| 164 module = zipimport.zipimporter(os.path.dirname(metafile.full_real_path)).load_module('testconf') | 166 module = zipimport.zipimporter(os.path.dirname(metafile.full_real_path)).load_module('testconf') |
| 165 except zipimport.ZipImportError: | 167 except zipimport.ZipImportError: |
| 166 pass | 168 pass |
