
    vKg;                         S SK r S SKJr  S SKJr  S SKJr  S SKJrJ	r	J
r
Jr  S SKJr   " S S5      r\" 5       r " S	 S
5      rg)    N)deque)pformat)AWSResponse)ParamValidationErrorStubAssertionErrorStubResponseErrorUnStubbedResponseError)validate_parametersc                   *    \ rS rSrSrS rS rS rSrg)_ANY   zN
A helper object that compares equal to everything. Copied from
unittest.mock
c                     g)NT selfothers     M/var/www/highfloat_scraper/venv/lib/python3.13/site-packages/botocore/stub.py__eq___ANY.__eq__!   s        c                     g)NFr   r   s     r   __ne___ANY.__ne__$   s    r   c                     g)Nz<ANY>r   r   s    r   __repr___ANY.__repr__'   s    r   r   N)	__name__
__module____qualname____firstlineno____doc__r   r   r   __static_attributes__r   r   r   r   r      s    
r   r   c                       \ rS rSrSrS rS rS rS rS r	SS	 jr
S
 r       SS jrS rS rS rS rS rS rS rSrg)Stubber.   a  
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                 J    Xl         SU l        SU l        [        5       U l        g)z1
:param client: The client to add your stubs to.
boto_stubberboto_stubber_expected_paramsN)client	_event_id_expected_params_event_idr   _queue)r   r*   s     r   __init__Stubber.__init__   s!     ')G&gr   c                 &    U R                  5         U $ N)activater   s    r   	__enter__Stubber.__enter__   s    r   c                 $    U R                  5         g r1   )
deactivate)r   exception_typeexception_value	tracebacks       r   __exit__Stubber.__exit__   s    r   c                    U R                   R                  R                  R                  SU R                  U R
                  S9  U R                   R                  R                  R                  SU R                  U R                  S9  g)z%
