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
3 changes: 2 additions & 1 deletion docs/sphinx/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
]

pygments_style = "sphinx"
pygments_dark_style = "monokai"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is required to make sure code blocks such as the one in HttpHeaders are visible in dark mode.


templates_path = []
exclude_patterns = []
Expand All @@ -44,5 +45,5 @@

intersphinx_mapping = {
"python": ("https://docs.python.org/3", None),
"requests": ("https://docs.python-requests.org/en/master", None),
"requests": ("https://docs.python-requests.org/en/latest", None),
Comment on lines -47 to +48
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a redirection in place, but /latest is the correct place. It also avoids a message about this redirection.

}
1 change: 1 addition & 0 deletions docs/sphinx/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ API Reference

installation
nodes
responses
exceptions
logging
transport
Expand Down
43 changes: 43 additions & 0 deletions docs/sphinx/responses.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Responses
=========

.. py:currentmodule:: elastic_transport


Response headers
----------------

.. autoclass:: elastic_transport::HttpHeaders
:members: freeze

Metadata
--------

.. autoclass:: ApiResponseMeta
:members:

Response classes
----------------

.. autoclass:: ApiResponse
:members:

.. autoclass:: BinaryApiResponse
:members:
:show-inheritance:

.. autoclass:: HeadApiResponse
:members:
:show-inheritance:

.. autoclass:: ListApiResponse
:members:
:show-inheritance:

.. autoclass:: ObjectApiResponse
:members:
:show-inheritance:

.. autoclass:: TextApiResponse
:members:
:show-inheritance:
30 changes: 18 additions & 12 deletions elastic_transport/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,15 @@ def __str__(self) -> str:


class HttpHeaders(MutableMapping[str, str]):
"""HTTP headers"""
"""HTTP headers

Behaves like a Python dictionary. Can be used like this::

headers = HttpHeaders()
headers["foo"] = "bar"
headers["foo"] = "baz"
print(headers["foo"]) # prints "baz"
"""

__slots__ = ("_internal", "_frozen")

Expand Down Expand Up @@ -180,26 +188,24 @@ def hide_auth(val: str) -> str:

@dataclass
class ApiResponseMeta:
"""Metadata that is returned from Transport.perform_request()"""
"""Metadata that is returned from Transport.perform_request()

:ivar int status: HTTP status code
:ivar str http_version: HTTP version being used
:ivar HttpHeaders headers: HTTP headers
:ivar float duration: Number of seconds from start of request to start of response
:ivar NodeConfig node: Node which handled the request
:ivar typing.Optional[str] mimetype: Mimetype to be used by the serializer to decode the raw response bytes.
Comment on lines +193 to +198
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to get Sphinx to show the #: comments, even with autodata, so I placed the information in the class docstring, using instance variables.

"""

#: HTTP status code
status: int

#: HTTP version being used
http_version: str

#: HTTP headers
headers: HttpHeaders

#: Number of seconds from start of request to start of response
duration: float

#: Node which handled the request
node: "NodeConfig"

@property
def mimetype(self) -> Optional[str]:
"""Mimetype to be used by the serializer to decode the raw response bytes."""
try:
content_type = self.headers["content-type"]
return content_type.partition(";")[0] or None
Expand Down