28
28
>>> from past.translation import remove_hooks
29
29
>>> remove_hooks()
30
30
31
- Author: Ed Schofield.
31
+ Author: Ed Schofield.
32
32
Inspired by and based on ``uprefix`` by Vinay M. Sajip.
33
33
"""
34
34
@@ -219,22 +219,9 @@ def detect_python2(source, pathname):
219
219
if source != str (tree )[:- 1 ]: # remove added newline
220
220
# The above fixers made changes, so we conclude it's Python 2 code
221
221
logger .debug ('Detected Python 2 code: {0}' .format (pathname ))
222
- with open ('/tmp/original_code.py' , 'w' ) as f :
223
- f .write ('### Original code (detected as py2): %s\n %s' %
224
- (pathname , source ))
225
- with open ('/tmp/py2_detection_code.py' , 'w' ) as f :
226
- f .write ('### Code after running py3 detection (from %s)\n %s' %
227
- (pathname , str (tree )[:- 1 ]))
228
222
return True
229
223
else :
230
224
logger .debug ('Detected Python 3 code: {0}' .format (pathname ))
231
- with open ('/tmp/original_code.py' , 'w' ) as f :
232
- f .write ('### Original code (detected as py3): %s\n %s' %
233
- (pathname , source ))
234
- try :
235
- os .remove ('/tmp/futurize_code.py' )
236
- except OSError :
237
- pass
238
225
return False
239
226
240
227
@@ -359,15 +346,15 @@ def load_module(self, fullname):
359
346
# Is the test in the next line more or less robust than the
360
347
# following one? Presumably less ...
361
348
# ispkg = self.pathname.endswith('__init__.py')
362
-
349
+
363
350
if self .kind == imp .PKG_DIRECTORY :
364
351
mod .__path__ = [ os .path .dirname (self .pathname ) ]
365
352
mod .__package__ = fullname
366
353
else :
367
354
#else, regular module
368
355
mod .__path__ = []
369
356
mod .__package__ = fullname .rpartition ('.' )[0 ]
370
-
357
+
371
358
try :
372
359
cachename = imp .cache_from_source (self .pathname )
373
360
if not os .path .exists (cachename ):
@@ -395,9 +382,6 @@ def load_module(self, fullname):
395
382
396
383
if detect_python2 (source , self .pathname ):
397
384
source = self .transform (source )
398
- with open ('/tmp/futurized_code.py' , 'w' ) as f :
399
- f .write ('### Futurized code (from %s)\n %s' %
400
- (self .pathname , source ))
401
385
402
386
code = compile (source , self .pathname , 'exec' )
403
387
@@ -457,7 +441,7 @@ def detect_hooks():
457
441
class hooks (object ):
458
442
"""
459
443
Acts as a context manager. Use like this:
460
-
444
+
461
445
>>> from past import translation
462
446
>>> with translation.hooks():
463
447
... import mypy2module
@@ -477,7 +461,7 @@ def __exit__(self, *args):
477
461
class suspend_hooks (object ):
478
462
"""
479
463
Acts as a context manager. Use like this:
480
-
464
+
481
465
>>> from past import translation
482
466
>>> translation.install_hooks()
483
467
>>> import http.client
@@ -495,4 +479,3 @@ def __enter__(self):
495
479
def __exit__ (self , * args ):
496
480
if self .hooks_were_installed :
497
481
install_hooks ()
498
-
0 commit comments