当前位置: 首页>>代码示例>>Python>>正文


Python orjson.dumps方法代码示例

本文整理汇总了Python中orjson.dumps方法的典型用法代码示例。如果您正苦于以下问题:Python orjson.dumps方法的具体用法?Python orjson.dumps怎么用?Python orjson.dumps使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在orjson的用法示例。


在下文中一共展示了orjson.dumps方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: encode

# 需要导入模块: import orjson [as 别名]
# 或者: from orjson import dumps [as 别名]
def encode(self, o):
        o = self.encode_object(o)
        if self.sort_keys is True or orjson is None:
            return super(ObjectJSONEncoder, self).encode(o).encode("utf8")
        else:
            return orjson.dumps(o) 
开发者ID:johnbywater,项目名称:eventsourcing,代码行数:8,代码来源:transcoding.py

示例2: render

# 需要导入模块: import orjson [as 别名]
# 或者: from orjson import dumps [as 别名]
def render(self, content: Any) -> bytes:
        return orjson.dumps(content) 
开发者ID:tiangolo,项目名称:fastapi,代码行数:4,代码来源:test_default_response_class.py

示例3: render

# 需要导入模块: import orjson [as 别名]
# 或者: from orjson import dumps [as 别名]
def render(self, content: Any) -> bytes:
        assert orjson is not None, "orjson must be installed to use ORJSONResponse"
        return orjson.dumps(content) 
开发者ID:tiangolo,项目名称:fastapi,代码行数:5,代码来源:responses.py

示例4: dumps

# 需要导入模块: import orjson [as 别名]
# 或者: from orjson import dumps [as 别名]
def dumps(value: Any) -> str:
    return orjson.dumps(value).decode() 
开发者ID:item4,项目名称:yui,代码行数:4,代码来源:json.py

示例5: send_bad_request_response

# 需要导入模块: import orjson [as 别名]
# 或者: from orjson import dumps [as 别名]
def send_bad_request_response(
    error_dict: Dict[str, Any],
    has_content_length: bool,
    headers: Optional[Sequence[Header]] = None,
    content_type: ContentType = ContentType.APPLICATION_JSON,
) -> ASGICallableResults:
    body = orjson.dumps({'error': error_dict})
    content_length = len(body) if has_content_length else None

    return (
        RESPONSES_MAP[content_type](
            content_length, HTTPStatus.BAD_REQUEST, make_asgi_headers(headers)
        ),
        body,
    ) 
开发者ID:dutradda,项目名称:apidaora,代码行数:17,代码来源:factory.py

示例6: dumps

# 需要导入模块: import orjson [as 别名]
# 或者: from orjson import dumps [as 别名]
def dumps(obj: Any, *args, **kw) -> bytes:
    kw["default"] = _orjson_default
    return _orjson.dumps(obj, *args, **kw) 
开发者ID:jmagnusson,项目名称:netsuite,代码行数:5,代码来源:json.py

示例7: dumps_str

# 需要导入模块: import orjson [as 别名]
# 或者: from orjson import dumps [as 别名]
def dumps_str(obj: Any, *args, **kw) -> str:
    return dumps(obj, *args, **kw).decode("utf-8") 
开发者ID:jmagnusson,项目名称:netsuite,代码行数:4,代码来源:json.py

示例8: write

# 需要导入模块: import orjson [as 别名]
# 或者: from orjson import dumps [as 别名]
def write(self, elems):
        for elem in elems:
            self.fh.write(orjson.dumps(elem) + b"\n") 
开发者ID:mozilla,项目名称:bugbug,代码行数:5,代码来源:db.py

示例9: orjson_dumps

# 需要导入模块: import orjson [as 别名]
# 或者: from orjson import dumps [as 别名]
def orjson_dumps(v, *, default):
    # orjson.dumps returns bytes, to match standard json.dumps we need to decode
    return orjson.dumps(v, default=default).decode() 
开发者ID:samuelcolvin,项目名称:pydantic,代码行数:5,代码来源:exporting_models_orjson.py

示例10: classify_bug

# 需要导入模块: import orjson [as 别名]
# 或者: from orjson import dumps [as 别名]
def classify_bug(model_name: str, bug_ids: Iterable[int], bugzilla_token: str) -> str:
    from bugbug_http.app import JobInfo

    # This should be called in a process worker so it should be safe to set
    # the token here
    bug_ids_set = set(map(int, bug_ids))
    bugzilla.set_token(bugzilla_token)
    bugs = bugzilla.get(bug_ids)

    missing_bugs = bug_ids_set.difference(bugs.keys())

    for bug_id in missing_bugs:
        job = JobInfo(classify_bug, model_name, bug_id)

        # TODO: Find a better error format
        setkey(job.result_key, orjson.dumps({"available": False}))

    if not bugs:
        return "NOK"

    model = MODEL_CACHE.get(model_name)

    if not model:
        LOGGER.info("Missing model %r, aborting" % model_name)
        return "NOK"

    model_extra_data = model.get_extra_data()

    # TODO: Classify could choke on a single bug which could make the whole
    # job to fails. What should we do here?
    probs = model.classify(list(bugs.values()), True)
    indexes = probs.argmax(axis=-1)
    suggestions = model.le.inverse_transform(indexes)

    probs_list = probs.tolist()
    indexes_list = indexes.tolist()
    suggestions_list = suggestions.tolist()

    for i, bug_id in enumerate(bugs.keys()):
        data = {
            "prob": probs_list[i],
            "index": indexes_list[i],
            "class": suggestions_list[i],
            "extra_data": model_extra_data,
        }

        job = JobInfo(classify_bug, model_name, bug_id)
        setkey(job.result_key, orjson.dumps(data))

        # Save the bug last change
        setkey(job.change_time_key, bugs[bug_id]["last_change_time"].encode())

    return "OK" 
开发者ID:mozilla,项目名称:bugbug,代码行数:55,代码来源:models.py


注:本文中的orjson.dumps方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。