Activates the stubber on the client
before-parameter-build.*.*	unique_idbefore-call.*.*N)	r*   metaeventsregister_first_assert_expected_paramsr,   register_get_response_handlerr+   r   s    r   r2   Stubber.activate   st     	..(((44 	/ 	

 	((&&nn 	) 	
r   c                    U R                   R                  R                  R                  SU R                  U R
                  S9  U R                   R                  R                  R                  SU R                  U R                  S9  g)z'
Deactivates the stubber on the client
r=   r>   r@   N)r*   rA   rB   
unregisterrD   r,   rF   r+   r   s    r   r6   Stubber.deactivate   st     	**(((44 	+ 	

 	**&&nn 	+ 	
r   Nc                 (    U R                  XU5        g)a  
Adds a service response to the response queue. This will be validated
against the service model to ensure correctness. It should be noted,
however, that while missing attributes are often considered correct,
your code may not function properly if you leave them out. Therefore
you should always fill in every value you see in a typical response for
your particular request.

:param method: The name of the client method to stub.
:type method: str

:param service_response: A dict response stub. Provided parameters will
    be validated against the service model.
:type service_response: dict

:param expected_params: A dictionary of the expected parameters to
    be called for the provided service response. The parameters match
    the names of keyword arguments passed to that client call. If
    any of the parameters differ a ``StubResponseError`` is thrown.
    You can use stub.ANY to indicate a particular parameter to ignore
    in validation. stub.ANY is only valid for top level params.
N)_add_response)r   methodservice_responseexpected_paramss       r   add_responseStubber.add_response   s    . 	6_Er   c                    [        U R                  U5      (       d9  [        SU R                  R                  R                  R
                   SU 35      e[        S S0 S 5      nU R                  R                  R                  R                  U5      nU R                  XR5        UXB4US.nU R                  R                  U5        g )NzClient z does not have method:    operation_nameresponserO   )hasattrr*   
ValueErrorrA   service_modelservice_namer   method_to_api_mappingget_validate_operation_responser-   append)r   rM   rN   rO   http_responserU   rV   s          r   rL   Stubber._add_response   s    t{{F++$++**88EEF G))/2  $D#r48))??CCFK)).K -&9.

 	8$r   c	                    [        SU0 S5      n	SU0X2S.S.n
Ub  U
S   R                  U5        Ub  U
S   R                  U5        UbS  U R                  R                  R                  nUR                  U5      nU R                  X5        U
R                  U5        U R                  R                  R                  R                  U5      nUX4US.nU R                  R                  U5        g)a_  
Adds a ``ClientError`` to the response queue.

:param method: The name of the service method to return the error on.
:type method: str

:param service_error_code: The service error code to return,
                           e.g. ``NoSuchBucket``
:type service_error_code: str

:param service_message: The service message to return, e.g.
                'The specified bucket does not exist.'
:type service_message: str

:param http_status_code: The HTTP status code to return, e.g. 404, etc
:type http_status_code: int

:param service_error_meta: Additional keys to be added to the
    service Error
:type service_error_meta: dict

:param expected_params: A dictionary of the expected parameters to
    be called for the provided service response. The parameters match
    the names of keyword arguments passed to that client call. If
    any of the parameters differ a ``StubResponseError`` is thrown.
    You can use stub.ANY to indicate a particular parameter to ignore
    in validation.

:param response_meta: Additional keys to be added to the
    response's ResponseMetadata
:type response_meta: dict

:param modeled_fields: Additional keys to be added to the response
    based on fields that are modeled for the particular error code.
    These keys will be validated against the particular error shape
    designated by the error code.
:type modeled_fields: dict

NHTTPStatusCode)MessageCode)ResponseMetadataErrorrf   re   rT   )r   updater*   rA   rY   shape_for_error_code_validate_responser[   r\   r-   r^   )r   rM   service_error_codeservice_messagehttp_status_codeservice_error_metarO   response_metamodeled_fieldsr_   parsed_responserY   shaperU   rV   s                  r   add_client_errorStubber.add_client_error  s    d $D*:BE "23C D!0M

 )G$++,>?$./66}E% KK,,::M!667IJE##E:"">2))??CCFK -&8.

 	8$r   c                 V    [        U R                  5      nUS:w  a  [        U S35      eg)z,
Asserts that all expected calls were made.
r   z responses remaining in queue.N)lenr-   AssertionError)r   	remainings     r   assert_no_pending_responses#Stubber.assert_no_pending_responsesV  s1     $	> I;.L!MNN r   c                     U R                   (       d  [        UR                  SS9eU R                   S   S   nX1R                  :w  a  [        UR                  SU S3S9eg )NzUnexpected API Call: A call was made but no additional calls expected. Either the API Call was not stubbed or it was called multiple times.rU   reasonr   rU   z'Operation mismatch: found response for .)r-   r	   namer   )r   modelparamsr~   s       r   _assert_expected_call_order#Stubber._assert_expected_call_order^  sf    {{($zz4  {{1~./::#$zz@aH  r   c                 ^    U R                  X5        U R                  R                  5       S   $ )NrV   )r   r-   popleft)r   r   r   contextkwargss        r   rF   Stubber._get_response_handlerp  s(    ((7{{""$Z00r   c           
         U R                  U5      (       a  g U R                  X5        U R                  S   S   nUc  g UR                  5        H@  u  pgXb;  d  XV   X&   :w  d  M  [	        UR
                  S[        U5       S[        U5       3S9e   [        UR                  5       5      [        UR                  5       5      :w  a,  [	        UR
                  S[        U5       S[        U5       3S9eg )Nr   rO   zExpected parameters:
z,
but received:
r{   )	_should_not_stubr   r-   itemsr   r~   r   sortedkeys)r   r   r   r   r   rO   paramvalues           r   rD   Stubber._assert_expected_paramsu  s      ))((7++a.):;" ,113LE"o&<&M(#(::01I0J K**1&/):<  4 /&&()VFKKM-BB$$zz,W_-E,F G&&-fo%68  Cr   c                 B    U(       a  UR                  S5      (       a  gg g )Nis_presign_requestT)r\   )r   r   s     r   r   Stubber._should_not_stub  s      w{{#788 97r   c                     U R                   R                  R                  nUR                  U5      nUR                  nUnSU;   a  [
        R
                  " U5      nUS	 U R                  XV5        g )Nre   )r*   rA   rY   operation_modeloutput_shapecopyri   )r   rU   rN   rY   r   r   rV   s          r   r]   $Stubber._validate_operation_response  sg    ((66'77G&33 $)yy!12H+,7r   c                 B    Ub  [        X!5        g U(       a	  [        SS9eg )Nz6Service response should only contain ResponseMetadata.)report)r
   r   )r   rq   rV   s      r   ri   Stubber._validate_response  s*    0 'L  r   )r+   r,   r-   r*   r1   ) r   i  NNNN)r   r   r    r!   r"   r.   r3   r:   r2   r6   rP   rL   rr   rx   r   rF   rD   r   r]   ri   r#   r   r   r   r%   r%   .   so    wr

F2%0 P%dO$1
:8
r   r%   )r   collectionsr   pprintr   botocore.awsrequestr   botocore.exceptionsr   r   r   r	   botocore.validater
   r   ANYr%   r   r   r   <module>r      sA       +  2   fC Cr   