k3utfjson 0.1.0__tar.gz → 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- k3utfjson-0.1.2/LICENSE +21 -0
- k3utfjson-0.1.2/PKG-INFO +85 -0
- k3utfjson-0.1.2/README.md +50 -0
- {k3utfjson-0.1.0/k3utfjson → k3utfjson-0.1.2}/__init__.py +5 -4
- k3utfjson-0.1.2/k3utfjson.egg-info/PKG-INFO +85 -0
- k3utfjson-0.1.2/k3utfjson.egg-info/SOURCES.txt +16 -0
- k3utfjson-0.1.2/k3utfjson.egg-info/requires.txt +15 -0
- k3utfjson-0.1.2/pyproject.toml +57 -0
- k3utfjson-0.1.2/test/test_doctest.py +8 -0
- k3utfjson-0.1.2/test/test_k3utfjson.py +123 -0
- {k3utfjson-0.1.0/k3utfjson → k3utfjson-0.1.2}/utfjson.py +2 -5
- k3utfjson-0.1.0/PKG-INFO +0 -66
- k3utfjson-0.1.0/k3utfjson/setup.py +0 -23
- k3utfjson-0.1.0/k3utfjson.egg-info/PKG-INFO +0 -66
- k3utfjson-0.1.0/k3utfjson.egg-info/SOURCES.txt +0 -10
- k3utfjson-0.1.0/k3utfjson.egg-info/requires.txt +0 -1
- k3utfjson-0.1.0/setup.py +0 -23
- {k3utfjson-0.1.0 → k3utfjson-0.1.2}/k3utfjson.egg-info/dependency_links.txt +0 -0
- {k3utfjson-0.1.0 → k3utfjson-0.1.2}/k3utfjson.egg-info/top_level.txt +0 -0
- {k3utfjson-0.1.0 → k3utfjson-0.1.2}/setup.cfg +0 -0
- {k3utfjson-0.1.0/k3utfjson → k3utfjson-0.1.2}/synopsis.py +0 -0
k3utfjson-0.1.2/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 张炎泼
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
k3utfjson-0.1.2/PKG-INFO
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: k3utfjson
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: JSON dump and load with enforced UTF-8 encoding
|
|
5
|
+
Author-email: Zhang Yanpo <drdr.xp@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/pykit3/k3utfjson
|
|
8
|
+
Project-URL: Documentation, https://k3utfjson.readthedocs.io
|
|
9
|
+
Keywords: json,utf-8,encoding,serialization
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Requires-Python: >=3.9
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Provides-Extra: dev
|
|
23
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
24
|
+
Requires-Dist: ruff; extra == "dev"
|
|
25
|
+
Requires-Dist: coverage; extra == "dev"
|
|
26
|
+
Provides-Extra: publish
|
|
27
|
+
Requires-Dist: build; extra == "publish"
|
|
28
|
+
Requires-Dist: twine; extra == "publish"
|
|
29
|
+
Requires-Dist: pk3; extra == "publish"
|
|
30
|
+
Provides-Extra: docs
|
|
31
|
+
Requires-Dist: mkdocs>=1.5; extra == "docs"
|
|
32
|
+
Requires-Dist: mkdocs-material>=9.0; extra == "docs"
|
|
33
|
+
Requires-Dist: mkdocstrings[python]>=0.24; extra == "docs"
|
|
34
|
+
Dynamic: license-file
|
|
35
|
+
|
|
36
|
+
# k3utfjson
|
|
37
|
+
|
|
38
|
+
[](https://github.com/pykit3/k3utfjson/actions/workflows/python-package.yml)
|
|
39
|
+
[](https://travis-ci.com/pykit3/k3utfjson)
|
|
40
|
+
[](https://k3utfjson.readthedocs.io/en/stable/?badge=stable)
|
|
41
|
+
[](https://pypi.org/project/k3utfjson)
|
|
42
|
+
|
|
43
|
+
force `json.dump` and `json.load` in `utf-8` encoding.
|
|
44
|
+
|
|
45
|
+
k3utfjson is a component of [pykit3] project: a python3 toolkit set.
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
# Name
|
|
49
|
+
|
|
50
|
+
utfjson: force `json.dump` and `json.load` in `utf-8` encoding.
|
|
51
|
+
|
|
52
|
+
# Status
|
|
53
|
+
|
|
54
|
+
This library is considered production ready.
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
# Install
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
pip install k3utfjson
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
# Synopsis
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
|
|
67
|
+
import k3utfjson
|
|
68
|
+
|
|
69
|
+
k3utfjson.load('"hello"')
|
|
70
|
+
k3utfjson.dump({})
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
# Author
|
|
75
|
+
|
|
76
|
+
Zhang Yanpo (张炎泼) <drdr.xp@gmail.com>
|
|
77
|
+
|
|
78
|
+
# Copyright and License
|
|
79
|
+
|
|
80
|
+
The MIT License (MIT)
|
|
81
|
+
|
|
82
|
+
Copyright (c) 2015 Zhang Yanpo (张炎泼) <drdr.xp@gmail.com>
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
[pykit3]: https://github.com/pykit3
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# k3utfjson
|
|
2
|
+
|
|
3
|
+
[](https://github.com/pykit3/k3utfjson/actions/workflows/python-package.yml)
|
|
4
|
+
[](https://travis-ci.com/pykit3/k3utfjson)
|
|
5
|
+
[](https://k3utfjson.readthedocs.io/en/stable/?badge=stable)
|
|
6
|
+
[](https://pypi.org/project/k3utfjson)
|
|
7
|
+
|
|
8
|
+
force `json.dump` and `json.load` in `utf-8` encoding.
|
|
9
|
+
|
|
10
|
+
k3utfjson is a component of [pykit3] project: a python3 toolkit set.
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# Name
|
|
14
|
+
|
|
15
|
+
utfjson: force `json.dump` and `json.load` in `utf-8` encoding.
|
|
16
|
+
|
|
17
|
+
# Status
|
|
18
|
+
|
|
19
|
+
This library is considered production ready.
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# Install
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
pip install k3utfjson
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
# Synopsis
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
|
|
32
|
+
import k3utfjson
|
|
33
|
+
|
|
34
|
+
k3utfjson.load('"hello"')
|
|
35
|
+
k3utfjson.dump({})
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
# Author
|
|
40
|
+
|
|
41
|
+
Zhang Yanpo (张炎泼) <drdr.xp@gmail.com>
|
|
42
|
+
|
|
43
|
+
# Copyright and License
|
|
44
|
+
|
|
45
|
+
The MIT License (MIT)
|
|
46
|
+
|
|
47
|
+
Copyright (c) 2015 Zhang Yanpo (张炎泼) <drdr.xp@gmail.com>
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
[pykit3]: https://github.com/pykit3
|
|
@@ -12,8 +12,9 @@ This library is considered production ready.
|
|
|
12
12
|
# from .proc import CalledProcessError
|
|
13
13
|
# from .proc import ProcError
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
from importlib.metadata import version
|
|
16
|
+
|
|
17
|
+
__version__ = version("k3utfjson")
|
|
17
18
|
|
|
18
19
|
from .utfjson import (
|
|
19
20
|
dump,
|
|
@@ -21,6 +22,6 @@ from .utfjson import (
|
|
|
21
22
|
)
|
|
22
23
|
|
|
23
24
|
__all__ = [
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
"dump",
|
|
26
|
+
"load",
|
|
26
27
|
]
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: k3utfjson
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: JSON dump and load with enforced UTF-8 encoding
|
|
5
|
+
Author-email: Zhang Yanpo <drdr.xp@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/pykit3/k3utfjson
|
|
8
|
+
Project-URL: Documentation, https://k3utfjson.readthedocs.io
|
|
9
|
+
Keywords: json,utf-8,encoding,serialization
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Requires-Python: >=3.9
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Provides-Extra: dev
|
|
23
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
24
|
+
Requires-Dist: ruff; extra == "dev"
|
|
25
|
+
Requires-Dist: coverage; extra == "dev"
|
|
26
|
+
Provides-Extra: publish
|
|
27
|
+
Requires-Dist: build; extra == "publish"
|
|
28
|
+
Requires-Dist: twine; extra == "publish"
|
|
29
|
+
Requires-Dist: pk3; extra == "publish"
|
|
30
|
+
Provides-Extra: docs
|
|
31
|
+
Requires-Dist: mkdocs>=1.5; extra == "docs"
|
|
32
|
+
Requires-Dist: mkdocs-material>=9.0; extra == "docs"
|
|
33
|
+
Requires-Dist: mkdocstrings[python]>=0.24; extra == "docs"
|
|
34
|
+
Dynamic: license-file
|
|
35
|
+
|
|
36
|
+
# k3utfjson
|
|
37
|
+
|
|
38
|
+
[](https://github.com/pykit3/k3utfjson/actions/workflows/python-package.yml)
|
|
39
|
+
[](https://travis-ci.com/pykit3/k3utfjson)
|
|
40
|
+
[](https://k3utfjson.readthedocs.io/en/stable/?badge=stable)
|
|
41
|
+
[](https://pypi.org/project/k3utfjson)
|
|
42
|
+
|
|
43
|
+
force `json.dump` and `json.load` in `utf-8` encoding.
|
|
44
|
+
|
|
45
|
+
k3utfjson is a component of [pykit3] project: a python3 toolkit set.
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
# Name
|
|
49
|
+
|
|
50
|
+
utfjson: force `json.dump` and `json.load` in `utf-8` encoding.
|
|
51
|
+
|
|
52
|
+
# Status
|
|
53
|
+
|
|
54
|
+
This library is considered production ready.
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
# Install
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
pip install k3utfjson
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
# Synopsis
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
|
|
67
|
+
import k3utfjson
|
|
68
|
+
|
|
69
|
+
k3utfjson.load('"hello"')
|
|
70
|
+
k3utfjson.dump({})
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
# Author
|
|
75
|
+
|
|
76
|
+
Zhang Yanpo (张炎泼) <drdr.xp@gmail.com>
|
|
77
|
+
|
|
78
|
+
# Copyright and License
|
|
79
|
+
|
|
80
|
+
The MIT License (MIT)
|
|
81
|
+
|
|
82
|
+
Copyright (c) 2015 Zhang Yanpo (张炎泼) <drdr.xp@gmail.com>
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
[pykit3]: https://github.com/pykit3
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
__init__.py
|
|
4
|
+
pyproject.toml
|
|
5
|
+
synopsis.py
|
|
6
|
+
utfjson.py
|
|
7
|
+
./__init__.py
|
|
8
|
+
./synopsis.py
|
|
9
|
+
./utfjson.py
|
|
10
|
+
k3utfjson.egg-info/PKG-INFO
|
|
11
|
+
k3utfjson.egg-info/SOURCES.txt
|
|
12
|
+
k3utfjson.egg-info/dependency_links.txt
|
|
13
|
+
k3utfjson.egg-info/requires.txt
|
|
14
|
+
k3utfjson.egg-info/top_level.txt
|
|
15
|
+
test/test_doctest.py
|
|
16
|
+
test/test_k3utfjson.py
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "k3utfjson"
|
|
7
|
+
version = "0.1.2"
|
|
8
|
+
description = "JSON dump and load with enforced UTF-8 encoding"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = {text = "MIT"}
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "Zhang Yanpo", email = "drdr.xp@gmail.com" }
|
|
14
|
+
]
|
|
15
|
+
keywords = ["json", "utf-8", "encoding", "serialization"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 4 - Beta",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Topic :: Software Development :: Libraries",
|
|
20
|
+
"License :: OSI Approved :: MIT License",
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"Programming Language :: Python :: 3.9",
|
|
23
|
+
"Programming Language :: Python :: 3.10",
|
|
24
|
+
"Programming Language :: Python :: 3.11",
|
|
25
|
+
"Programming Language :: Python :: 3.12",
|
|
26
|
+
]
|
|
27
|
+
dependencies = []
|
|
28
|
+
|
|
29
|
+
[project.urls]
|
|
30
|
+
Homepage = "https://github.com/pykit3/k3utfjson"
|
|
31
|
+
Documentation = "https://k3utfjson.readthedocs.io"
|
|
32
|
+
|
|
33
|
+
[project.optional-dependencies]
|
|
34
|
+
dev = [
|
|
35
|
+
"pytest>=7.0",
|
|
36
|
+
"ruff",
|
|
37
|
+
"coverage",
|
|
38
|
+
]
|
|
39
|
+
publish = [
|
|
40
|
+
"build",
|
|
41
|
+
"twine",
|
|
42
|
+
"pk3",
|
|
43
|
+
]
|
|
44
|
+
docs = [
|
|
45
|
+
"mkdocs>=1.5",
|
|
46
|
+
"mkdocs-material>=9.0",
|
|
47
|
+
"mkdocstrings[python]>=0.24",
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
[tool.setuptools]
|
|
51
|
+
packages = ["k3utfjson"]
|
|
52
|
+
|
|
53
|
+
[tool.setuptools.package-dir]
|
|
54
|
+
k3utfjson = "."
|
|
55
|
+
|
|
56
|
+
[tool.ruff]
|
|
57
|
+
line-length = 120
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import unittest
|
|
3
|
+
|
|
4
|
+
import k3ut
|
|
5
|
+
import k3utfjson
|
|
6
|
+
import json
|
|
7
|
+
|
|
8
|
+
dd = k3ut.dd
|
|
9
|
+
|
|
10
|
+
this_base = os.path.dirname(__file__)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class TestUTFJson(unittest.TestCase):
|
|
14
|
+
def test_load(self):
|
|
15
|
+
self.assertEqual(None, k3utfjson.load(None))
|
|
16
|
+
self.assertEqual({}, k3utfjson.load("{}"))
|
|
17
|
+
|
|
18
|
+
# load unicode, result in utf-8
|
|
19
|
+
|
|
20
|
+
self.assertEqual("我", k3utfjson.load('"\\u6211"'))
|
|
21
|
+
self.assertEqual(str, type(k3utfjson.load('"\\u6211"')))
|
|
22
|
+
|
|
23
|
+
# unicode and string in a dictionary.
|
|
24
|
+
|
|
25
|
+
obj = '{"a": "\u6211", "b": "1"}'
|
|
26
|
+
rst = k3utfjson.load(obj)
|
|
27
|
+
|
|
28
|
+
self.assertEqual({"a": b"\xe6\x88\x91".decode("utf-8"), "b": "1"}, rst)
|
|
29
|
+
self.assertEqual(str, type(rst["a"]))
|
|
30
|
+
self.assertEqual(str, type(rst["b"]))
|
|
31
|
+
|
|
32
|
+
# load utf-8, result in str
|
|
33
|
+
|
|
34
|
+
rst = k3utfjson.load(b'"\xe6\x88\x91"')
|
|
35
|
+
self.assertEqual("我", rst)
|
|
36
|
+
self.assertEqual(str, type(rst))
|
|
37
|
+
|
|
38
|
+
# load gbk, result in str, in gbk encoding
|
|
39
|
+
|
|
40
|
+
gbk = b'"\xb6\xd4\xd5\xbd\xc6\xbd\xcc\xa8\xb9\xd9\xb7\xbd\xd7\xee\xd0\xc2\xb0\xe6"'
|
|
41
|
+
self.assertEqual("对战平台官方最新版", k3utfjson.load(gbk, encoding="gbk"))
|
|
42
|
+
self.assertEqual(str, type(k3utfjson.load(gbk, encoding="gbk")))
|
|
43
|
+
|
|
44
|
+
# load any
|
|
45
|
+
|
|
46
|
+
s = '"\xbb"'
|
|
47
|
+
rst = k3utfjson.load(s)
|
|
48
|
+
self.assertEqual("\xbb", rst)
|
|
49
|
+
self.assertEqual(str, type(rst))
|
|
50
|
+
|
|
51
|
+
def test_load_backslash_x_encoded(self):
|
|
52
|
+
s = '"\x61"'
|
|
53
|
+
self.assertEqual("a", k3utfjson.load(s))
|
|
54
|
+
|
|
55
|
+
s = '"\x61"'
|
|
56
|
+
self.assertEqual("a", k3utfjson.load(s))
|
|
57
|
+
|
|
58
|
+
s = b'"\xe6\x88\x91"'
|
|
59
|
+
self.assertEqual("我", k3utfjson.load(s))
|
|
60
|
+
|
|
61
|
+
self.assertRaises(json.JSONDecodeError, k3utfjson.load, '"\\"')
|
|
62
|
+
self.assertRaises(json.JSONDecodeError, k3utfjson.load, '"\\x"')
|
|
63
|
+
self.assertRaises(json.JSONDecodeError, k3utfjson.load, '"\\x6"')
|
|
64
|
+
|
|
65
|
+
def test_load_decode(self):
|
|
66
|
+
self.assertEqual("我", k3utfjson.load('"我"'))
|
|
67
|
+
self.assertEqual("我", k3utfjson.load('"我"', encoding="utf-8"))
|
|
68
|
+
self.assertEqual(str, type(k3utfjson.load('"我"', encoding="utf-8")))
|
|
69
|
+
|
|
70
|
+
self.assertEqual({"a": "我"}, k3utfjson.load('{"a": "\\u6211"}'))
|
|
71
|
+
self.assertEqual({"a": "我"}, k3utfjson.load('{"a": "我"}', encoding="utf-8"))
|
|
72
|
+
self.assertEqual({"a": "我"}, k3utfjson.load('{"a": "我"}'))
|
|
73
|
+
self.assertEqual({"a": "我"}, k3utfjson.load('{"a": "我"}'))
|
|
74
|
+
self.assertEqual(["我"], k3utfjson.load('["我"]'))
|
|
75
|
+
|
|
76
|
+
def test_dump(self):
|
|
77
|
+
self.assertEqual("null", k3utfjson.dump(None))
|
|
78
|
+
self.assertEqual("{}", k3utfjson.dump({}))
|
|
79
|
+
|
|
80
|
+
self.assertRaises(TypeError, k3utfjson.dump, b"\xe6\x88\x91", encoding=None)
|
|
81
|
+
self.assertRaises(TypeError, k3utfjson.dump, {b"\xe6\x88\x91": 1}, encoding=None)
|
|
82
|
+
self.assertRaises(TypeError, k3utfjson.dump, {1: b"\xe6\x88\x91"}, encoding=None)
|
|
83
|
+
self.assertRaises(TypeError, k3utfjson.dump, [b"\xe6\x88\x91"], encoding=None)
|
|
84
|
+
self.assertRaises(TypeError, k3utfjson.dump, [(b"\xe6\x88\x91",)], encoding=None)
|
|
85
|
+
|
|
86
|
+
self.assertEqual('"\\u6211"', k3utfjson.dump("我", encoding=None))
|
|
87
|
+
self.assertEqual('"' + b"\xb6\xd4".decode("gbk") + '"', k3utfjson.dump("对", encoding="gbk"))
|
|
88
|
+
self.assertEqual('"' + b"\xe6\x88\x91".decode("utf-8") + '"', k3utfjson.dump("我", encoding="utf-8"))
|
|
89
|
+
|
|
90
|
+
self.assertEqual('"' + b"\xe6\x88\x91".decode("utf-8") + '"', k3utfjson.dump("我"))
|
|
91
|
+
self.assertEqual('"' + b"\xe6\x88\x91".decode("utf-8") + '"', k3utfjson.dump("我"))
|
|
92
|
+
|
|
93
|
+
# by default unicode are encoded
|
|
94
|
+
|
|
95
|
+
self.assertEqual(
|
|
96
|
+
'{"' + b"\xe6\x88\x91".decode("utf-8") + '": "' + b"\xe6\x88\x91".decode("utf-8") + '"}',
|
|
97
|
+
k3utfjson.dump({"我": "我"}),
|
|
98
|
+
)
|
|
99
|
+
self.assertEqual(
|
|
100
|
+
'{"' + b"\xe6\x88\x91".decode("utf-8") + '": "' + b"\xe6\x88\x91".decode("utf-8") + '"}',
|
|
101
|
+
k3utfjson.dump({"我": "我"}),
|
|
102
|
+
)
|
|
103
|
+
self.assertEqual(
|
|
104
|
+
'{"' + b"\xe6\x88\x91".decode("utf-8") + '": "' + b"\xe6\x88\x91".decode("utf-8") + '"}',
|
|
105
|
+
k3utfjson.dump({"我": "我"}),
|
|
106
|
+
)
|
|
107
|
+
self.assertEqual(
|
|
108
|
+
'{"' + b"\xe6\x88\x91".decode("utf-8") + '": "' + b"\xe6\x88\x91".decode("utf-8") + '"}',
|
|
109
|
+
k3utfjson.dump({"我": "我"}),
|
|
110
|
+
)
|
|
111
|
+
self.assertEqual('["' + b"\xe6\x88\x91".decode("utf-8") + '"]', k3utfjson.dump(("我",)))
|
|
112
|
+
|
|
113
|
+
self.assertEqual('{"\\u6211": "\\u6211"}', k3utfjson.dump({"我": "我"}, encoding=None))
|
|
114
|
+
|
|
115
|
+
self.assertEqual('"\\""', k3utfjson.dump('"'))
|
|
116
|
+
|
|
117
|
+
# encoded chars and unicode chars in one string
|
|
118
|
+
self.assertEqual(
|
|
119
|
+
"/aaa\xe7\x89\x88\xe6\x9c\xac/jfkdsl\x01", k3utfjson.load('"\/aaa\xe7\x89\x88\xe6\x9c\xac\/jfkdsl\\u0001"')
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
self.assertEqual('{\n "我": "我"\n}', k3utfjson.dump({"我": "我"}, indent=2))
|
|
123
|
+
self.assertEqual('{\n "我": "我"\n}', k3utfjson.dump({"我": "我"}, indent=4))
|
|
@@ -30,7 +30,7 @@ import json
|
|
|
30
30
|
# str '\xe6\x88\x91' '"\\u00e6\\u0088\\u0091"' '"\xe6\x88\x91"'
|
|
31
31
|
|
|
32
32
|
|
|
33
|
-
def dump(obj, encoding=
|
|
33
|
+
def dump(obj, encoding="utf-8", indent=None):
|
|
34
34
|
# - Using non-unicode with ensure_ascii=True results in unexpected output:
|
|
35
35
|
# p3fjson.dump('我', ensure_ascii=True) --> '"\\u00e6\\u0088\\u0091"'
|
|
36
36
|
#
|
|
@@ -57,10 +57,8 @@ def dump(obj, encoding='utf-8', indent=None):
|
|
|
57
57
|
|
|
58
58
|
|
|
59
59
|
def ensure_str(o):
|
|
60
|
-
|
|
61
60
|
if isinstance(o, bytes):
|
|
62
|
-
raise TypeError(
|
|
63
|
-
' if ensure_ascii is True'.format(o=o, tp=type(o)))
|
|
61
|
+
raise TypeError("string({o} {tp}) must be str if ensure_ascii is True".format(o=o, tp=type(o)))
|
|
64
62
|
|
|
65
63
|
if isinstance(o, dict):
|
|
66
64
|
for k, v in o.items():
|
|
@@ -102,7 +100,6 @@ def load(s, encoding=None):
|
|
|
102
100
|
s = decode(s, encoding="utf-8")
|
|
103
101
|
else:
|
|
104
102
|
s = decode(s, encoding)
|
|
105
|
-
s = "\"" + s + "\""
|
|
106
103
|
rst = json.loads(s)
|
|
107
104
|
|
|
108
105
|
return rst
|
k3utfjson-0.1.0/PKG-INFO
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: k3utfjson
|
|
3
|
-
Version: 0.1.0
|
|
4
|
-
Summary: force `json.dump` and `json.load` in `utf-8` encoding.
|
|
5
|
-
Home-page: https://github.com/pykit3/k3utfjson
|
|
6
|
-
Author: Zhang Yanpo
|
|
7
|
-
Author-email: drdr.xp@gmail.com
|
|
8
|
-
License: MIT
|
|
9
|
-
Description: # k3utfjson
|
|
10
|
-
|
|
11
|
-
[](https://github.com/pykit3/k3utfjson/actions/workflows/python-package.yml)
|
|
12
|
-
[](https://travis-ci.com/pykit3/k3utfjson)
|
|
13
|
-
[](https://k3utfjson.readthedocs.io/en/stable/?badge=stable)
|
|
14
|
-
[](https://pypi.org/project/k3utfjson)
|
|
15
|
-
|
|
16
|
-
force `json.dump` and `json.load` in `utf-8` encoding.
|
|
17
|
-
|
|
18
|
-
k3utfjson is a component of [pykit3] project: a python3 toolkit set.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
# Name
|
|
22
|
-
|
|
23
|
-
utfjson: force `json.dump` and `json.load` in `utf-8` encoding.
|
|
24
|
-
|
|
25
|
-
# Status
|
|
26
|
-
|
|
27
|
-
This library is considered production ready.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
# Install
|
|
31
|
-
|
|
32
|
-
```
|
|
33
|
-
pip install k3utfjson
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
# Synopsis
|
|
37
|
-
|
|
38
|
-
```python
|
|
39
|
-
|
|
40
|
-
import k3utfjson
|
|
41
|
-
|
|
42
|
-
k3utfjson.load('"hello"')
|
|
43
|
-
k3utfjson.dump({})
|
|
44
|
-
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
# Author
|
|
48
|
-
|
|
49
|
-
Zhang Yanpo (张炎泼) <drdr.xp@gmail.com>
|
|
50
|
-
|
|
51
|
-
# Copyright and License
|
|
52
|
-
|
|
53
|
-
The MIT License (MIT)
|
|
54
|
-
|
|
55
|
-
Copyright (c) 2015 Zhang Yanpo (张炎泼) <drdr.xp@gmail.com>
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
[pykit3]: https://github.com/pykit3
|
|
59
|
-
Keywords: python,json
|
|
60
|
-
Platform: UNKNOWN
|
|
61
|
-
Classifier: Development Status :: 4 - Beta
|
|
62
|
-
Classifier: Intended Audience :: Developers
|
|
63
|
-
Classifier: Topic :: Software Development :: Libraries
|
|
64
|
-
Classifier: Programming Language :: Python :: 3
|
|
65
|
-
Requires-Python: >=3.0
|
|
66
|
-
Description-Content-Type: text/markdown
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# DO NOT EDIT!!! built with `python _building/build_setup.py`
|
|
2
|
-
import setuptools
|
|
3
|
-
setuptools.setup(
|
|
4
|
-
name="k3utfjson",
|
|
5
|
-
packages=["k3utfjson"],
|
|
6
|
-
version="0.1.0",
|
|
7
|
-
license='MIT',
|
|
8
|
-
description='force `json.dump` and `json.load` in `utf-8` encoding.',
|
|
9
|
-
long_description='# k3utfjson\n\n[](https://github.com/pykit3/k3utfjson/actions/workflows/python-package.yml)\n[](https://travis-ci.com/pykit3/k3utfjson)\n[](https://k3utfjson.readthedocs.io/en/stable/?badge=stable)\n[](https://pypi.org/project/k3utfjson)\n\nforce `json.dump` and `json.load` in `utf-8` encoding.\n\nk3utfjson is a component of [pykit3] project: a python3 toolkit set.\n\n\n# Name\n\nutfjson: force `json.dump` and `json.load` in `utf-8` encoding.\n\n# Status\n\nThis library is considered production ready.\n\n\n# Install\n\n```\npip install k3utfjson\n```\n\n# Synopsis\n\n```python\n\nimport k3utfjson\n\nk3utfjson.load(\'"hello"\')\nk3utfjson.dump({})\n\n```\n\n# Author\n\nZhang Yanpo (张炎泼) <drdr.xp@gmail.com>\n\n# Copyright and License\n\nThe MIT License (MIT)\n\nCopyright (c) 2015 Zhang Yanpo (张炎泼) <drdr.xp@gmail.com>\n\n\n[pykit3]: https://github.com/pykit3',
|
|
10
|
-
long_description_content_type="text/markdown",
|
|
11
|
-
author='Zhang Yanpo',
|
|
12
|
-
author_email='drdr.xp@gmail.com',
|
|
13
|
-
url='https://github.com/pykit3/k3utfjson',
|
|
14
|
-
keywords=['python', 'json'],
|
|
15
|
-
python_requires='>=3.0',
|
|
16
|
-
|
|
17
|
-
install_requires=['k3ut<0.2,>=0.1.15'],
|
|
18
|
-
classifiers=[
|
|
19
|
-
'Development Status :: 4 - Beta',
|
|
20
|
-
'Intended Audience :: Developers',
|
|
21
|
-
'Topic :: Software Development :: Libraries',
|
|
22
|
-
] + ['Programming Language :: Python :: 3'],
|
|
23
|
-
)
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: k3utfjson
|
|
3
|
-
Version: 0.1.0
|
|
4
|
-
Summary: force `json.dump` and `json.load` in `utf-8` encoding.
|
|
5
|
-
Home-page: https://github.com/pykit3/k3utfjson
|
|
6
|
-
Author: Zhang Yanpo
|
|
7
|
-
Author-email: drdr.xp@gmail.com
|
|
8
|
-
License: MIT
|
|
9
|
-
Description: # k3utfjson
|
|
10
|
-
|
|
11
|
-
[](https://github.com/pykit3/k3utfjson/actions/workflows/python-package.yml)
|
|
12
|
-
[](https://travis-ci.com/pykit3/k3utfjson)
|
|
13
|
-
[](https://k3utfjson.readthedocs.io/en/stable/?badge=stable)
|
|
14
|
-
[](https://pypi.org/project/k3utfjson)
|
|
15
|
-
|
|
16
|
-
force `json.dump` and `json.load` in `utf-8` encoding.
|
|
17
|
-
|
|
18
|
-
k3utfjson is a component of [pykit3] project: a python3 toolkit set.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
# Name
|
|
22
|
-
|
|
23
|
-
utfjson: force `json.dump` and `json.load` in `utf-8` encoding.
|
|
24
|
-
|
|
25
|
-
# Status
|
|
26
|
-
|
|
27
|
-
This library is considered production ready.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
# Install
|
|
31
|
-
|
|
32
|
-
```
|
|
33
|
-
pip install k3utfjson
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
# Synopsis
|
|
37
|
-
|
|
38
|
-
```python
|
|
39
|
-
|
|
40
|
-
import k3utfjson
|
|
41
|
-
|
|
42
|
-
k3utfjson.load('"hello"')
|
|
43
|
-
k3utfjson.dump({})
|
|
44
|
-
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
# Author
|
|
48
|
-
|
|
49
|
-
Zhang Yanpo (张炎泼) <drdr.xp@gmail.com>
|
|
50
|
-
|
|
51
|
-
# Copyright and License
|
|
52
|
-
|
|
53
|
-
The MIT License (MIT)
|
|
54
|
-
|
|
55
|
-
Copyright (c) 2015 Zhang Yanpo (张炎泼) <drdr.xp@gmail.com>
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
[pykit3]: https://github.com/pykit3
|
|
59
|
-
Keywords: python,json
|
|
60
|
-
Platform: UNKNOWN
|
|
61
|
-
Classifier: Development Status :: 4 - Beta
|
|
62
|
-
Classifier: Intended Audience :: Developers
|
|
63
|
-
Classifier: Topic :: Software Development :: Libraries
|
|
64
|
-
Classifier: Programming Language :: Python :: 3
|
|
65
|
-
Requires-Python: >=3.0
|
|
66
|
-
Description-Content-Type: text/markdown
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
setup.py
|
|
2
|
-
k3utfjson/__init__.py
|
|
3
|
-
k3utfjson/setup.py
|
|
4
|
-
k3utfjson/synopsis.py
|
|
5
|
-
k3utfjson/utfjson.py
|
|
6
|
-
k3utfjson.egg-info/PKG-INFO
|
|
7
|
-
k3utfjson.egg-info/SOURCES.txt
|
|
8
|
-
k3utfjson.egg-info/dependency_links.txt
|
|
9
|
-
k3utfjson.egg-info/requires.txt
|
|
10
|
-
k3utfjson.egg-info/top_level.txt
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
k3ut<0.2,>=0.1.15
|
k3utfjson-0.1.0/setup.py
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# DO NOT EDIT!!! built with `python _building/build_setup.py`
|
|
2
|
-
import setuptools
|
|
3
|
-
setuptools.setup(
|
|
4
|
-
name="k3utfjson",
|
|
5
|
-
packages=["k3utfjson"],
|
|
6
|
-
version="0.1.0",
|
|
7
|
-
license='MIT',
|
|
8
|
-
description='force `json.dump` and `json.load` in `utf-8` encoding.',
|
|
9
|
-
long_description='# k3utfjson\n\n[](https://github.com/pykit3/k3utfjson/actions/workflows/python-package.yml)\n[](https://travis-ci.com/pykit3/k3utfjson)\n[](https://k3utfjson.readthedocs.io/en/stable/?badge=stable)\n[](https://pypi.org/project/k3utfjson)\n\nforce `json.dump` and `json.load` in `utf-8` encoding.\n\nk3utfjson is a component of [pykit3] project: a python3 toolkit set.\n\n\n# Name\n\nutfjson: force `json.dump` and `json.load` in `utf-8` encoding.\n\n# Status\n\nThis library is considered production ready.\n\n\n# Install\n\n```\npip install k3utfjson\n```\n\n# Synopsis\n\n```python\n\nimport k3utfjson\n\nk3utfjson.load(\'"hello"\')\nk3utfjson.dump({})\n\n```\n\n# Author\n\nZhang Yanpo (张炎泼) <drdr.xp@gmail.com>\n\n# Copyright and License\n\nThe MIT License (MIT)\n\nCopyright (c) 2015 Zhang Yanpo (张炎泼) <drdr.xp@gmail.com>\n\n\n[pykit3]: https://github.com/pykit3',
|
|
10
|
-
long_description_content_type="text/markdown",
|
|
11
|
-
author='Zhang Yanpo',
|
|
12
|
-
author_email='drdr.xp@gmail.com',
|
|
13
|
-
url='https://github.com/pykit3/k3utfjson',
|
|
14
|
-
keywords=['python', 'json'],
|
|
15
|
-
python_requires='>=3.0',
|
|
16
|
-
|
|
17
|
-
install_requires=['k3ut<0.2,>=0.1.15'],
|
|
18
|
-
classifiers=[
|
|
19
|
-
'Development Status :: 4 - Beta',
|
|
20
|
-
'Intended Audience :: Developers',
|
|
21
|
-
'Topic :: Software Development :: Libraries',
|
|
22
|
-
] + ['Programming Language :: Python :: 3'],
|
|
23
|
-
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|