
    vKgz                         S SK r S SKrS SKrS SKrS SKrS SKrS SKJrJr  S SK	J
r
  S SKJrJrJr  S SKJrJr  S SKJr   " S S5      r " S	 S
5      rS rSS jr " S S5      rS r SS jrS r SS jrS rg)    N)create_request_objectprepare_request_dict)OrderedDict)UnknownClientMethodErrorUnknownSignatureVersionError UnsupportedSignatureVersionError)	ArnParserdatetime2timestamp)fix_s3_hostc                       \ rS rSrSr SS jr\S 5       r\S 5       r\S 5       r	SS jr
    SS	 jrS
 rS r  SS jr\r   SS jrSrg)RequestSigner!   a  
An object to sign requests before they go out over the wire using
one of the authentication mechanisms defined in ``auth.py``. This
class fires two events scoped to a service and operation name:

* choose-signer: Allows overriding the auth signer name.
* before-sign: Allows mutating the request before signing.

Together these events allow for customization of the request
signing pipeline, including overrides, request path manipulation,
and disabling signing per operation.


:type service_id: botocore.model.ServiceId
:param service_id: The service id for the service, e.g. ``S3``

:type region_name: string
:param region_name: Name of the service region, e.g. ``us-east-1``

:type signing_name: string
:param signing_name: Service signing name. This is usually the
                     same as the service name, but can differ. E.g.
                     ``emr`` vs. ``elasticmapreduce``.

:type signature_version: string
:param signature_version: Signature name like ``v4``.

:type credentials: :py:class:`~botocore.credentials.Credentials`
:param credentials: User credentials with which to sign requests.

:type event_emitter: :py:class:`~botocore.hooks.BaseEventHooks`
:param event_emitter: Extension mechanism to fire events.
Nc                     X l         X0l        X@l        XPl        Xpl        Xl        [        R                  " U5      U l        g N)	_region_name_signing_name_signature_version_credentials_auth_token_service_idweakrefproxy_event_emitter)self
service_idregion_namesigning_namesignature_versioncredentialsevent_emitter
auth_tokens           P/var/www/highfloat_scraper/venv/lib/python3.13/site-packages/botocore/signers.py__init__RequestSigner.__init__D   s;     ()"3'%% &mmM:    c                     U R                   $ r   )r   r   s    r"   r   RequestSigner.region_nameX   s       r%   c                     U R                   $ r   )r   r'   s    r"   r   RequestSigner.signature_version\   s    &&&r%   c                     U R                   $ r   )r   r'   s    r"   r   RequestSigner.signing_name`   s    !!!r%   c                 $    U R                  X5      $ r   )sign)r   operation_namerequestkwargss       r"   handlerRequestSigner.handlerd   s    
 yy11r%   c           
      ,   UnUc  U R                   nUc  U R                  nU R                  XUR                  5      nU R                  R                  SU R                  R                  5        SU 3UUU R                   UU US9  U[        R                  :w  a  UUUS.n	Ub  XYS'   UR                  R                  S0 5      n
U(       d  U
R                  S5      (       a  U
S   U	S	'   U
R                  S
5      (       a  U
S
   U	S
'   U
R                  S5      (       a  U
S   U	S'   U
R                  S5      b  U R                  U	U
S   U
S   5         U R                  " S0 U	D6nUR                  U5        gg! [         a  nUS:w  a	  [        US9eUeSnAff = f)a  Sign a request before it goes out over the wire.

:type operation_name: string
:param operation_name: The name of the current operation, e.g.
                       ``ListBuckets``.
:type request: AWSRequest
:param request: The request object to be sent over the wire.

:type region_name: str
:param region_name: The region to sign the request for.

:type signing_type: str
:param signing_type: The type of signing to perform. This can be one of
    three possible values:

    * 'standard'     - This should be used for most requests.
    * 'presign-url'  - This should be used when pre-signing a request.
    * 'presign-post' - This should be used when pre-signing an S3 post.

:type expires_in: int
:param expires_in: The number of seconds the presigned url is valid
    for. This parameter is only valid for signing type 'presign-url'.

:type signing_name: str
:param signing_name: The name to use for the service when signing.
Nzbefore-sign..)r0   r   r   r   request_signerr/   )r   r   r   expiressigningregionr   r   request_credentialsidentity_cache	cache_keystandardr    )r   r   _choose_signercontextr   emitr   	hyphenizebotocoreUNSIGNEDget_resolve_identity_cacheget_auth_instancer   r   add_auth)r   r/   r0   r   signing_type
expires_inr   explicit_region_namer   r1   signing_contextauthes                r"   r.   RequestSigner.signk   s   F  +++K--L //'//

 	  4++5578.9IJ%))/) 	! 	
  1 11 ,*%6F
 %$.y!%oo11)R@O'O,?,?,I,I(7(A}%"">22)8)H~&""#8990?)1,- ""#34@,,#$45#K0
