##// END OF EJS Templates
Fix syntax for Python 2.6 - no set literals.
Thomas -
Show More
@@ -1,23 +1,23 b''
1 """Utilities for working with Python source files.
1 """Utilities for working with Python source files.
2
2
3 Exposes various functions from recent Python standard libraries, along with
3 Exposes various functions from recent Python standard libraries, along with
4 equivalents for older Python versions.
4 equivalents for older Python versions.
5 """
5 """
6 import os.path
6 import os.path
7
7
8 try: # Python 3.2
8 try: # Python 3.2
9 from imp import source_from_cache, cache_from_source
9 from imp import source_from_cache, cache_from_source
10 except ImportError:
10 except ImportError:
11 # Python <= 3.1: .pyc files go next to .py
11 # Python <= 3.1: .pyc files go next to .py
12 def source_from_cache(path):
12 def source_from_cache(path):
13 basename, ext = os.path.splitext(path)
13 basename, ext = os.path.splitext(path)
14 if ext not in {'.pyc', '.pyo'}:
14 if ext not in ('.pyc', '.pyo'):
15 raise ValueError('Not a cached Python file extension', ext)
15 raise ValueError('Not a cached Python file extension', ext)
16 # Should we look for .pyw files?
16 # Should we look for .pyw files?
17 return basename + '.py'
17 return basename + '.py'
18
18
19 def cache_from_source(path, debug_override=None):
19 def cache_from_source(path, debug_override=None):
20 if debug_override is None:
20 if debug_override is None:
21 debug_override = __debug__
21 debug_override = __debug__
22 basename, ext = os.path.splitext(path)
22 basename, ext = os.path.splitext(path)
23 return basename + '.pyc' if debug_override else '.pyo'
23 return basename + '.pyc' if debug_override else '.pyo'
General Comments 0
You need to be logged in to leave comments. Login now