Mercurial > hgrepos > Python > libs > ConfigMix
comparison configmix/py.py @ 166:b5ce9a8461bf
Use the filesystem encoding explicitely where appropriate.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Thu, 14 Mar 2019 01:35:16 +0100 |
| parents | e2e8d21b4122 |
| children | b3b5ed34d180 |
comparison
equal
deleted
inserted
replaced
| 165:6ca90e80f4f4 | 166:b5ce9a8461bf |
|---|---|
| 16 try: | 16 try: |
| 17 from ordereddict import OrderedDict as DictImpl | 17 from ordereddict import OrderedDict as DictImpl |
| 18 except ImportError: | 18 except ImportError: |
| 19 DictImpl = dict | 19 DictImpl = dict |
| 20 | 20 |
| 21 from .compat import PY2 | 21 from .compat import PY2, u2fs |
| 22 | 22 |
| 23 | 23 |
| 24 __all__ = ["load"] | 24 __all__ = ["load"] |
| 25 | 25 |
| 26 | 26 |
| 41 if not isinstance(extract, (type([]), type(tuple()), type(set()), )): | 41 if not isinstance(extract, (type([]), type(tuple()), type(set()), )): |
| 42 raise TypeError("`extract' must be a sequence") | 42 raise TypeError("`extract' must be a sequence") |
| 43 gcontext = DictImpl() | 43 gcontext = DictImpl() |
| 44 lcontext = DictImpl() | 44 lcontext = DictImpl() |
| 45 if PY2: | 45 if PY2: |
| 46 filename2 = filename.encode(locale.getpreferredencoding()) | 46 execfile(u2fs(filename, True), gcontext, lcontext) |
| 47 if PY2: | |
| 48 execfile(filename2, gcontext, lcontext) | |
| 49 else: | 47 else: |
| 50 # "rb" mode allows Python to derive the encoding automatically | 48 # "rb" mode allows Python to derive the encoding automatically |
| 51 with open(filename, "rb") as vf: | 49 with open(filename, "rb") as vf: |
| 52 code = compile(vf.read(), filename, "exec") | 50 code = compile(vf.read(), filename, "exec") |
| 53 exec(code, gcontext, lcontext) | 51 exec(code, gcontext, lcontext) |