--77 MM'"C 22 0 :-:*;  Gs   E3 3
F=FFc                     X!S'   X1S'   g )Nr;   r<   r?   )r   r1   cacher<   s       r"   rG   %RequestSigner._resolve_identity_cache   s    #( '{r%   c                 H   SSS.nUR                  US5      nUR                  S5      =(       d    U R                  nUR                  S0 5      nUR                  SU R                  5      nUR                  SU R                  5      n	U[        R
                  La  UR                  U5      (       d  Xe-  nU R                  R                  S	U R                  R                  5        S
U 3UU	UUS9u  pUb/  UnU[        R
                  La  UR                  U5      (       d  Xe-  nU$ )a1  
Allow setting the signature version via the choose-signer event.
A value of `botocore.UNSIGNED` means no signing will be performed.

:param operation_name: The operation to sign.
:param signing_type: The type of signing that the signer is to be used
    for.
:return: The signature version to sign with.
z-presign-postz-query)presign-postpresign-url 	auth_typer8   r   r9   zchoose-signer.r5   )r   r   r   rA   )rF   r   r   r   rD   rE   endswithr   emit_until_responser   rC   )r   r/   rJ   rA   signing_type_suffix_mapsuffixr   r8   r   r   r2   responses               r"   r@   RequestSigner._choose_signer   s0    ,##
 ),,\2> $KK4O8O8O++i,{{>43E3EFkk(D,=,=>X%6%66%..v66' //CCT--779:!N;KL%#/ D 
  ( "):)::)226::!+!  r%   c                 b   Uc  U R                   n[        R                  R                  R	                  U5      nUc	  [        US9eUR                  SL a3  SnU R                  b  U R                  R                  5       nU" U5      nU$ U=(       d    U R                  n	[        USS5      SL a  US   n
US   nU
R                  U5      n	US	 SnU	b  U	R                  5       nXS'   UR                  (       a3  U R                  c  [        R                  R!                  5       eX%S'   XS	'   U" S
0 UD6nU$ )aA  
Get an auth instance which can be used to sign a request
using the given signature version.

:type signing_name: string
:param signing_name: Service signing name. This is usually the
                     same as the service name, but can differ. E.g.
                     ``emr`` vs. ``elasticmapreduce``.

:type region_name: string
:param region_name: Name of the service region, e.g. ``us-east-1``

:type signature_version: string
:param signature_version: Signature name like ``v4``.

:rtype: :py:class:`~botocore.auth.BaseSigner`
:return: Auth instance to sign a request.
Nr>   TREQUIRES_IDENTITY_CACHEr;   r<   r   r   service_namer?   )r   rD   rN   AUTH_TYPE_MAPSrF   r   REQUIRES_TOKENr   get_frozen_tokenr   getattrget_credentialsget_frozen_credentialsREQUIRES_REGIONr   
exceptionsNoRegionError)r   r   r   r   r:   r1   clsfrozen_tokenrN   r   rR   keyfrozen_credentialss                r"   rH   RequestSigner.get_auth_instance   sH   4 $ $ 7 7mm**../@A;."3  %L+#//@@B|$DK)>T->->3148D@+,E%C//4K{# ""!,!C!C!E 2}  ())7799$/=!%1>"}V}r%   c                 |    [        U5      nU R                  UUUSUU5        UR                  5         UR                  $ )a]  Generates a presigned url

:type request_dict: dict
:param request_dict: The prepared request dictionary returned by
    ``botocore.awsrequest.prepare_request_dict()``

:type operation_name: str
:param operation_name: The operation being signed.

:type expires_in: int
:param expires_in: The number of seconds the presigned url is valid
    for. By default it expires in an hour (3600 seconds)

:type region_name: string
:param region_name: The region name to sign the presigned url.

:type signing_name: str
:param signing_name: The name to use for the service when signing.

:returns: The presigned url
rV   )r   r.   prepareurl)r   request_dictr/   rK   r   r   r0   s          r"   generate_presigned_url$RequestSigner.generate_presigned_url?  sB    : (5			
 	{{r%   )r   r   r   r   r   r   r   r   NN)Nr=   NN)  NN)__name__
