Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_encode_unsupported():
unserializable = Unserializable()
with pytest.raises(ValueError):
jsonable_encoder(unserializable)
def upsert(
bucket: Bucket, *, doc_id: str, doc_in: PydanticModel, persist_to=0, ttl=0
) -> Optional[PydanticModel]:
doc_data = jsonable_encoder(doc_in)
with bucket.durability(
persist_to=persist_to, timeout=config.COUCHBASE_DURABILITY_TIMEOUT_SECS
):
result = bucket.upsert(doc_id, doc_data, ttl=ttl)
if result.success:
return doc_in
return None
def update_in_db(bucket: Bucket, *, username: str, user_in: UserUpdate, persist_to=0):
user_doc_id = get_doc_id(username)
stored_user = get(bucket, username=username)
stored_user = stored_user.copy(update=user_in.dict(skip_defaults=True))
if user_in.password:
passwordhash = get_password_hash(user_in.password)
stored_user.hashed_password = passwordhash
data = jsonable_encoder(stored_user)
with bucket.durability(
persist_to=persist_to, timeout=config.COUCHBASE_DURABILITY_TIMEOUT_SECS
):
bucket.upsert(user_doc_id, data)
return stored_user
if path:
paths.setdefault(openapi_prefix + route.path_format, {}).update(
path
)
if security_schemes:
components.setdefault("securitySchemes", {}).update(
security_schemes
)
if path_definitions:
definitions.update(path_definitions)
if definitions:
components["schemas"] = {k: definitions[k] for k in sorted(definitions)}
if components:
output["components"] = components
output["paths"] = paths
return jsonable_encoder(OpenAPI(**output), by_alias=True, include_none=False)
) -> Any:
if field:
errors = []
if exclude_unset and isinstance(response, BaseModel):
if PYDANTIC_1:
response = response.dict(exclude_unset=exclude_unset)
else:
response = response.dict(skip_defaults=exclude_unset) # pragma: nocover
value, errors_ = field.validate(response, {}, loc=("response",))
if isinstance(errors_, ErrorWrapper):
errors.append(errors_)
elif isinstance(errors_, list):
errors.extend(errors_)
if errors:
raise ValidationError(errors, field.type_)
return jsonable_encoder(
value,
include=include,
exclude=exclude,
by_alias=by_alias,
exclude_unset=exclude_unset,
)
else:
return jsonable_encoder(response)
def __render_json_response(data):
res = {
'meta': { 'status': 200 },
'data': data,
}
content = jsonable_encoder(res)
return JSONResponse(content=content)
def _build_for_create_users_with_list_input(self, body: List[m.User]) -> Awaitable[None]:
body = jsonable_encoder(body)
return self.api_client.request(type_=None, method="POST", url="/user/createWithList", json=body)