ContentDecodePolicy Class
Policy for decoding unstreamed response content.
- Inheritance
-
azure.core.pipeline.policies._base.SansIOHTTPPolicyContentDecodePolicy
Constructor
ContentDecodePolicy(response_encoding: Optional[str] = None, **kwargs: Any)
Parameters
- response_encoding
- str
The encoding to use if known for this service (will disable auto-detection)
Methods
| deserialize_from_http_generics |
Deserialize from HTTP response. Headers will tested for "content-type" |
| deserialize_from_text |
Decode response data according to content-type. Accept a stream of data as well, but will be load at once in memory for now. If no content-type, will return the string version (not bytes, not stream) |
| on_request |
Is executed before sending the request from next policy. |
| on_response |
Extract data from the body of a REST response object. This will load the entire payload in memory. Will follow Content-Type to parse. We assume everything is UTF8 (BOM acceptable). |
deserialize_from_http_generics
Deserialize from HTTP response.
Headers will tested for "content-type"
deserialize_from_http_generics(response, encoding=None)
Parameters
- response
The HTTP response
- encoding
The encoding to use if known for this service (will disable auto-detection)
- encoding
Returns
A dict or XML tree, depending of the mime-type
Exceptions
If deserialization fails
deserialize_from_text
Decode response data according to content-type.
Accept a stream of data as well, but will be load at once in memory for now. If no content-type, will return the string version (not bytes, not stream)
deserialize_from_text(data, mime_type=None, response=None)
Parameters
- response
If passed, exception will be annotated with that response
- response
Returns
A dict or XML tree, depending of the mime_type
Exceptions
If deserialization fails
on_request
Is executed before sending the request from next policy.
on_request(request: azure.core.pipeline.PipelineRequest) -> None
Parameters
Exceptions
If deserialization fails
on_response
Extract data from the body of a REST response object. This will load the entire payload in memory. Will follow Content-Type to parse. We assume everything is UTF8 (BOM acceptable).
on_response(request: PipelineRequest[HTTPRequestType], response: PipelineResponse[HTTPRequestType, Union[HttpResponse, AsyncHttpResponse]]) -> None
Parameters
- raw_data
Data to be processed.
- content_type
How to parse if raw_data is a string/bytes.
Exceptions
If JSON is requested and parsing is impossible.
If bytes is not UTF8
If bytes is not valid XML
If deserialization fails
Attributes
CONTEXT_NAME
CONTEXT_NAME = 'deserialized_data'
JSON_REGEXP
JSON_REGEXP = re.compile('^(application|text)/([0-9a-z+.-]+\\+)?json$')
Feedback
Submit and view feedback for