__module____qualname____firstlineno____doc__r#   propertyr   r   r   r2   r.   rG   r@   rH   get_authrt   __static_attributes__r?   r%   r"   r   r   !   s     T ;( ! ! ' ' " "2 Z#x(.!h  ?D !H (r%   r   c                   @    \ rS rSrSrS rS
S jrS r S
S jrS r	S	r
g)CloudFrontSignerij  a  A signer to create a signed CloudFront URL.

First you create a cloudfront signer based on a normalized RSA signer::

    import rsa
    def rsa_signer(message):
        private_key = open('private_key.pem', 'r').read()
        return rsa.sign(
            message,
            rsa.PrivateKey.load_pkcs1(private_key.encode('utf8')),
            'SHA-1')  # CloudFront requires SHA-1 hash
    cf_signer = CloudFrontSigner(key_id, rsa_signer)

To sign with a canned policy::

    signed_url = cf_signer.generate_signed_url(
        url, date_less_than=datetime(2015, 12, 1))

To sign with a custom policy::

    signed_url = cf_signer.generate_signed_url(url, policy=my_policy)
c                     Xl         X l        g)aV  Create a CloudFrontSigner.

:type key_id: str
:param key_id: The CloudFront Key Pair ID

:type rsa_signer: callable
:param rsa_signer: An RSA signer.
       Its only input parameter will be the message to be signed,
       and its output will be the signed content as a binary string.
       The hash algorithm needed by CloudFront is SHA-1.
Nkey_id
rsa_signer)r   r   r   s      r"   r#   CloudFrontSigner.__init__  s     $r%   Nc                 .   USL=(       a    USLnUSL =(       a    USL nU(       d  U(       a  Sn[        U5      eUb  U R                  X5      n[        U[        5      (       a  UR	                  S5      nUb  S[        [        U5      5       3/nO$SU R                  U5      R                  S5       3/nU R                  U5      nUR                  SU R                  U5      R                  S5       3SU R                   3/5        U R                  X5      $ )a\  Creates a signed CloudFront URL based on given parameters.

:type url: str
:param url: The URL of the protected object

:type date_less_than: datetime
:param date_less_than: The URL will expire after that date and time

:type policy: str
:param policy: The custom policy, possibly built by self.build_policy()

:rtype: str
:return: The signed URL.
Nz=Need to provide either date_less_than or policy, but not bothutf8zExpires=zPolicy=z
Signature=zKey-Pair-Id=)
ValueErrorbuild_policy
isinstancestrencodeintr
   _url_b64encodedecoder   extendr   
