-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #712 from EvanBldy/master
[qa] use orjson instead of json to improve performances
- Loading branch information
Showing
22 changed files
with
76 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import json | ||
import orjson as json | ||
|
||
from tests.base import ApiDBTestCase | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import datetime | ||
import unittest | ||
import json | ||
import orjson as json | ||
import os | ||
import ntpath | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import os | ||
import json | ||
import orjson as json | ||
|
||
from tests.base import ApiDBTestCase | ||
from zou.app import db | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import json | ||
import orjson as json | ||
|
||
from tests.base import ApiDBTestCase | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import base64 | ||
|
||
import json | ||
import orjson as json | ||
import os | ||
import zlib | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# coding: utf-8 | ||
|
||
import os | ||
import json | ||
import orjson as json | ||
import datetime | ||
import tempfile | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from ua_parser import user_agent_parser | ||
from werkzeug.user_agent import UserAgent | ||
from werkzeug.utils import cached_property | ||
from flask.json.provider import JSONProvider | ||
from flask import make_response | ||
import orjson | ||
|
||
orjson_options = orjson.OPT_NON_STR_KEYS | ||
|
||
|
||
def output_json(data, code, headers=None): | ||
"""Makes a Flask response with a JSON encoded body""" | ||
dumped = orjson.dumps(data, option=orjson_options) | ||
|
||
resp = make_response(dumped, code) | ||
resp.headers.extend(headers or {}) | ||
return resp | ||
|
||
|
||
class ORJSONProvider(JSONProvider): | ||
def __init__(self, *args, **kwargs): | ||
self.options = kwargs | ||
super().__init__(*args, **kwargs) | ||
|
||
def loads(self, s, **kwargs): | ||
return orjson.loads(s) | ||
|
||
def dumps(self, obj, **kwargs): | ||
return orjson.dumps(obj, option=orjson_options).decode("utf-8") | ||
|
||
|
||
class ParsedUserAgent(UserAgent): | ||
@cached_property | ||
def _details(self): | ||
return user_agent_parser.Parse(self.string) | ||
|
||
@property | ||
def platform(self): | ||
return self._details["os"]["family"] | ||
|
||
@property | ||
def browser(self): | ||
return self._details["user_agent"]["family"] | ||
|
||
@property | ||
def version(self): | ||
return ".".join( | ||
part | ||
for key in ("major", "minor", "patch") | ||
if (part := self._details["user_agent"][key]) is not None | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import nomad | ||
import base64 | ||
import json | ||
import orjson as json | ||
import textwrap | ||
import time | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import os | ||
import json | ||
import orjson as json | ||
import sys | ||
|
||
from pathlib import Path | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#!/usr/bin/env python | ||
import base64 | ||
import json | ||
import orjson as json | ||
import logging | ||
import os | ||
import sys | ||
|