Codebase list python-commentjson / 098b927
Import upstream version 0.9.0+git20210123.1.c8678f4 Debian Janitor 2 years ago
13 changed file(s) with 179 addition(s) and 137 deletion(s). Raw diff Collapse all Expand all
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
11 Name: commentjson
2 Version: 0.8.3
2 Version: 0.9.0
33 Summary: Add Python and JavaScript style comments in your JSON files.
44 Home-page: https://github.com/vaidik/commentjson
55 Author: Vaidik Kapoor
66 Author-email: kapoor.vaidik@gmail.com
77 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
708 Platform: UNKNOWN
719 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
2525 import lark
2626
2727 from lark import Lark
28 from lark.lexer import Token
2829 from lark.reconstruct import Reconstructor
30 from lark.tree import Tree
2931
3032
3133 parser = Lark('''
3739 | "true" -> true
3840 | "false" -> false
3941 | "null" -> null
40 array : "[" [value ("," value)*] "]"
41 object : "{" [pair ("," pair)*] "}"
42 array : "[" [value ("," value)*] TRAILING_COMMA? "]"
43 object : "{" [pair ("," pair)*] TRAILING_COMMA? "}"
4244 pair : string ":" value
4345 string : ESCAPED_STRING
4446
45 COMMENT: /(#|\/\/)[^\\n]*/
47 COMMENT: "/*" /(.|\\n)+?/ "*/"
48 | /(#|\\/\\/)[^\\n]*/
49 TRAILING_COMMA: ","
4650
4751 %import common.ESCAPED_STRING
4852 %import common.SIGNED_NUMBER
4953 %import common.WS
5054 %ignore WS
5155 %ignore COMMENT
52 ''', maybe_placeholders=False)
56 ''', maybe_placeholders=False, parser='lalr')
5357
5458 serializer = Reconstructor(parser)
5559
150154 library = 'json'
151155
152156
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
153166 def loads(text, *args, **kwargs):
154167 ''' Deserialize `text` (a `str` or `unicode` instance containing a JSON
155168 document with Python or JavaScript like comments) to a Python object.
164177 text = text.decode(detect_encoding(text), 'surrogatepass')
165178
166179 try:
167 parsed = parser.parse(text)
180 parsed = _remove_trailing_commas(parser.parse(text))
168181 final_text = serializer.reconstruct(parsed)
169182 except lark.exceptions.UnexpectedCharacters:
170183 raise ValueError('Unable to parse text', text)
1919 'string_with_inline_comment',
2020 'inline_has_special_characters',
2121 'array_with_hash',
22 'inline_last_quote')
22 'inline_last_quote',
23 'trailing_comma')
2324
2425 for file_ in self.files:
2526 fpath = os.path.join(self.path, file_)
0 Metadata-Version: 1.1
0 Metadata-Version: 2.1
11 Name: commentjson
2 Version: 0.8.3
2 Version: 0.9.0
33 Summary: Add Python and JavaScript style comments in your JSON files.
44 Home-page: https://github.com/vaidik/commentjson
55 Author: Vaidik Kapoor
66 Author-email: kapoor.vaidik@gmail.com
77 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
708 Platform: UNKNOWN
719 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
0 LICENSE.rst
1 MANIFEST.in
02 README.rst
13 setup.py
24 commentjson/__init__.py
0 lark-parser>=0.7.1,<0.8.0
0 lark-parser<0.8.0,>=0.7.1
00 [egg_info]
11 tag_build =
22 tag_date = 0
3 tag_svn_revision = 0
43
55 from setuptools import setup, find_packages
66
77
8 __version__ = '.'.join(map(str, (0, 8, 3)))
8 __version__ = '0.9.0'
99
1010 install_requires = [
1111 'lark-parser>=0.7.1,<0.8.0'