_build_url)	r   rr   date_less_thanpolicyboth_args_suppliedneither_arg_suppliedrO   params	signatures	            r"   rt   'CloudFrontSigner.generate_presigned_url  s    ,47NF$<N-5H&D.!5OAQ-%&&s;Ffc""]]6*F% %7%G!H IJKF 3 3F ; B B6 JKLMFOOF+	T00;BB6JKLt{{m,	
 s++r%   c                 B    SU;   a  SOSnX-   SR                  U5      -   $ )N?&)join)r   base_urlextra_params	separators       r"   r   CloudFrontSigner._build_url  s&    (?C	#chh|&<<<r%   c                    [        [        U5      5      n[        SSU005      nU(       a  SU;  a  US-  nSU0US'   U(       a  [        [        U5      5      nSU0US'   SU4S	U4/nS
[        U5      /0n[        R                  " USS9$ )a  A helper to build policy.

:type resource: str
:param resource: The URL or the stream filename of the protected object

:type date_less_than: datetime
:param date_less_than: The URL will expire after the time has passed

:type date_greater_than: datetime
:param date_greater_than: The URL will not be valid until this time

:type ip_address: str
:param ip_address: Use 'x.x.x.x' for an IP, or 'x.x.x.x/x' for a subnet

:rtype: str
:return: The policy in a compact string.
DateLessThanzAWS:EpochTime/z/32zAWS:SourceIp	IpAddressDateGreaterThanResource	Condition	Statement),:)
separators)r   r
   r   jsondumps)	r   resourcer   date_greater_than
