mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-01-19 09:38:21 +08:00
💡 add docstring
This commit is contained in:
parent
916bb5b0e6
commit
62c0dd6e74
@ -275,6 +275,69 @@ Reverse Driver 基类。将后端框架封装,以满足适配器使用。
|
|||||||
HTTP 请求封装。参考 [asgi http scope](https://asgi.readthedocs.io/en/latest/specs/www.html#http-connection-scope)。
|
HTTP 请求封装。参考 [asgi http scope](https://asgi.readthedocs.io/en/latest/specs/www.html#http-connection-scope)。
|
||||||
|
|
||||||
|
|
||||||
|
### _property_ `type`
|
||||||
|
|
||||||
|
Always http
|
||||||
|
|
||||||
|
|
||||||
|
### _property_ `scope`
|
||||||
|
|
||||||
|
Raw scope from asgi.
|
||||||
|
|
||||||
|
The connection scope information, a dictionary that
|
||||||
|
contains at least a type key specifying the protocol that is incoming.
|
||||||
|
|
||||||
|
|
||||||
|
### _property_ `http_version`
|
||||||
|
|
||||||
|
One of "1.0", "1.1" or "2".
|
||||||
|
|
||||||
|
|
||||||
|
### _property_ `method`
|
||||||
|
|
||||||
|
The HTTP method name, uppercased.
|
||||||
|
|
||||||
|
|
||||||
|
### _property_ `schema`
|
||||||
|
|
||||||
|
URL scheme portion (likely "http" or "https").
|
||||||
|
Optional (but must not be empty); default is "http".
|
||||||
|
|
||||||
|
|
||||||
|
### _property_ `path`
|
||||||
|
|
||||||
|
HTTP request target excluding any query string,
|
||||||
|
with percent-encoded sequences and UTF-8 byte sequences
|
||||||
|
decoded into characters.
|
||||||
|
|
||||||
|
|
||||||
|
### _property_ `query_string`
|
||||||
|
|
||||||
|
URL portion after the ?, percent-encoded.
|
||||||
|
|
||||||
|
|
||||||
|
### _property_ `headers`
|
||||||
|
|
||||||
|
An iterable of [name, value] two-item iterables,
|
||||||
|
where name is the header name, and value is the header value.
|
||||||
|
|
||||||
|
Order of header values must be preserved from the original HTTP request;
|
||||||
|
order of header names is not important.
|
||||||
|
|
||||||
|
Duplicates are possible and must be preserved in the message as received.
|
||||||
|
|
||||||
|
Header names must be lowercased.
|
||||||
|
|
||||||
|
|
||||||
|
### _property_ `body`
|
||||||
|
|
||||||
|
Body of the request.
|
||||||
|
|
||||||
|
Optional; if missing defaults to b"".
|
||||||
|
|
||||||
|
If more_body is set, treat as start of body and concatenate on further chunks.
|
||||||
|
|
||||||
|
|
||||||
## _class_ `HTTPResponse`
|
## _class_ `HTTPResponse`
|
||||||
|
|
||||||
基类:`object`
|
基类:`object`
|
||||||
@ -282,11 +345,41 @@ HTTP 请求封装。参考 [asgi http scope](https://asgi.readthedocs.io/en/late
|
|||||||
HTTP 响应封装。参考 [asgi http scope](https://asgi.readthedocs.io/en/latest/specs/www.html#http-connection-scope)。
|
HTTP 响应封装。参考 [asgi http scope](https://asgi.readthedocs.io/en/latest/specs/www.html#http-connection-scope)。
|
||||||
|
|
||||||
|
|
||||||
|
### `status`
|
||||||
|
|
||||||
|
HTTP status code.
|
||||||
|
|
||||||
|
|
||||||
|
### `headers`
|
||||||
|
|
||||||
|
An iterable of [name, value] two-item iterables,
|
||||||
|
where name is the header name,
|
||||||
|
and value is the header value.
|
||||||
|
|
||||||
|
Order must be preserved in the HTTP response.
|
||||||
|
|
||||||
|
Header names must be lowercased.
|
||||||
|
|
||||||
|
Optional; if missing defaults to an empty list.
|
||||||
|
|
||||||
|
|
||||||
|
### `body`
|
||||||
|
|
||||||
|
HTTP body content.
|
||||||
|
|
||||||
|
Optional; if missing defaults to None.
|
||||||
|
|
||||||
|
|
||||||
|
### _property_ `type`
|
||||||
|
|
||||||
|
Always http
|
||||||
|
|
||||||
|
|
||||||
## _class_ `WebSocket`
|
## _class_ `WebSocket`
|
||||||
|
|
||||||
基类:`object`
|
基类:`object`
|
||||||
|
|
||||||
WebSocket 连接封装,统一接口方便外部调用。
|
WebSocket 连接封装。参考 [asgi websocket scope](https://asgi.readthedocs.io/en/latest/specs/www.html#websocket-connection-scope)。
|
||||||
|
|
||||||
|
|
||||||
### _abstract_ `__init__(websocket)`
|
### _abstract_ `__init__(websocket)`
|
||||||
|
@ -243,38 +243,72 @@ class HTTPRequest:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def type(self) -> str:
|
def type(self) -> str:
|
||||||
|
"""Always `http`"""
|
||||||
return "http"
|
return "http"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def scope(self) -> MutableMapping[str, Any]:
|
def scope(self) -> MutableMapping[str, Any]:
|
||||||
|
"""Raw scope from asgi.
|
||||||
|
|
||||||
|
The connection scope information, a dictionary that
|
||||||
|
contains at least a `type` key specifying the protocol that is incoming.
|
||||||
|
"""
|
||||||
return self._scope
|
return self._scope
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def http_version(self) -> str:
|
def http_version(self) -> str:
|
||||||
|
"""One of `"1.0"`, `"1.1"` or `"2"`."""
|
||||||
raise self.scope["http_version"]
|
raise self.scope["http_version"]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def method(self) -> str:
|
def method(self) -> str:
|
||||||
|
"""The HTTP method name, uppercased."""
|
||||||
raise self.scope["method"]
|
raise self.scope["method"]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def schema(self) -> str:
|
def schema(self) -> str:
|
||||||
|
"""
|
||||||
|
URL scheme portion (likely `"http"` or `"https"`).
|
||||||
|
Optional (but must not be empty); default is `"http"`.
|
||||||
|
"""
|
||||||
raise self.scope["schema"]
|
raise self.scope["schema"]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def path(self) -> str:
|
def path(self) -> str:
|
||||||
|
"""
|
||||||
|
HTTP request target excluding any query string,
|
||||||
|
with percent-encoded sequences and UTF-8 byte sequences
|
||||||
|
decoded into characters.
|
||||||
|
"""
|
||||||
return self.scope["path"]
|
return self.scope["path"]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def query_string(self) -> bytes:
|
def query_string(self) -> bytes:
|
||||||
|
""" URL portion after the `?`, percent-encoded."""
|
||||||
return self.scope["query_string"]
|
return self.scope["query_string"]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def headers(self) -> List[Tuple[bytes, bytes]]:
|
def headers(self) -> List[Tuple[bytes, bytes]]:
|
||||||
|
"""An iterable of [name, value] two-item iterables,
|
||||||
|
where name is the header name, and value is the header value.
|
||||||
|
|
||||||
|
Order of header values must be preserved from the original HTTP request;
|
||||||
|
order of header names is not important.
|
||||||
|
|
||||||
|
Duplicates are possible and must be preserved in the message as received.
|
||||||
|
|
||||||
|
Header names must be lowercased.
|
||||||
|
"""
|
||||||
return list(self.scope["headers"])
|
return list(self.scope["headers"])
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def body(self) -> bytes:
|
def body(self) -> bytes:
|
||||||
|
"""Body of the request.
|
||||||
|
|
||||||
|
Optional; if missing defaults to b"".
|
||||||
|
|
||||||
|
If more_body is set, treat as start of body and concatenate on further chunks.
|
||||||
|
"""
|
||||||
return self.scope["body"]
|
return self.scope["body"]
|
||||||
|
|
||||||
|
|
||||||
@ -285,19 +319,41 @@ class HTTPResponse:
|
|||||||
https://asgi.readthedocs.io/en/latest/specs/www.html#http-connection-scope
|
https://asgi.readthedocs.io/en/latest/specs/www.html#http-connection-scope
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, status: int, headers: List[Tuple[bytes, bytes]],
|
def __init__(self,
|
||||||
body: bytes):
|
status: int,
|
||||||
|
headers: List[Tuple[bytes, bytes]] = [],
|
||||||
|
body: Optional[bytes] = None):
|
||||||
self.status: int = status
|
self.status: int = status
|
||||||
|
"""HTTP status code."""
|
||||||
self.headers: List[Tuple[bytes, bytes]] = headers
|
self.headers: List[Tuple[bytes, bytes]] = headers
|
||||||
self.body: bytes = body
|
"""An iterable of [name, value] two-item iterables,
|
||||||
|
where name is the header name,
|
||||||
|
and value is the header value.
|
||||||
|
|
||||||
|
Order must be preserved in the HTTP response.
|
||||||
|
|
||||||
|
Header names must be lowercased.
|
||||||
|
|
||||||
|
Optional; if missing defaults to an empty list.
|
||||||
|
"""
|
||||||
|
self.body: Optional[bytes] = body
|
||||||
|
"""HTTP body content.
|
||||||
|
|
||||||
|
Optional; if missing defaults to `None`.
|
||||||
|
"""
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def type(self) -> str:
|
def type(self) -> str:
|
||||||
|
"""Always `http`"""
|
||||||
return "http"
|
return "http"
|
||||||
|
|
||||||
|
|
||||||
class WebSocket:
|
class WebSocket:
|
||||||
"""WebSocket 连接封装,统一接口方便外部调用。"""
|
"""WebSocket 连接封装。参考 `asgi websocket scope`_。
|
||||||
|
|
||||||
|
.. _asgi websocket scope:
|
||||||
|
https://asgi.readthedocs.io/en/latest/specs/www.html#websocket-connection-scope
|
||||||
|
"""
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def __init__(self, websocket):
|
def __init__(self, websocket):
|
||||||
|
Loading…
Reference in New Issue
Block a user