Show More
@@ -1,5 +1,6 b'' | |||||
1 | # coding: utf-8 |
|
1 | # coding: utf-8 | |
2 | """Compatibility tricks for Python 3. Mainly to do with unicode.""" |
|
2 | """Compatibility tricks for Python 3. Mainly to do with unicode.""" | |
|
3 | import __builtin__ | |||
3 | import functools |
|
4 | import functools | |
4 | import sys |
|
5 | import sys | |
5 | import re |
|
6 | import re | |
@@ -151,13 +152,21 b' else:' | |||||
151 | Accepts a string or a function, so it can be used as a decorator.""" |
|
152 | Accepts a string or a function, so it can be used as a decorator.""" | |
152 | return s.format(u='u') |
|
153 | return s.format(u='u') | |
153 |
|
154 | |||
154 | def execfile(fname, glob, loc=None): |
|
155 | if sys.platform == 'win32': | |
155 | loc = loc if (loc is not None) else glob |
|
156 | def execfile(fname, glob, loc=None): | |
156 | scripttext = file(fname).read() |
|
157 | loc = loc if (loc is not None) else glob | |
157 | #compile converts unicode filename to str assuming |
|
158 | scripttext = file(fname).read() | |
158 | #ascii. Let's do the conversion before calling compile |
|
159 | #compile converts unicode filename to str assuming | |
159 | if isinstance(fname, unicode): |
|
160 | #ascii. Let's do the conversion before calling compile | |
160 |
|
|
161 | if isinstance(fname, unicode): | |
161 | else: |
|
162 | filename = unicode_to_str(fname) | |
162 |
|
|
163 | else: | |
163 | exec compile(scripttext, filename, 'exec') in glob, loc |
|
164 | filename = fname | |
|
165 | exec compile(scripttext, filename, 'exec') in glob, loc | |||
|
166 | else: | |||
|
167 | def execfile(fname, glob, loc=None): | |||
|
168 | if isinstance(fname, unicode): | |||
|
169 | filename = fname.encode(sys.getfilesystemencoding()) | |||
|
170 | else: | |||
|
171 | filename = fname | |||
|
172 | __builtin__.execfile(filename, glob, loc) |
General Comments 0
You need to be logged in to leave comments.
Login now