ip_addressmoment	conditionordered_payloadcustom_policys	            r"   r   CloudFrontSigner.build_policy  s    : '78/61J KL	*$e#
&4j%AIk"+,=>?F,;V+DI'(&1K3KL${?'C&DEzz-J??r%   c                     [         R                  " U5      R                  SS5      R                  SS5      R                  SS5      $ )N   +   -   =   _   /   ~)base64	b64encodereplace)r   datas     r"   r   CloudFrontSigner._url_b64encode  s;     T"WT4 WT4 WT4 		
r%   r   rv   )rx   ry   rz   r{   r|   r#   rt   r   r   r   r   r?   r%   r"   r   r   j  s*    .%$,L=
 LP(@T
r%   r   c                     [         U S'   g )Ngenerate_db_auth_token)r   class_attributesr1   s     r"   add_generate_db_auth_tokenr         1G-.r%   c                     UnUc  U R                   R                  nSUS.nSS0 USS.nSnU U S	U 3n	[        Xy5        U R                  R	                  SUUS
SS9n
U
[        U5      S $ )a  Generates an auth token used to connect to a db with IAM credentials.

:type DBHostname: str
:param DBHostname: The hostname of the database to connect to.

:type Port: int
:param Port: The port number the database is listening on.

:type DBUsername: str
:param DBUsername: The username to log in as.

:type Region: str
:param Region: The region the database is in. If None, the client
    region will be used.

:return: A presigned url which can be used as an auth token.
Nconnect)ActionDBUserr   rW   GET)url_pathquery_stringheadersbodymethodzhttps://r   i  zrds-db)r/   rs   r   rK   r   )metar   r   _request_signerrt   len)r   
DBHostnamePort
DBUsernameRegionr9   r   rs   schemeendpoint_urlpresigned_urls              r"   r   r     s    $ F~&& F L FXj\4&1L4((?? ! @ M V''r%   c                   ,    \ rS rSrS r    SS jrSrg)S3PostPresigneri*  c                     Xl         g r   r   )r   r6   s     r"   r#   S3PostPresigner.__init__+  s    -r%   Nc                    Uc  0 nUc  / n0 n[         R                   R                  5       nU[         R                  " US9-   nUR                  [        R
                  R                  5      US'   / US'   U H  n	US   R                  U	5        M     [        U5      n
X*R                  S'   XjR                  S'   U R                  R                  SXS5        U
R                  US.$ )	ae  Generates the url and the form fields used for a presigned s3 post

:type request_dict: dict
:param request_dict: The prepared request dictionary returned by
    ``botocore.awsrequest.prepare_request_dict()``

:type fields: dict
:param fields: A dictionary of prefilled form fields to build on top
    of.

:type conditions: list
:param conditions: A list of conditions to include in the policy. Each
    element can be either a list or a structure. For example:

    .. code:: python

        [
            {"acl": "public-read"},
            {"bucket": "amzn-s3-demo-bucket"},
            ["starts-with", "$key", "mykey"]
        ]

:type expires_in: int
:param expires_in: The number of seconds the presigned post is valid
    for.

:type region_name: string
:param region_name: The region name to sign the presigned post to.

:rtype: dict
:returns: A dictionary with two elements: ``url`` and ``fields``.
    Url is the url to post to. Fields is a dictionary filled with
    the form fields and respective values to use when submitting the
    post. For example:

    .. code:: python

        {
            'url': 'https://amzn-s3-demo-bucket.s3.amazonaws.com',
            'fields': {
                'acl': 'public-read',
                'key': 'mykey',
                'signature': 'mysignature',
                'policy': 'mybase64 encoded policy'
            }
        }
)seconds
expiration
conditionszs3-presign-post-fieldszs3-presign-post-policy	PutObjectrU   )rr   fields)datetimeutcnow	timedeltastrftimerD   rN   ISO8601appendr   rA   r   r.   rr   )r   rs   r   r   rK   r   r   datetime_nowexpire_dater   r0   s              r"   generate_presigned_post'S3PostPresigner.generate_presigned_post.  s    n >FJ   ((//1"X%7%7
%KK*33HMM4I4IJ|  "|#I< ''	2 $ (54:014:01!!~	
 {{f55r%   r   )NNrw   N)rx   ry   rz   r{   r#   r   r   r?   r%   r"   r   r   *  s    . S6r%   r   c                     [         U S'   g )Nrt   )rt   r   s     r"   add_generate_presigned_urlr     r   r%   c           	         UnUnUc  0 nUnUnS[        U 5      S.n	U R                  n
 U R                  U   nU R
                  R                  R                  U5      nU R                  UUU	S9n[        R                  " UR                  SS5      5      nU R                  UUU	U(       + S9u  nnnU R                  UUUU	USS	9nUb  UUS
'   U
R                  UUUS9$ ! [         a
    [	        US9ef = f)aD  Generate a presigned url given a client, its method, and arguments

:type ClientMethod: string
:param ClientMethod: The client method to presign for

:type Params: dict
:param Params: The parameters normally passed to
    ``ClientMethod``.

:type ExpiresIn: int
:param ExpiresIn: The number of seconds the presigned url is valid
    for. By default it expires in an hour (3600 seconds)

:type HttpMethod: string
:param HttpMethod: The http method to use on the generated url. By
    default, the http method is whatever is used in the method's model.

:returns: The presigned url
Tis_presign_requestuse_global_endpoint)method_name
api_paramsoperation_modelrA   BucketrW   ignore_signing_regionFr   r   r   rA   r   set_user_agent_headerr   )rs   rK   r/   )_should_use_global_endpointr   _PY_TO_OP_NAMEKeyErrorr   r   service_modelr   _emit_api_paramsr	   is_arnrF   _resolve_endpoint_ruleset_convert_to_request_dictrt   )r   ClientMethodParams	ExpiresIn
HttpMethodclient_methodr   rK   http_methodrA   r6   r/   r   bucket_is_arnr   additional_headers
propertiesrs   s                     r"   rt   rt     s]   , !MF~JK":4@G
 ))NB,,]; ii--==nMO""' # F
 $$VZZ"%=>M
 	&&#00	 	' 		 00'!"# 1 L !,X 00!% 1  G  B&=AABs   C C0c                     [         U S'   g )Nr   )r   r   s     r"   add_generate_presigned_postr    s    2I./r%   c           	         UnUnUnUn	Un
