Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions nexios_contrib/accepts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,40 @@
This module provides content negotiation and Accept header processing
for Nexios applications.
"""

from __future__ import annotations

from .dependency import AcceptsDepend
from .helpers import (
AcceptItem,
parse_accept_header,
parse_accept_language,
parse_accept_charset,
parse_accept_encoding,
negotiate_content_type,
negotiate_language,
negotiate_charset,
negotiate_encoding,
matches_media_type,
get_best_match,
get_accepts_info,
AcceptsInfo,
create_vary_header,
get_accepted_content_types,
get_accepted_languages,
get_accepted_charsets,
get_accepted_content_types,
get_accepted_encodings,
get_accepted_languages,
get_accepts_from_request,
get_accepts_info,
get_best_accepted_content_type,
get_best_accepted_language,
get_accepts_from_request,
AcceptsInfo,

get_best_match,
matches_media_type,
negotiate_charset,
negotiate_content_type,
negotiate_encoding,
negotiate_language,
parse_accept_charset,
parse_accept_encoding,
parse_accept_header,
parse_accept_language,
)
from .middleware import (
Accepts,

AcceptsMiddleware,
ContentNegotiationMiddleware,
StrictContentNegotiationMiddleware,
)
from .dependency import AcceptsDepend

__all__ = [
"AcceptItem",
"parse_accept_header",
Expand Down
19 changes: 11 additions & 8 deletions nexios_contrib/accepts/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
This module provides dependency injection utilities for accessing
parsed Accept header information from requests.
"""
from __future__ import annotations

from typing import Any
from nexios.dependencies import Depend, Context
from nexios.http import Request
from .helpers import AcceptsInfo

from __future__ import annotations
from typing import cast


from nexios.dependencies import Context, Depend
from nexios.http import Request

from .helpers import AcceptsInfo


def get_accepts_info_from_request(request: Request, attribute_name: str = "accepts") -> AcceptsInfo:
def get_accepts_info_from_request(
request: Request, attribute_name: str = "accepts"
) -> AcceptsInfo:
"""
Get AcceptsInfo object from request.

Expand Down Expand Up @@ -54,7 +55,9 @@ async def get_users(
accepted_types = accepts.get_accepted_types()
return {"accepted_types": accepted_types}
"""

def _wrap(request: Request = Context().request) -> AcceptsInfo:
return get_accepts_info_from_request(request, attribute_name)

return Depend(_wrap)
return cast(AcceptsInfo, Depend(_wrap))

Loading
Loading