RestReply
Base classes
| Name |
Children |
Inherits |
QRestReply PySide6.QtNetwork QRestReply(self, reply: PySide6.QtNetwork.QNetworkReply, /) -> None |
|
|
⋔ Inheritance diagram
graph TD
2963176294["network.RestReply"]
91902614["QtNetwork.QRestReply"]
37984305["Shiboken.Object"]
2751680898["builtins.object"]
91902614 --> 2963176294
37984305 --> 91902614
2751680898 --> 37984305
🛈 DocStrings
Bases: QRestReply
Convenience wrapper around QNetworkReply for RESTful operations.
Source code in prettyqt/network/restreply.py
| class RestReply(QtNetwork.QRestReply):
"""Convenience wrapper around QNetworkReply for RESTful operations."""
def __repr__(self):
return get_repr(self, self.httpStatus(), self.get_error())
def __bool__(self) -> bool:
return self.isSuccess()
def get_error(self) -> network.networkreply.NetworkErrorStr:
"""Return the network error type as a string."""
return network.networkreply.NETWORK_ERROR.inverse[self.error()]
def get_http_status(self) -> int:
"""Return the HTTP status code received in the server response."""
return self.httpStatus()
def is_success(self) -> bool:
"""Return whether the request succeeded without network or HTTP error."""
return self.isSuccess()
def is_http_status_success(self) -> bool:
"""Return whether the HTTP status code is between 200 and 299."""
return self.isHttpStatusSuccess()
def read_text(self) -> str:
"""Read the received data as a string."""
return self.readText()
def read_body(self) -> bytes:
"""Read the received data as raw bytes."""
return bytes(self.readBody().data())
def read_json(self) -> Any:
"""Read and parse the received JSON data into Python objects, or None."""
result = self.readJson()
doc = result[0] if isinstance(result, tuple) else result
if doc is None or doc.isNull():
return None
return json.loads(bytes(doc.toJson().data()).decode())
def get_network_reply(self) -> network.NetworkReply | None:
"""Return the underlying NetworkReply, or None if unset."""
reply = self.networkReply()
return network.NetworkReply(reply) if reply is not None else None
|
get_error() -> network.networkreply.NetworkErrorStr
Return the network error type as a string.
Source code in prettyqt/network/restreply.py
| def get_error(self) -> network.networkreply.NetworkErrorStr:
"""Return the network error type as a string."""
return network.networkreply.NETWORK_ERROR.inverse[self.error()]
|
get_http_status() -> int
Return the HTTP status code received in the server response.
Source code in prettyqt/network/restreply.py
| def get_http_status(self) -> int:
"""Return the HTTP status code received in the server response."""
return self.httpStatus()
|
get_network_reply() -> network.NetworkReply | None
Return the underlying NetworkReply, or None if unset.
Source code in prettyqt/network/restreply.py
| def get_network_reply(self) -> network.NetworkReply | None:
"""Return the underlying NetworkReply, or None if unset."""
reply = self.networkReply()
return network.NetworkReply(reply) if reply is not None else None
|
is_http_status_success() -> bool
Return whether the HTTP status code is between 200 and 299.
Source code in prettyqt/network/restreply.py
| def is_http_status_success(self) -> bool:
"""Return whether the HTTP status code is between 200 and 299."""
return self.isHttpStatusSuccess()
|
is_success() -> bool
Return whether the request succeeded without network or HTTP error.
Source code in prettyqt/network/restreply.py
| def is_success(self) -> bool:
"""Return whether the request succeeded without network or HTTP error."""
return self.isSuccess()
|
read_body() -> bytes
Read the received data as raw bytes.
Source code in prettyqt/network/restreply.py
| def read_body(self) -> bytes:
"""Read the received data as raw bytes."""
return bytes(self.readBody().data())
|
read_json() -> Any
Read and parse the received JSON data into Python objects, or None.
Source code in prettyqt/network/restreply.py
| def read_json(self) -> Any:
"""Read and parse the received JSON data into Python objects, or None."""
result = self.readJson()
doc = result[0] if isinstance(result, tuple) else result
if doc is None or doc.isNull():
return None
return json.loads(bytes(doc.toJson().data()).decode())
|
read_text() -> str
Read the received data as a string.
Source code in prettyqt/network/restreply.py
| def read_text(self) -> str:
"""Read the received data as a string."""
return self.readText()
|
:fa-brands-github: Show source on GitHub