mirror of
https://github.com/nlohmann/json.git
synced 2024-11-23 22:19:02 +08:00
Miscellaneous small fixes (#3643)
* serve_header: suppress lgtm warning * serve_header: fix exit code * serve_header: replace deprecated ssl.wrap_socket() * Add checks to unit test readme * Add lgtm configuration file
This commit is contained in:
parent
f1e34070d2
commit
8eee62d388
4
.lgtm.yml
Normal file
4
.lgtm.yml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
path_classifiers:
|
||||||
|
thirdparty:
|
||||||
|
- /tools/amalgamate
|
||||||
|
- /tools/cpplint
|
@ -106,12 +106,10 @@ TEST_CASE("README" * doctest::skip())
|
|||||||
json j = "{ \"happy\": true, \"pi\": 3.141 }"_json; // NOLINT(modernize-raw-string-literal)
|
json j = "{ \"happy\": true, \"pi\": 3.141 }"_json; // NOLINT(modernize-raw-string-literal)
|
||||||
|
|
||||||
// or even nicer with a raw string literal
|
// or even nicer with a raw string literal
|
||||||
auto j2 = R"(
|
auto j2 = R"({
|
||||||
{
|
"happy": true,
|
||||||
"happy": true,
|
"pi": 3.141
|
||||||
"pi": 3.141
|
})"_json;
|
||||||
}
|
|
||||||
)"_json;
|
|
||||||
|
|
||||||
// or explicitly
|
// or explicitly
|
||||||
auto j3 = json::parse(R"({"happy": true, "pi": 3.141})");
|
auto j3 = json::parse(R"({"happy": true, "pi": 3.141})");
|
||||||
@ -160,10 +158,10 @@ TEST_CASE("README" * doctest::skip())
|
|||||||
CHECK(foo == true);
|
CHECK(foo == true);
|
||||||
|
|
||||||
// other stuff
|
// other stuff
|
||||||
j.size(); // 3 entries
|
CHECK(j.size() == 3); // 3 entries
|
||||||
j.empty(); // false
|
CHECK_FALSE(j.empty()); // false
|
||||||
j.type(); // json::value_t::array
|
CHECK(j.type() == json::value_t::array); // json::value_t::array
|
||||||
j.clear(); // the array is empty again
|
j.clear(); // the array is empty again
|
||||||
|
|
||||||
// create an object
|
// create an object
|
||||||
json o;
|
json o;
|
||||||
@ -172,6 +170,7 @@ TEST_CASE("README" * doctest::skip())
|
|||||||
o["baz"] = 3.141;
|
o["baz"] = 3.141;
|
||||||
|
|
||||||
// find an entry
|
// find an entry
|
||||||
|
CHECK(o.find("foo") != o.end());
|
||||||
if (o.find("foo") != o.end())
|
if (o.find("foo") != o.end())
|
||||||
{
|
{
|
||||||
// there is an entry with key "foo"
|
// there is an entry with key "foo"
|
||||||
@ -266,9 +265,9 @@ TEST_CASE("README" * doctest::skip())
|
|||||||
{
|
{
|
||||||
// a JSON value
|
// a JSON value
|
||||||
json j_original = R"({
|
json j_original = R"({
|
||||||
"baz": ["one", "two", "three"],
|
"baz": ["one", "two", "three"],
|
||||||
"foo": "bar"
|
"foo": "bar"
|
||||||
})"_json;
|
})"_json;
|
||||||
|
|
||||||
// access members with a JSON pointer (RFC 6901)
|
// access members with a JSON pointer (RFC 6901)
|
||||||
j_original["/baz/1"_json_pointer];
|
j_original["/baz/1"_json_pointer];
|
||||||
@ -276,10 +275,10 @@ TEST_CASE("README" * doctest::skip())
|
|||||||
|
|
||||||
// a JSON patch (RFC 6902)
|
// a JSON patch (RFC 6902)
|
||||||
json j_patch = R"([
|
json j_patch = R"([
|
||||||
{ "op": "replace", "path": "/baz", "value": "boo" },
|
{ "op": "replace", "path": "/baz", "value": "boo" },
|
||||||
{ "op": "add", "path": "/hello", "value": ["world"] },
|
{ "op": "add", "path": "/hello", "value": ["world"] },
|
||||||
{ "op": "remove", "path": "/foo"}
|
{ "op": "remove", "path": "/foo"}
|
||||||
])"_json;
|
])"_json;
|
||||||
|
|
||||||
// apply the patch
|
// apply the patch
|
||||||
json j_result = j_original.patch(j_patch);
|
json j_result = j_original.patch(j_patch);
|
||||||
|
@ -240,7 +240,7 @@ class WorkTrees(FileSystemEventHandler):
|
|||||||
self.observer.stop()
|
self.observer.stop()
|
||||||
self.observer.join()
|
self.observer.join()
|
||||||
|
|
||||||
class HeaderRequestHandler(SimpleHTTPRequestHandler):
|
class HeaderRequestHandler(SimpleHTTPRequestHandler): # lgtm[py/missing-call-to-init]
|
||||||
def __init__(self, request, client_address, server):
|
def __init__(self, request, client_address, server):
|
||||||
"""."""
|
"""."""
|
||||||
self.worktrees = server.worktrees
|
self.worktrees = server.worktrees
|
||||||
@ -388,11 +388,11 @@ if __name__ == '__main__':
|
|||||||
if https.get('enabled', True):
|
if https.get('enabled', True):
|
||||||
cert_file = https.get('cert_file', 'localhost.pem')
|
cert_file = https.get('cert_file', 'localhost.pem')
|
||||||
key_file = https.get('key_file', 'localhost-key.pem')
|
key_file = https.get('key_file', 'localhost-key.pem')
|
||||||
ssl.minimum_version = ssl.TLSVersion.TLSv1_3
|
ssl_ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
|
||||||
ssl.maximum_version = ssl.TLSVersion.MAXIMUM_SUPPORTED
|
ssl_ctx.minimum_version = ssl.TLSVersion.TLSv1_2
|
||||||
httpd.socket = ssl.wrap_socket(httpd.socket,
|
ssl_ctx.maximum_version = ssl.TLSVersion.MAXIMUM_SUPPORTED
|
||||||
certfile=cert_file, keyfile=key_file,
|
ssl_ctx.load_cert_chain(cert_file, key_file)
|
||||||
server_side=True, ssl_version=ssl.PROTOCOL_TLS)
|
httpd.socket = ssl_ctx.wrap_socket(httpd.socket, server_side=True)
|
||||||
scheme = 'HTTPS'
|
scheme = 'HTTPS'
|
||||||
host, port = httpd.socket.getsockname()[:2]
|
host, port = httpd.socket.getsockname()[:2]
|
||||||
log.info(f'serving {scheme} on {host} port {port}')
|
log.info(f'serving {scheme} on {host} port {port}')
|
||||||
@ -402,8 +402,8 @@ if __name__ == '__main__':
|
|||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
log.info('exiting')
|
log.info('exiting')
|
||||||
except Exception:
|
except Exception:
|
||||||
log.exception('an error occurred:')
|
|
||||||
ec = 1
|
ec = 1
|
||||||
|
log.exception('an error occurred:')
|
||||||
finally:
|
finally:
|
||||||
if worktrees is not None:
|
if worktrees is not None:
|
||||||
worktrees.stop()
|
worktrees.stop()
|
||||||
|
Loading…
Reference in New Issue
Block a user