Import upstream version 0.9.0+git20210123.1.c8678f4
Debian Janitor
2 years ago
0 | The MIT License (MIT) | |
1 | ||
2 | Copyright (c) 2014 Vaidik Kapoor | |
3 | ||
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of | |
5 | this software and associated documentation files (the "Software"), to deal in | |
6 | the Software without restriction, including without limitation the rights to | |
7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | |
8 | the Software, and to permit persons to whom the Software is furnished to do so, | |
9 | subject to the following conditions: | |
10 | ||
11 | The above copyright notice and this permission notice shall be included in all | |
12 | copies or substantial portions of the Software. | |
13 | ||
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | |
16 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | |
17 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | |
18 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | |
19 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
0 | include *.rst |
0 | Metadata-Version: 1.1 | |
0 | Metadata-Version: 2.1 | |
1 | 1 | Name: commentjson |
2 | Version: 0.8.3 | |
2 | Version: 0.9.0 | |
3 | 3 | Summary: Add Python and JavaScript style comments in your JSON files. |
4 | 4 | Home-page: https://github.com/vaidik/commentjson |
5 | 5 | Author: Vaidik Kapoor |
6 | 6 | Author-email: kapoor.vaidik@gmail.com |
7 | 7 | License: UNKNOWN |
8 | Description: =========== | |
9 | commentjson | |
10 | =========== | |
11 | ||
12 | `commentjson` (Comment JSON) is a Python package that helps you create JSON | |
13 | files with Python and JavaScript style inline comments. Its API is very similar | |
14 | to the Python standard library's `json`_ module. | |
15 | ||
16 | .. _`json`: http://docs.python.org/2/library/json.html | |
17 | ||
18 | .. image:: https://travis-ci.org/vaidik/commentjson.png | |
19 | ||
20 | Installation | |
21 | ============ | |
22 | ||
23 | pip install commentjson | |
24 | ||
25 | Basic Usage | |
26 | =========== | |
27 | ||
28 | .. code-block:: python | |
29 | ||
30 | >>> import commentjson | |
31 | >>> | |
32 | >>> json_string = """{ | |
33 | ... "name": "Vaidik Kapoor", # Person's name | |
34 | ... "location": "Delhi, India", // Person's location | |
35 | ... | |
36 | ... # Section contains info about | |
37 | ... // person's appearance | |
38 | ... "appearance": { | |
39 | ... "hair_color": "black", | |
40 | ... "eyes_color": "black", | |
41 | ... "height": "6" | |
42 | ... } | |
43 | ... }""" | |
44 | >>> | |
45 | >>> json_loaded = commentjson.loads(json_string) | |
46 | >>> print json_loaded | |
47 | {u'appearance': {u'eyes_color': u'black', u'hair_color': u'black', u'height': u'6'}, u'name': u'Vaidik Kapoor', u'location': u'Delhi, India'} | |
48 | ||
49 | Documentation | |
50 | ============= | |
51 | ||
52 | Complete documentation can be found `here`_. | |
53 | ||
54 | .. _`here`: http://commentjson.readthedocs.org/en/latest/ | |
55 | ||
56 | Tests | |
57 | ===== | |
58 | ||
59 | python setup.py test | |
60 | ||
61 | License | |
62 | ======= | |
63 | ||
64 | See `license`_. | |
65 | ||
66 | .. _`license`: https://github.com/vaidik/commentjson/blob/master/LICENSE.rst | |
67 | ||
68 | ||
69 | ||
70 | 8 | Platform: UNKNOWN |
71 | 9 | Classifier: Programming Language :: Python |
10 | License-File: LICENSE.rst | |
11 | ||
12 | =========== | |
13 | commentjson | |
14 | =========== | |
15 | ||
16 | `commentjson` (Comment JSON) is a Python package that helps you create JSON | |
17 | files with Python and JavaScript style inline comments. Its API is very similar | |
18 | to the Python standard library's `json`_ module. | |
19 | ||
20 | .. _`json`: http://docs.python.org/2/library/json.html | |
21 | ||
22 | .. image:: https://travis-ci.org/vaidik/commentjson.png | |
23 | ||
24 | Installation | |
25 | ============ | |
26 | ||
27 | pip install commentjson | |
28 | ||
29 | Basic Usage | |
30 | =========== | |
31 | ||
32 | .. code-block:: python | |
33 | ||
34 | >>> import commentjson | |
35 | >>> | |
36 | >>> json_string = """{ | |
37 | ... "name": "Vaidik Kapoor", # Person's name | |
38 | ... "location": "Delhi, India", // Person's location | |
39 | ... | |
40 | ... # Section contains info about | |
41 | ... // person's appearance | |
42 | ... "appearance": { | |
43 | ... "hair_color": "black", | |
44 | ... "eyes_color": "black", | |
45 | ... "height": "6" | |
46 | ... } | |
47 | ... }""" | |
48 | >>> | |
49 | >>> json_loaded = commentjson.loads(json_string) | |
50 | >>> print json_loaded | |
51 | {u'appearance': {u'eyes_color': u'black', u'hair_color': u'black', u'height': u'6'}, u'name': u'Vaidik Kapoor', u'location': u'Delhi, India'} | |
52 | ||
53 | Documentation | |
54 | ============= | |
55 | ||
56 | Complete documentation can be found `here`_. | |
57 | ||
58 | .. _`here`: http://commentjson.readthedocs.org/en/latest/ | |
59 | ||
60 | Tests | |
61 | ===== | |
62 | ||
63 | python setup.py test | |
64 | ||
65 | License | |
66 | ======= | |
67 | ||
68 | See `license`_. | |
69 | ||
70 | .. _`license`: https://github.com/vaidik/commentjson/blob/master/LICENSE.rst | |
71 | ||
72 | ||
73 | ||
74 |
25 | 25 | import lark |
26 | 26 | |
27 | 27 | from lark import Lark |
28 | from lark.lexer import Token | |
28 | 29 | from lark.reconstruct import Reconstructor |
30 | from lark.tree import Tree | |
29 | 31 | |
30 | 32 | |
31 | 33 | parser = Lark(''' |
37 | 39 | | "true" -> true |
38 | 40 | | "false" -> false |
39 | 41 | | "null" -> null |
40 | array : "[" [value ("," value)*] "]" | |
41 | object : "{" [pair ("," pair)*] "}" | |
42 | array : "[" [value ("," value)*] TRAILING_COMMA? "]" | |
43 | object : "{" [pair ("," pair)*] TRAILING_COMMA? "}" | |
42 | 44 | pair : string ":" value |
43 | 45 | string : ESCAPED_STRING |
44 | 46 | |
45 | COMMENT: /(#|\/\/)[^\\n]*/ | |
47 | COMMENT: "/*" /(.|\\n)+?/ "*/" | |
48 | | /(#|\\/\\/)[^\\n]*/ | |
49 | TRAILING_COMMA: "," | |
46 | 50 | |
47 | 51 | %import common.ESCAPED_STRING |
48 | 52 | %import common.SIGNED_NUMBER |
49 | 53 | %import common.WS |
50 | 54 | %ignore WS |
51 | 55 | %ignore COMMENT |
52 | ''', maybe_placeholders=False) | |
56 | ''', maybe_placeholders=False, parser='lalr') | |
53 | 57 | |
54 | 58 | serializer = Reconstructor(parser) |
55 | 59 | |
150 | 154 | library = 'json' |
151 | 155 | |
152 | 156 | |
157 | def _remove_trailing_commas(tree): | |
158 | if isinstance(tree, Tree): | |
159 | tree.children = [ | |
160 | _remove_trailing_commas(ch) for ch in tree.children | |
161 | if not (isinstance(ch, Token) and ch.type == 'TRAILING_COMMA') | |
162 | ] | |
163 | return tree | |
164 | ||
165 | ||
153 | 166 | def loads(text, *args, **kwargs): |
154 | 167 | ''' Deserialize `text` (a `str` or `unicode` instance containing a JSON |
155 | 168 | document with Python or JavaScript like comments) to a Python object. |
164 | 177 | text = text.decode(detect_encoding(text), 'surrogatepass') |
165 | 178 | |
166 | 179 | try: |
167 | parsed = parser.parse(text) | |
180 | parsed = _remove_trailing_commas(parser.parse(text)) | |
168 | 181 | final_text = serializer.reconstruct(parsed) |
169 | 182 | except lark.exceptions.UnexpectedCharacters: |
170 | 183 | raise ValueError('Unable to parse text', text) |
19 | 19 | 'string_with_inline_comment', |
20 | 20 | 'inline_has_special_characters', |
21 | 21 | 'array_with_hash', |
22 | 'inline_last_quote') | |
22 | 'inline_last_quote', | |
23 | 'trailing_comma') | |
23 | 24 | |
24 | 25 | for file_ in self.files: |
25 | 26 | fpath = os.path.join(self.path, file_) |
0 | Metadata-Version: 1.1 | |
0 | Metadata-Version: 2.1 | |
1 | 1 | Name: commentjson |
2 | Version: 0.8.3 | |
2 | Version: 0.9.0 | |
3 | 3 | Summary: Add Python and JavaScript style comments in your JSON files. |
4 | 4 | Home-page: https://github.com/vaidik/commentjson |
5 | 5 | Author: Vaidik Kapoor |
6 | 6 | Author-email: kapoor.vaidik@gmail.com |
7 | 7 | License: UNKNOWN |
8 | Description: =========== | |
9 | commentjson | |
10 | =========== | |
11 | ||
12 | `commentjson` (Comment JSON) is a Python package that helps you create JSON | |
13 | files with Python and JavaScript style inline comments. Its API is very similar | |
14 | to the Python standard library's `json`_ module. | |
15 | ||
16 | .. _`json`: http://docs.python.org/2/library/json.html | |
17 | ||
18 | .. image:: https://travis-ci.org/vaidik/commentjson.png | |
19 | ||
20 | Installation | |
21 | ============ | |
22 | ||
23 | pip install commentjson | |
24 | ||
25 | Basic Usage | |
26 | =========== | |
27 | ||
28 | .. code-block:: python | |
29 | ||
30 | >>> import commentjson | |
31 | >>> | |
32 | >>> json_string = """{ | |
33 | ... "name": "Vaidik Kapoor", # Person's name | |
34 | ... "location": "Delhi, India", // Person's location | |
35 | ... | |
36 | ... # Section contains info about | |
37 | ... // person's appearance | |
38 | ... "appearance": { | |
39 | ... "hair_color": "black", | |
40 | ... "eyes_color": "black", | |
41 | ... "height": "6" | |
42 | ... } | |
43 | ... }""" | |
44 | >>> | |
45 | >>> json_loaded = commentjson.loads(json_string) | |
46 | >>> print json_loaded | |
47 | {u'appearance': {u'eyes_color': u'black', u'hair_color': u'black', u'height': u'6'}, u'name': u'Vaidik Kapoor', u'location': u'Delhi, India'} | |
48 | ||
49 | Documentation | |
50 | ============= | |
51 | ||
52 | Complete documentation can be found `here`_. | |
53 | ||
54 | .. _`here`: http://commentjson.readthedocs.org/en/latest/ | |
55 | ||
56 | Tests | |
57 | ===== | |
58 | ||
59 | python setup.py test | |
60 | ||
61 | License | |
62 | ======= | |
63 | ||
64 | See `license`_. | |
65 | ||
66 | .. _`license`: https://github.com/vaidik/commentjson/blob/master/LICENSE.rst | |
67 | ||
68 | ||
69 | ||
70 | 8 | Platform: UNKNOWN |
71 | 9 | Classifier: Programming Language :: Python |
10 | License-File: LICENSE.rst | |
11 | ||
12 | =========== | |
13 | commentjson | |
14 | =========== | |
15 | ||
16 | `commentjson` (Comment JSON) is a Python package that helps you create JSON | |
17 | files with Python and JavaScript style inline comments. Its API is very similar | |
18 | to the Python standard library's `json`_ module. | |
19 | ||
20 | .. _`json`: http://docs.python.org/2/library/json.html | |
21 | ||
22 | .. image:: https://travis-ci.org/vaidik/commentjson.png | |
23 | ||
24 | Installation | |
25 | ============ | |
26 | ||
27 | pip install commentjson | |
28 | ||
29 | Basic Usage | |
30 | =========== | |
31 | ||
32 | .. code-block:: python | |
33 | ||
34 | >>> import commentjson | |
35 | >>> | |
36 | >>> json_string = """{ | |
37 | ... "name": "Vaidik Kapoor", # Person's name | |
38 | ... "location": "Delhi, India", // Person's location | |
39 | ... | |
40 | ... # Section contains info about | |
41 | ... // person's appearance | |
42 | ... "appearance": { | |
43 | ... "hair_color": "black", | |
44 | ... "eyes_color": "black", | |
45 | ... "height": "6" | |
46 | ... } | |
47 | ... }""" | |
48 | >>> | |
49 | >>> json_loaded = commentjson.loads(json_string) | |
50 | >>> print json_loaded | |
51 | {u'appearance': {u'eyes_color': u'black', u'hair_color': u'black', u'height': u'6'}, u'name': u'Vaidik Kapoor', u'location': u'Delhi, India'} | |
52 | ||
53 | Documentation | |
54 | ============= | |
55 | ||
56 | Complete documentation can be found `here`_. | |
57 | ||
58 | .. _`here`: http://commentjson.readthedocs.org/en/latest/ | |
59 | ||
60 | Tests | |
61 | ===== | |
62 | ||
63 | python setup.py test | |
64 | ||
65 | License | |
66 | ======= | |
67 | ||
68 | See `license`_. | |
69 | ||
70 | .. _`license`: https://github.com/vaidik/commentjson/blob/master/LICENSE.rst | |
71 | ||
72 | ||
73 | ||
74 |