Uc  0 nOUR                  5       nU	c  / n	S[        U 5      S.n[        U R                  5      nU R                  R
                  R                  S5      nU R                  SU0UUS9n[        R                  " UR                  SS5      5      nU R                  UUUU(       + S9u  nnnU R                  UUUUUS	S
9nU	R                  SU05        UR                  S5      (       a"  U	R                  SSUS[        S5      *  /5        OU	R                  SU05        XxS'   UR!                  UUU	U
S9$ )a	  Builds the url and the form fields used for a presigned s3 post

:type Bucket: string
:param Bucket: The name of the bucket to presign the post to. Note that
    bucket related conditions should not be included in the
    ``conditions`` parameter.

:type Key: string
:param Key: Key name, optionally add ${filename} to the end to
    attach the submitted filename. Note that key related conditions and
    fields are filled out for you and should not be included in the
    ``Fields`` or ``Conditions`` parameter.

:type Fields: dict
:param Fields: A dictionary of prefilled form fields to build on top
    of. Elements that may be included are acl, Cache-Control,
    Content-Type, Content-Disposition, Content-Encoding, Expires,
    success_action_redirect, redirect, success_action_status,
    and x-amz-meta-.

    Note that if a particular element is included in the fields
    dictionary it will not be automatically added to the conditions
    list. You must specify a condition for the element as well.

:type Conditions: list
:param Conditions: A list of conditions to include in the policy. Each
    element can be either a list or a structure. For example:

    .. code:: python

        [
            {"acl": "public-read"},
            ["content-length-range", 2, 5],
            ["starts-with", "$success_action_redirect", ""]
        ]

    Conditions that are included may pertain to acl,
    content-length-range, Cache-Control, Content-Type,
    Content-Disposition, Content-Encoding, Expires,
    success_action_redirect, redirect, success_action_status,
    and/or x-amz-meta-.

    Note that if you include a condition, you must specify
    a valid value in the fields dictionary as well. A value will
    not be added automatically to the fields dictionary based on the
    conditions.

:type ExpiresIn: int
:param ExpiresIn: The number of seconds the presigned post
    is valid for.

:rtype: dict
:returns: A dictionary with two elements: ``url`` and ``fields``.
    Url is the url to post to. Fields is a dictionary filled with
    the form fields and respective values to use when submitting the
    post. For example:

    .. code:: python

        {
            'url': 'https://amzn-s3-demo-bucket.s3.amazonaws.com',
            'fields': {
                'acl': 'public-read',
                'key': 'mykey',
                'signature': 'mysignature',
                'policy': 'mybase64 encoded policy'
            }
        }
NTr   CreateBucketr   r   rW   r   Fr   bucketz${filename}zstarts-withz$keyrm   )rs   r   r   rK   )copyr  r   r   r   r  r   r  r	   r  rF   r  r  r   rY   r   r   )r   r   KeyFields
Conditionsr  r  rm   r   r   rK   rA   post_presignerr   r   r  r   r  r  rs   s                       r"   r   r     s   P F
CFJJ~
 #:4@G
 %T%9%9:N ii--==nMO""f%' # F
 $$VZZ"%=>M
 	&&#00	 	' 		 00'!"# 1 L x() ||M""=&#6K]9K8K2LMN5#,' 5M11!	 2  r%   c                 X   U R                   R                  S:w  a  gU R                   R                  R                  nU(       ah  UR	                  SS5      (       a  gUR	                  S5      S:X  a%  U R                   R                  R
                  S:X  a  gUR	                  S5      S:X  a  gg	)
NawsFuse_dualstack_endpointus_east_1_regional_endpointregionalz	us-east-1addressing_stylevirtualT)r   	partitionconfigs3rF   r   )client	s3_configs     r"   r  r  j  s    {{%""%%I==1599MM78JF""..+===+,	9r%   r   )Nrw   N)NNrw   )r   r   r   r   rD   botocore.authbotocore.awsrequestr   r   botocore.compatr   botocore.exceptionsr   r   r   botocore.utilsr	   r
   r   r   r   r   r   r   r   rt   r  r   r  r?   r%   r"   <module>r-     s          K ' 
 9 'F FR
C
 C
LH3(lW6 W6tH
 AEL^J
 @DL^r%   