Represents the elements of an HTTP request. This class was originally inspired by requests.models.Request, but has been boiled down to meet the specific use cases in botocore. That being said this class (even in requests) is effectively a named-tuple.
| 425 | |
| 426 | |
| 427 | class AWSRequest: |
| 428 | """Represents the elements of an HTTP request. |
| 429 | |
| 430 | This class was originally inspired by requests.models.Request, but has been |
| 431 | boiled down to meet the specific use cases in botocore. That being said this |
| 432 | class (even in requests) is effectively a named-tuple. |
| 433 | """ |
| 434 | |
| 435 | _REQUEST_PREPARER_CLS = AWSRequestPreparer |
| 436 | |
| 437 | def __init__( |
| 438 | self, |
| 439 | method=None, |
| 440 | url=None, |
| 441 | headers=None, |
| 442 | data=None, |
| 443 | params=None, |
| 444 | auth_path=None, |
| 445 | stream_output=False, |
| 446 | ): |
| 447 | self._request_preparer = self._REQUEST_PREPARER_CLS() |
| 448 | |
| 449 | # Default empty dicts for dict params. |
| 450 | params = {} if params is None else params |
| 451 | |
| 452 | self.method = method |
| 453 | self.url = url |
| 454 | self.headers = HTTPHeaders() |
| 455 | self.data = data |
| 456 | self.params = params |
| 457 | self.auth_path = auth_path |
| 458 | self.stream_output = stream_output |
| 459 | |
| 460 | if headers is not None: |
| 461 | for key, value in headers.items(): |
| 462 | self.headers[key] = value |
| 463 | |
| 464 | # This is a dictionary to hold information that is used when |
| 465 | # processing the request. What is inside of ``context`` is open-ended. |
| 466 | # For example, it may have a timestamp key that is used for holding |
| 467 | # what the timestamp is when signing the request. Note that none |
| 468 | # of the information that is inside of ``context`` is directly |
| 469 | # sent over the wire; the information is only used to assist in |
| 470 | # creating what is sent over the wire. |
| 471 | self.context = {} |
| 472 | |
| 473 | def prepare(self): |
| 474 | """Constructs a :class:`AWSPreparedRequest <AWSPreparedRequest>`.""" |
| 475 | return self._request_preparer.prepare(self) |
| 476 | |
| 477 | @property |
| 478 | def body(self): |
| 479 | body = self.prepare().body |
| 480 | if isinstance(body, str): |
| 481 | body = body.encode('utf-8') |
| 482 | return body |
| 483 | |
| 484 |
no outgoing calls