Mercurial > hgrepos > Python > libs > ConfigMix
comparison configmix/json.py @ 128:95ad65c69561
FIX: todo comment: allow **numbers** -- not strings
| author | Franz Glasner <hg@dom66.de> |
|---|---|
| date | Wed, 04 Apr 2018 20:54:32 +0200 |
| parents | 5b62d2c0e5a8 |
| children | df60417d7665 |
comparison
equal
deleted
inserted
replaced
| 127:5b62d2c0e5a8 | 128:95ad65c69561 |
|---|---|
| 38 def load(filename, encoding="utf-8"): | 38 def load(filename, encoding="utf-8"): |
| 39 """Load a single JSON file with name `filename` and encoding `encoding`. | 39 """Load a single JSON file with name `filename` and encoding `encoding`. |
| 40 | 40 |
| 41 .. todo:: Allow comments in JSON files | 41 .. todo:: Allow comments in JSON files |
| 42 | 42 |
| 43 .. todo:: Allow all Python string literals | 43 .. todo:: Allow all Python integer literals as numbers |
| 44 | 44 |
| 45 """ | 45 """ |
| 46 with io.open(filename, mode="rt", encoding=encoding) as jsfp: | 46 with io.open(filename, mode="rt", encoding=encoding) as jsfp: |
| 47 kwds = { | 47 kwds = { |
| 48 "parse_int": lambda n: int(n, 0), | 48 "parse_int": lambda s: int(s, 0), |
| 49 "strict": False | 49 "strict": False |
| 50 } | 50 } |
| 51 if _with_object_pairs_hook: | 51 if _with_object_pairs_hook: |
| 52 kwds["object_pairs_hook"] = DictImpl | 52 kwds["object_pairs_hook"] = DictImpl |
| 53 decoder = json.decoder.JSONDecoder(**kwds) | 53 decoder = json.decoder.JSONDecoder(**kwds) |
