Pyjo.AWS.Protocol.RestXML - Call of the REST-XML protocol of AWS

from Pyjo.AWS.Client import Client
from Pyjo.AWS.Protocol.RestXML import RestXML

dom = Client(service='s3').call(RestXML('GET', '/my-bucket', query={'list-type': 2, 'prefix': 'logs/'}))
print(dom.find('Contents > Key').map('text').join('\n'))

# Or import the module, as in Google Python Style Guide

import Pyjo.AWS.Client
import Pyjo.AWS.Protocol.RestXML

s3 = Pyjo.AWS.Client.new(service='s3', region='eu-central-1')
call = Pyjo.AWS.Protocol.RestXML.new('PUT', '/my-bucket/hello.txt', b'Hello!', headers={'Content-Type': 'text/plain'})
s3.call_p(call).then(lambda dom: print('uploaded')).wait()

feed = s3.call(Pyjo.AWS.Protocol.RestXML.new('GET', '/my-bucket/feed.xml', raw=True))

Pyjo.AWS.Protocol.RestXML is a call of the REST-XML protocol of AWS, of the APIs of S3, Route 53 and CloudFront: a method and a path, which is percent-encoded already, with the parameters of its query, its headers and its body, as XML. The result is the XML of the response, as a Pyjo.DOM object, its body of another type, or None without a body, as the response of PUT of an object of S3, whose result is in its headers, which a subclass of the call reads in its result(), and tx of an error has.

The result of a call of raw is the body of the response, whatever its Content-Type, empty too, as the payload of GetObject of S3, whose object of XML, as a feed, is not parsed, as a Pyjo.DOM object serialized again may differ from it, of its XML declaration, its whitespace or its entities. Without the models of the APIs, the call does not know which operation has its payload in the body, so GetObject sets it, not the call of its path, where the subresources of an object, as ?tagging and ?acl, give XML too.

The error of the response is the code and the message of its element Error, or its status, as 404 of HEAD, without a body.

See also

Pyjo.AWS.Protocol, Pyjo.AWS.Client, https://smithy.io/2.0/aws/protocols/aws-restxml-protocol.html.

Classes

class Pyjo.AWS.Protocol.RestXML.Pyjo_AWS_Protocol_RestXML(method: str, path: str, body: bytes | str | None = None, *, query: Mapping[str, Any] | None = None, headers: Mapping[str, str] | None = None, raw: bool = False)[source]

Pyjo.AWS.Protocol.RestXML inherits all attributes and methods from Pyjo.AWS.Protocol and implements the following new ones.

__init__(method: str, path: str, body: bytes | str | None = None, *, query: Mapping[str, Any] | None = None, headers: Mapping[str, str] | None = None, raw: bool = False) → None[source]
call = Pyjo.AWS.Protocol.RestXML.new('GET', '/my-bucket', query={'list-type': 2})
call = Pyjo.AWS.Protocol.RestXML.new('PUT', '/my-bucket/hello.txt', b'Hello!')
call = Pyjo.AWS.Protocol.RestXML.new('POST', '/2013-04-01/hostedzone/Z123/rrset', xml)
call = Pyjo.AWS.Protocol.RestXML.new('GET', '/my-bucket/feed.xml', raw=True)

Construct a new Pyjo.AWS.Protocol.RestXML object.

body
body = call.body

The body of the request, its XML or an object of S3, or None for none.

build_tx(ua: Pyjo_UserAgent, url: Pyjo_URL) → Pyjo_Transaction_HTTP[source]
tx = call.build_tx(ua, url)

The transaction of the method and the path, after the path of the endpoint, with the body.

error(tx: Pyjo_Transaction_HTTP) → Pyjo_AWS_Error[source]
e = call.error(tx)

The error of the element Error of the response, or of its status without a body.

headers
headers = call.headers

The headers of the request.

method
method = call.method

The method of the request, as GET.

parse(tx: Pyjo_Transaction_HTTP) → Any[source]
result = call.parse(tx)

The XML of the response, as a Pyjo.DOM object, its body of another type, or None without a body, and its body of a call of raw, empty too.

path
path = call.path

The path of the request, which is percent-encoded already, as /my-bucket/a%20b.txt, with the parameters of a query too.

query
query = call.query

The parameters of the query, whose values are strings, true or false of booleans and the strings of the others, whose None values the request leaves out.

raw
raw = call.raw

The body of the response as the result, whatever its type, as the payload of GetObject of S3, not its XML, False by default.