Файловый менеджер - Редактировать - /opt/imh-python/lib/python3.9/site-packages/botocore/__pycache__/stub.cpython-39.pyc
Ðазад
a p�h8 � @ sz d dl Z d dlmZ d dlmZ d dlmZ d dlmZm Z m Z mZ d dlm Z G dd� de�Ze� ZG d d � d e�ZdS )� N)�deque)�pformat)�validate_parameters)�ParamValidationError�StubResponseError�StubAssertionError�UnStubbedResponseError)�AWSResponsec @ s( e Zd ZdZdd� Zdd� Zdd� ZdS ) �_ANYzZ A helper object that compares equal to everything. Copied from unittest.mock c C s dS )NT� ��self�otherr r �}/root/rpmbuild/BUILDROOT/imh-python39-modules-3.9.7-92.el8.x86_64/opt/imh-python/lib/python3.9/site-packages/botocore/stub.py�__eq__ s z_ANY.__eq__c C s dS )NFr r r r r �__ne__ s z_ANY.__ne__c C s dS )Nz<ANY>r �r r r r �__repr__# s z _ANY.__repr__N)�__name__� __module__�__qualname__�__doc__r r r r r r r r s r c @ s� e Zd ZdZdd� Zdd� Zdd� Zdd � Zd d� Zd!d d�Z dd� Z d"dd�Zdd� Zdd� Z dd� Zdd� Zdd� Zdd � ZdS )#�Stubbera� This class will allow you to stub out requests so you don't have to hit an endpoint to write tests. Responses are returned first in, first out. If operations are called out of order, or are called with no remaining queued responses, an error will be raised. **Example:** :: import datetime import botocore.session from botocore.stub import Stubber s3 = botocore.session.get_session().create_client('s3') stubber = Stubber(s3) response = { 'IsTruncated': False, 'Name': 'test-bucket', 'MaxKeys': 1000, 'Prefix': '', 'Contents': [{ 'Key': 'test.txt', 'ETag': '"abc123"', 'StorageClass': 'STANDARD', 'LastModified': datetime.datetime(2016, 1, 20, 22, 9), 'Owner': {'ID': 'abc123', 'DisplayName': 'myname'}, 'Size': 14814 }], 'EncodingType': 'url', 'ResponseMetadata': { 'RequestId': 'abc123', 'HTTPStatusCode': 200, 'HostId': 'abc123' }, 'Marker': '' } expected_params = {'Bucket': 'test-bucket'} stubber.add_response('list_objects', response, expected_params) stubber.activate() service_response = s3.list_objects(Bucket='test-bucket') assert service_response == response This class can also be called as a context manager, which will handle activation / deactivation for you. **Example:** :: import datetime import botocore.session from botocore.stub import Stubber s3 = botocore.session.get_session().create_client('s3') response = { "Owner": { "ID": "foo", "DisplayName": "bar" }, "Buckets": [{ "CreationDate": datetime.datetime(2016, 1, 20, 22, 9), "Name": "baz" }] } with Stubber(s3) as stubber: stubber.add_response('list_buckets', response, {}) service_response = s3.list_buckets() assert service_response == response If you have an input parameter that is a randomly generated value, or you otherwise don't care about its value, you can use ``stub.ANY`` to ignore it in validation. **Example:** :: import datetime import botocore.session from botocore.stub import Stubber, ANY s3 = botocore.session.get_session().create_client('s3') stubber = Stubber(s3) response = { 'IsTruncated': False, 'Name': 'test-bucket', 'MaxKeys': 1000, 'Prefix': '', 'Contents': [{ 'Key': 'test.txt', 'ETag': '"abc123"', 'StorageClass': 'STANDARD', 'LastModified': datetime.datetime(2016, 1, 20, 22, 9), 'Owner': {'ID': 'abc123', 'DisplayName': 'myname'}, 'Size': 14814 }], 'EncodingType': 'url', 'ResponseMetadata': { 'RequestId': 'abc123', 'HTTPStatusCode': 200, 'HostId': 'abc123' }, 'Marker': '' } expected_params = {'Bucket': ANY} stubber.add_response('list_objects', response, expected_params) with stubber: service_response = s3.list_objects(Bucket='test-bucket') assert service_response == response c C s || _ d| _d| _t� | _dS )zA :param client: The client to add your stubs to. Zboto_stubberZboto_stubber_expected_paramsN)�client� _event_id�_expected_params_event_idr �_queue)r r r r r �__init__� s zStubber.__init__c C s | � � | S �N)�activater r r r � __enter__� s zStubber.__enter__c C s | � � d S r )� deactivate)r Zexception_typeZexception_value� tracebackr r r �__exit__� s zStubber.__exit__c C s8 | j jjjd| j| jd� | j jjjd| j| jd� dS )z5 Activates the stubber on the client �before-parameter-build.*.*�� unique_id�before-call.*.*N) r �meta�eventsZregister_first�_assert_expected_paramsr �register�_get_response_handlerr r r r r r � s � �zStubber.activatec C s8 | j jjjd| j| jd� | j jjjd| j| jd� dS )z7 Deactivates the stubber on the client r$ r% r'