
    IiX                         S r 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  SSKJrJrJrJr  SSKJr  SSKJr  SSKJrJrJr   " S S	\5      r " S
 S\5      r " S S\5      rg! \	 a    SSK
r NPf = f)zn
Provides AWS4Auth class for handling Amazon Web Services version 4
authentication with the Requests module.

    N)urlparseparse_qsquoteunquote)AuthBase   )AWS4SigningKey)DateMismatchErrorNoSecretKeyErrorDateFormatErrorc                       \ rS rSrSr1 SkrS r  SS jrS rS r	\
S	 5       r\S
 5       rS r\S 5       rS r\
SS j5       r\S 5       rS r\S 5       r\S 5       rSrg)AWS4Auth   a  
Requests authentication class providing AWS version 4 authentication for
HTTP requests. Implements header-based authentication only, GET URL
parameter and POST parameter authentication are not supported.

Provides authentication for regions and services listed at:
http://docs.aws.amazon.com/general/latest/gr/rande.html

The following services do not support AWS auth version 4 and are not usable
with this package:
    * Simple Email Service (SES)' - AWS auth v3 only
    * Simple Workflow Service - AWS auth v3 only
    * Import/Export - AWS auth v2 only
    * SimpleDB - AWS auth V2 only
    * DevPay - AWS auth v1 only
    * Mechanical Turk - has own signing mechanism

You can reuse AWS4Auth instances to sign as many requests as you need.

Basic usage
-----------
>>> import requests
>>> from requests_aws4auth import AWS4Auth
>>> auth = AWS4Auth('<ACCESS ID>', '<ACCESS KEY>', 'eu-west-1', 's3')
>>> endpoint = 'http://s3-eu-west-1.amazonaws.com'
>>> response = requests.get(endpoint, auth=auth)
>>> response.text
<?xml version="1.0" encoding="UTF-8"?>
    <ListAllMyBucketsResult xmlns="http://s3.amazonaws.com/doc/2006-03-01">
        <Owner>
        <ID>bcaf1ffd86f461ca5fb16fd081034f</ID>
        <DisplayName>webfile</DisplayName>
        ...

This example lists your buckets in the eu-west-1 region of the Amazon S3
service.

STS Temporary Credentials
-------------------------
>>> from requests_aws4auth import AWS4Auth
>>> auth = AWS4Auth('<ACCESS ID>', '<ACCESS KEY>', 'eu-west-1', 's3',
                    session_token='<SESSION TOKEN>')
...

This example shows how to construct an AWS4Auth object for use with STS
temporary credentials. The ``x-amz-security-token`` header is added with
the session token. Temporary credential timeouts are not managed -- in
case the temporary credentials expire, they need to be re-generated and
the AWS4Auth object re-constructed with the new credentials.

Dynamic STS Credentials using botocore RefreshableCredentials
-------------------------------------------------------------
>>> from requests_aws4auth import AWS4Auth
>>> from botocore.session import Session
>>> credentials = Session().get_credentials()
>>> auth = AWS4Auth(region='eu-west-1', service='es',
                    refreshable_credentials=credentials)
...

This example shows how to construct an AWS4Auth instance with
automatically refreshing credentials, suitable for long-running
applications using AWS IAM assume-role.
The RefreshableCredentials instance is used to generate valid static
credentials per-request, eliminating the need to recreate the AWS4Auth
instance when temporary credentials expire.

Date handling
-------------
If an HTTP request to be authenticated contains a Date or X-Amz-Date
header, AWS will only accept authorisation if the date in the header
matches the scope date of the signing key (see
http://docs.aws.amazon.com/general/latest/gr/sigv4-date-handling.html).

From version 0.8 of requests-aws4auth, if the header date does not match
the scope date, the AWS4Auth class will automatically regenerate its
signing key, using the same scope parameters as the previous key except for
the date, which will be changed to match the request date. (If a request
does not include a date, the current date is added to the request in an
X-Amz-Date header).

The new behaviour from version 0.8 has implications for thread safety and
secret key security, see the "Automatic key regeneration", "Secret key
storage" and "Multithreading" sections below.

This also means that AWS4Auth is now attempting to parse and extract dates
from the values in X-Amz-Date and Date headers. Supported date formats are:

    * RFC 7231 (e.g. Mon, 09 Sep 2011 23:36:00 GMT)
    * RFC 850 (e.g. Sunday, 06-Nov-94 08:49:37 GMT)
    * C time (e.g. Wed Dec 4 00:00:00 2002)
    * Amz-Date format (e.g. 20090325T010101Z)
    * ISO 8601 / RFC 3339 (e.g. 2009-03-25T10:11:12.13-01:00)

If either header is present but AWS4Auth cannot extract a date because all
present date headers are in an unrecognisable format, AWS4Auth will delete
any X-Amz-Date and Date headers present and replace with a single
X-Amz-Date header containing the current date. This behaviour can be
modified using the 'raise_invalid_date' keyword argument of the AWS4Auth
constructor.

Automatic key regeneration
--------------------------
If you do not want the signing key to be automatically regenerated when a
mismatch between the request date and the scope date is encountered, use
the alternative StrictAWS4Auth class, which is identical to AWS4Auth except
that upon encountering a date mismatch it just raises a DateMismatchError.
You can also use the PassiveAWS4Auth class, which mimics the AWS4Auth
behaviour prior to version 0.8 and just signs and sends the request,
whether the date matches or not. In this case it is up to the calling code
to handle an authentication failure response from AWS caused by a date
mismatch.

Secret key storage
------------------
To allow automatic key regeneration, the secret key is stored in the
AWS4Auth instance, in the signing key object. If you do not want this to
occur, instantiate the instance using an AWS4Signing key which was created
with the store_secret_key parameter set to False:

>>> sig_key = AWS4SigningKey(secret_key, region, service, date, False)
>>> auth = StrictAWS4Auth(access_id, sig_key)

The AWS4Auth class will then raise a NoSecretKeyError when it attempts to
regenerate its key. A slightly more conceptually elegant way to handle this
is to use the alternative StrictAWS4Auth class, again instantiating it with
an AWS4SigningKey instance created with store_secret_key = False.

Multithreading
--------------
If you share AWS4Auth (or even StrictAWS4Auth) instances between threads
you are likely to encounter problems. Because AWS4Auth instances may
unpredictably regenerate their signing key as part of signing a request,
threads using the same instance may find the key changed by another thread
halfway through the signing process, which may result in undefined
behaviour.

It may be possible to rig up a workable instance sharing mechanism using
locking primitives and the StrictAWS4Auth class, however this poor author
can't think of a scenario which works safely yet doesn't suffer from at
some point blocking all threads for at least the duration of an HTTP
request, which could be several seconds. If several requests come in in
close succession which all require key regenerations then the system could
be forced into serial operation for quite a length of time.

In short, it's best to create a thread-local instance of AWS4Auth for each
thread that needs to do authentication.

Class attributes
----------------
AWS4Auth.access_id   -- the access ID supplied to the instance
AWS4Auth.region      -- the AWS region for the instance
AWS4Auth.service     -- the endpoint code for the service for this instance
AWS4Auth.date        -- the date the instance is valid for
AWS4Auth.signing_key -- instance of AWS4SigningKey used for this instance,
                        either generated from the supplied parameters or
                        supplied directly on the command line

>   datehostx-amz-*content-typec                 <   SU l         UR                  SS5      U l        U R                  (       a  UR                  SS5      U l        U R                  (       d  [	        S5      eUR                  SS5      U l        U R
                  (       d  [	        S5      eUR                  SS5      U l        U R                  R                  S5        GO>[        U5      nUS	;  a  S
R                  U5      n[	        U5      eUS   U l        [        US   [        5      (       ab  US:X  a\  US   U l         U R                   R
                  U l        U R                   R                  U l        U R                   R                  U l        OKUS;   a;  US   nUS   U l        US   U l        US:X  a  US   OSU l        U R                  US9  O
[	        5       eUR                  S5      U l        U R                  (       a  U R                  R                  S5        UR                  SS5      nUS;   a  X`l        O[#        S5      e[%        U R                  5      U l        SU;   a5  [        US   [(        R*                  5      (       a  [%        US   5      U l        [,        R.                  " U 5        g)a[  
AWS4Auth instances can be created by supplying key scope parameters
directly or by using an AWS4SigningKey instance:

>>> auth = AWS4Auth(access_id, secret_key, region, service
...                 [, date][, raise_invalid_date=False][, session_token=None])

  or

>>> auth = AWS4Auth(access_id, signing_key[, raise_invalid_date=False])

  or using auto-refreshed STS temporary creds via botocore RefreshableCredentials
  (useful for long-running processes):

>>> auth = AWS4Auth(refreshable_credentials=botocore.session.Session().get_credentials(),
...                 region='eu-west-1', service='es')

access_id   -- This is your AWS access ID
secret_key  -- This is your AWS secret access key
region      -- The region you're connecting to, as per the list at
               http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
               e.g. us-east-1. For services which don't require a region
               (e.g. IAM), use us-east-1.
               Must be supplied as a keyword argument iff refreshable_credentials
               is set.
service     -- The name of the service you're connecting to, as per
               endpoints at:
               http://docs.aws.amazon.com/general/latest/gr/rande.html
               e.g. elasticbeanstalk.
               Must be supplied as a keyword argument iff refreshable_credentials
               is set.
date        -- Date this instance is valid for. 8-digit date as str of the
               form YYYYMMDD. Key is only valid for requests with a
               Date or X-Amz-Date header matching this date. If date is
               not supplied the current date is used.
signing_key -- An AWS4SigningKey instance.
raise_invalid_date
            -- Must be supplied as keyword argument. AWS4Auth tries to
               parse a date from the X-Amz-Date and Date headers of the
               request, first trying X-Amz-Date, and then Date if
               X-Amz-Date is not present or is in an unrecognised
               format. If one or both of the two headers are present
               yet neither are in a format which AWS4Auth recognises
               then it will remove both headers and replace with a new
               X-Amz-Date header using the current date.

               If this behaviour is not wanted, set the
               raise_invalid_date keyword argument to True, and
               instead an InvalidDateError will be raised when neither
               date is recognised. If neither header is present at all
               then an X-Amz-Date header will still be added containing
               the current date.

               See the AWS4Auth class docstring for supported date
               formats.
session_token
            -- Must be supplied as keyword argument. If session_token
               is set, then it is used for the x-amz-security-token
               header, for use with STS temporary credentials.
refreshable_credentials
            -- A botocore.credentials.RefreshableCredentials instance.
               Must be supplied as keyword argument. This instance is
               used to generate valid per-request static credentials,
               without needing to re-generate the AWS4Auth instance.                       
               If refreshable_credentials is set, the following arguments
               are ignored: access_id, secret_key, signing_key,
               session_token.

Nrefreshable_credentialsservicezOservice must be provided as keyword argument when using refreshable_credentialsregionzNregion must be provided as keyword argument when using refreshable_credentialsr   x-amz-security-token)         z.AWS4Auth() takes 2, 4 or 5 arguments, {} givenr   r   r   )r   r      r   r   
secret_keysession_tokenraise_invalid_dateF)TFz?raise_invalid_date must be True or False in AWS4Auth.__init__()include_hdrs)signing_keygetr   r   	TypeErrorr   r   default_include_headersaddlenformat	access_id
isinstancer	   regenerate_signing_keyr   r    
ValueErrorsetr!   abcIterabler   __init__)selfargskwargslmsgr   r    s          @/venv/lib/python3.13/site-packages/requests_aws4auth/aws4auth.pyr0   AWS4Auth.__init__   s,   L  '-zz2KT'R$''!::i6DL<< qrr **Xt4DK;; pqq

640DI((,,-CDD	A	!FMMaPn$!!WDN$q'>22qAv#'7 "..55#//77 ,,11	f!!W
"1g#Aw'(AvDG4	++z+Bk!!'O!<D!!,,001GH#ZZ(<eD.&8#^__ < <= V#
6.3I3<<(X(X #F>$: ;D$    Nc                    Uc*  U R                   b  U R                   R                  c  [        eU=(       d    U R                   R                  nU=(       d    U R                  nU=(       d    U R                  nU=(       d    U R
                  nU R                   c  SnOU R                   R                  n[        XX4U5      U l         X l        X0l        U R                   R
                  U l        g)a  
Regenerate the signing key for this instance. Store the new key in
signing_key property.

Take scope elements of the new key from the equivalent properties
(region, service, date) of the current AWS4Auth instance. Scope
elements can be overridden for the new key by supplying arguments to
this function. If overrides are supplied update the current AWS4Auth
instance's equivalent properties to match the new values.

If secret_key is not specified use the value of the secret_key property
of the current AWS4Auth instance's signing key. If the existing signing
key is not storing its secret key (i.e. store_secret_key was set to
False at instantiation) then raise a NoSecretKeyError and do not
regenerate the key. In order to regenerate a key which is not storing
its secret key, secret_key must be supplied to this function.

Use the value of the existing key's store_secret_key property when
generating the new key. If there is no existing key, then default
to setting store_secret_key to True for new key.

NT)r"   r   r   r   r   r   store_secret_keyr	   )r1   r   r   r   r   r:   s         r6   r+   AWS4Auth.regenerate_signing_key8  s    0 4#3#3#;t?O?O?Z?Z?b"">4#3#3#>#>
&4;;)T\\ tyy###//@@)*g*:< $$))	r8   c                 d   U R                   (       a  U R                  5         U R                  U5      nUc  SUR                  ;   a  UR                  S	 SUR                  ;   a  UR                  S	 [        R                  R                  5       nUR                  5       nUR                  S5      UR                  S'   UR                  S5      nX@R                  :w  a  U R                  U5        [        US5      (       ay  UR                  bl  [        UR                  S5      (       a  UR                  R                  5       Ul
        U R                  U5        [        R                  " UR                  5      nOU[        US5      (       a.  UR                  b!  [        R                  " UR                  5      nO[        R                  " S5      nUR!                  5       UR                  S	'   U R"                  (       a  U R"                  UR                  S
'   U R%                  XR&                  5      nUu  pxU R)                  XU5      n	U R+                  XU R,                  R.                  5      n
U
R1                  S5      n
[2        R4                  " U R,                  R6                  U
[        R                  5      nUR!                  5       nSnUSR9                  U R:                  U R,                  R.                  5      -  nUSR9                  U5      -  nUSR9                  U5      -  nXR                  S'   U$ )a  
Interface used by Requests module to apply authentication to HTTP
requests.

Add x-amz-content-sha256 and Authorization headers to the request. Add
x-amz-date header to request if not already present and req does not
contain a Date header.

Check request date matches date in the current signing key. If not,
regenerate signing key to match request date.

If request body is not already encoded to bytes, encode to charset
specified in Content-Type header, or UTF-8 if not specified.

req -- Requests PreparedRequest object

r   
x-amz-datez%Y%m%dT%H%M%SZ%Y%m%dbodyreadcontentr8   x-amz-content-sha256r   utf-8zAWS4-HMAC-SHA256 zCredential={}/{}, zSignedHeaders={}, zSignature={}Authorization)r   refresh_credentialsget_request_dateheadersdatetimeutcnowr   strftimehandle_date_mismatchhasattrr?   r@   encode_bodyhashlibsha256rA   	hexdigestr   get_canonical_headersr!   get_canonical_requestget_sig_stringr"   scopeencodehmacnewkeyr(   r)   )r1   reqreq_datenowreq_scope_datecontent_hashresultcano_headerssigned_headerscano_req
sig_stringhshsigauth_strs                 r6   __call__AWS4Auth.__call__d  s   $ ''$$&((- $#++f*=s{{*L0I##**,CxxzH(+5E(FCKK%!**84YY&%%c* 3CHH$8sxx((88==?S!">>#((3LS)$$)@">>#++6L">>#.L.:.D.D.F*+262D2DCKK./ ++C1B1BC'-$--c.<>((8H8H8N8NO
&&w/
hht''++ZHmmo&(//040@0@0F0FH 	H(//??N))#..'/O$
r8   c                     U R                   R                  5       nUR                  U l        UR                  U l        U R                  UR                  S9  g )Nr   )r   get_frozen_credentials
access_keyr)   tokenr   r+   r   )r1   temporary_credss     r6   rE   AWS4Auth.refresh_credentials  sH    66MMO(33,22##/I/I#Jr8   c                     SnS Hc  nX1R                   ;  a  M   U R                  UR                   U   5      n [        R                  R	                  US5      R                  5       n  U$    U$ ! [         a     Mv  f = f! [         a     M  f = f)a  
Try to pull a date from the request by looking first at the
x-amz-date header, and if that's not present then the Date header.

Return a datetime.date object, or None if neither date header
is found or is in a recognisable format.

req -- a requests PreparedRequest object

N)r=   r   z%Y-%m-%d)rG   
parse_dater   rH   strptimer   r,   )clsrY   r   headerdate_strs        r6   rF   AWS4Auth.get_request_date  s     ,F[[(>>#++f*=>((11(JGLLN  -  #   s"   A..A?.
A<;A<?
BBc                    ^ / SQmU4S jU4S jU4S jS S S.nSnUR                  5        H,  u  p4[        R                  " X05      nU(       d  M$  U" U5      n  O   Uc  [        eU$ )	a  
Check if date_str is in a recognised format and return an ISO
yyyy-mm-dd format version if so. Raise DateFormatError if not.

Recognised formats are:
* RFC 7231 (e.g. Mon, 09 Sep 2011 23:36:00 GMT)
* RFC 850 (e.g. Sunday, 06-Nov-94 08:49:37 GMT)
* C time (e.g. Wed Dec 4 00:00:00 2002)
* Amz-Date format (e.g. 20090325T010101Z)
* ISO 8601 / RFC 3339 (e.g. 2009-03-25T10:11:12.13-01:00)

date_str -- Str containing a date and optional time

)janfebmaraprmayjunjulaugsepoctnovdecc                    > SR                  U R                  S5      TR                  U R                  S5      R                  5       5      S-   U R                  S5      5      $ )Nz{}-{:02d}-{}r   r   r   )r(   groupindexlowermmonthss    r6   <lambda>%AWS4Auth.parse_date.<locals>.<lambda>  sH    .//GGAJLL!1!1!34q8GGAJ r8   c           	      *  > SR                  [        [        R                  R	                  5       R
                  5      S S U R                  S5      TR                  U R                  S5      R                  5       5      S-   U R                  S5      5      $ )Nz{}{}-{:02d}-{}r   r   r   )	r(   strrH   r   todayyearr   r   r   r   s    r6   r   r     sk    *11++-223BQ7GGAJLL!1!1!34q8GGAJ	 r8   c           	         > SR                  U R                  S5      TR                  U R                  S5      R                  5       5      S-   [	        U R                  S5      5      5      $ )Nz{}-{:02d}-{:02d}r   r   r   )r(   r   r   r   intr   s    r6   r   r     sM    ,33GGAJLL!1!1!34q8
O%r8   c                 <    SR                   " U R                  5       6 $ )Nz{}-{}-{})r(   groupsr   s    r6   r   r     s    *++QXXZ8r8   c                 $    U R                  S5      $ )Nr   )r   r   s    r6   r   r     s    !''!*r8   )z)^(?:\w{3}, )?(\d{2}) (\w{3}) (\d{4})\D.*$z%^\w+day, (\d{2})-(\w{3})-(\d{2})\D.*$z3^\w{3} (\w{3}) (\d{1,2}) \d{2}:\d{2}:\d{2} (\d{4})$z^(\d{4})(\d{2})(\d{2})T\d{6}Z$z ^(\d{4}-\d{2}-\d{2})(?:[Tt].*)?$N)itemsresearchr   )rs   formatsout_dateregexxformr   r   s         @r6   ro   AWS4Auth.parse_date  su     .
  % 9 %5
: #MMOLE		%*Aq 8	 ,
 !!Or8   c                 f    U R                  U5      nUR                  S5      nU R                  US9  g)z
Handle a request whose date doesn't match the signing key scope date.

This AWS4Auth class implementation regenerates the signing key. See
StrictAWS4Auth class if you would prefer an exception to be raised.

req -- a requests prepared request object

r>   )r   N)rF   rJ   r+   )r1   rY   req_datetimenew_key_dates       r6   rK   AWS4Auth.handle_date_mismatch  s5     ,,S1#,,X6###6r8   c                    [        U R                  [        5      (       a  U R                  R	                  SS5      R                  S5      n[        U5      S:X  a9  Uu  p#UR                  S5      S   nU R                  R                  U5      U l        gUS   nUS:X  d  S	U;   a   U R                  R                  5       U l        gU R                  R                  S
5      U l        US-   U R                  S'   gg)a  
Encode body of request to bytes and update content-type if required.

If the body of req is Unicode then encode to the charset found in
content-type header if present, otherwise UTF-8, or ASCII if
content-type is application/x-www-form-urlencoded. If encoding to UTF-8
then add charset to content-type. Modifies req directly, does not
return a modified copy.

req -- Requests PreparedRequest object

r   z
text/plain;r   =r   r   z!application/x-www-form-urlencodedx-amz-rC   z; charset=utf-8N)r*   r?   r   rG   r#   splitr'   rU   )rY   r   ctcss       r6   rM   AWS4Auth.encode_body  s     chh$$KKOONLAGGLE5zQXXc]1%88??2.1X==R"xx0CH"xxw7CH247H2HCKK/ %r8   c                 j   [        UR                  5      n[        U5      nU R                  UR                  5      nUR                  SS5      n[        U5      S:X  a  US   OSnU R                  U5      nUR                  S   n	UR                  R                  5       XhUX9/n
SR                  U
5      nU$ )a  
Create the AWS authentication Canonical Request string.

req            -- Requests/Httpx PreparedRequest object. Should already
                  include an x-amz-content-sha256 header
cano_headers   -- Canonical Headers section of Canonical Request, as
                  returned by get_canonical_headers()
signed_headers -- Signed Headers, as returned by
                  get_canonical_headers()

?r   r    rB   
)r   urlr   amz_cano_pathpathr   r'   amz_cano_querystringrG   methodupperjoin)r1   rY   r_   r`   raw_urlr   r   r   qspayload_hash	req_partsra   s               r6   rR   AWS4Auth.get_canonical_request-  s     cgg,w!!#((+ c1%UqU1Xb&&r*{{#9:ZZ%%'<#3	99Y'r8   c                 X   Uc  U R                   nU Vs/ s H  o3R                  5       PM     nnUR                  R                  5       nSU;  a=  [	        [        UR                  5      5      R                  R                  S5      S   US'   0 nUR                  5        H  u  pgUR                  5       R                  5       nU R                  U5      R                  5       nXb;   d.  SU;   d(  SU;   d  MU  UR                  S5      (       d  Mm  US:X  a  Mu  UR                  U/ 5      nUR                  U5        M     Sn	/ n
[        U5       HF  nXV   nS	R!                  [        U5      5      nU	S
R#                  Xg5      -  n	U
R                  U5        MH     SR!                  U
5      nX4$ s  snf )a  
Generate the Canonical Headers section of the Canonical Request.

Return the Canonical Headers and the Signed Headers strs as a tuple
(canonical_headers, signed_headers).

req     -- Requests PreparedRequest object
include -- List of headers to include in the canonical and signed
           headers. It's primarily included to allow testing against
           specific examples from Amazon. If omitted or None it
           includes host, content-type and any header starting 'x-amz-'
           except for x-amz-client context, which appears to break
           mobile analytics auth if included. Except for the
           x-amz-client-context exclusion these defaults are per the
           AWS documentation.

r   :r   *r   r   zx-amz-client-contextr   ,z{}:{}
r   )r%   r   rG   copyr   r   r   netlocr   r   stripamz_norm_whitespace
startswith
setdefaultappendsortedr   r(   )rq   rY   includexrG   cano_headers_dicthdrvalvalsr_   signed_headers_listr`   s               r6   rQ   AWS4Auth.get_canonical_headersG  s|   & ?11G&-.g779g.++""$  &s377|4;;AA#FqIGFO HC))+##%C))#.446C#.(S^^H-E-E#99(33C<C  (  +,C$)D((6$<(CI,,S66L&&s+	 -
 "56--= /s   F'c                     U R                   S   n[        R                  " UR                  5       5      nSX2UR	                  5       /nSR                  U5      nU$ )z
Generate the AWS4 auth string to sign for the request.

req      -- Requests PreparedRequest object. This should already
            include an x-amz-date header.
cano_req -- The Canonical Request, as returned by
            get_canonical_request()

r=   zAWS4-HMAC-SHA256r   )rG   rN   rO   rU   rP   r   )rY   ra   rT   amz_daterc   	sig_itemsrb   s          r6   rS   AWS4Auth.get_sig_string|  sM     ;;|,nnX__./'#--/J	YYy)
r8   c                    SnSnUnSU;   a  UR                  SS5      u  pC[        R                  " U5      n[        R                  " SSU5      nUR                  S5      (       a  UR                  S5      (       d  US-  nUnU R                  S;   a  [        U5      n[        XRS9nU(       a  SR                  XS45      nU$ )	z
Generate the canonical path as per AWS4 auth requirements.

Not documented anywhere, determined from aws4_testsuite examples,
problem reports and testing against the live services.

path -- request path

z/~r   r   r   z/+/)s3r   safe)
r   	posixpathnormpathr   subendswithr   r   r   r   )r1   r   
safe_charsr   
fixed_path	full_paths         r6   r   AWS4Auth.amz_cano_path  s     

*'--c15NJ''
3
VVD#z2
==j&9&9#&>&>#J	 <<>)	*I)5	)1Ir8   c           	         SnU R                  S5      S   n U R                  SS5      n 0 n[        U SS9R                  5        H+  u  p4[	        X1S9nU Vs/ s H  n[	        XQS9PM     nnXBU'   M-     / n[        U5       H:  nX#   n[        U5       H$  nUR                  S	R                  X5/5      5        M&     M<     S
R                  U5      n U $ s  snf )zu
Parse and format querystring as per AWS4 auth requirements.

Perform percent quoting as needed.

qs -- querystring

z-_.~ r   r   z%3BT)keep_blank_valuesr   r   &)r   replacer   r   r   r   r   r   )r   safe_qs_unresvdqs_itemsnamer   r   
qs_stringss          r6   r   AWS4Auth.amz_cano_querystring  s     !XXc]1ZZU#"2>DDFJD4D@DEE#4DE!TN G 
8$D>Dd|!!#((D;"78 $ % XXj!	 Fs   Cc                     [         R                  " SU 5      (       a$  SR                  [        R                  " U SS95      $ U $ )zS
Replace runs of whitespace with a single space.

Ignore text enclosed in quotes.

z\sr   F)posix)r   r   r   shlexr   )texts    r6   r   AWS4Auth.amz_norm_whitespace  s4     99UD!!88EKKE:;;r8   )	r)   r   r!   r    r   r   r   r   r"   )NNNNN)__name__
__module____qualname____firstlineno____doc__r%   r0   r+   rf   rE   classmethodrF   staticmethodro   rK   rM   rR   rQ   rS   r   r   r   __static_attributes__ r8   r6   r   r      s    ]| Jx t >B26**X@DK  8 7 7r7 I I64 2. 2.h   :  4 	 	r8   r   c                       \ rS rSrSrS rSrg)StrictAWS4Authi  a  
Instances of this subclass will not automatically regenerate their signing
keys when asked to sign a request whose date does not match the scope date
of the signing key. Instances will instead raise a DateMismatchError.

Keys of StrictAWSAuth instances can be regenerated manually by calling the
regenerate_signing_key() method.

Keys will still store the secret key by default. If this is not desired
then create the instance by passing an AWS4SigningKey created with
store_secret_key set to False to the StrictAWS4AUth constructor:

>>> sig_key = AWS4SigningKey(secret_key, region, service, date, False)
>>> auth = StrictAWS4Auth(access_id, sig_key)

c                     [         e)a8  
Handle a request whose date doesn't match the signing key process, by
raising a DateMismatchError.

Overrides the default behaviour of AWS4Auth where the signing key
is automatically regenerated to match the request date

To update the signing key if this is hit, call
StrictAWS4Auth.regenerate_signing_key().

)r
   r1   rY   s     r6   rK   #StrictAWS4Auth.handle_date_mismatch  s
      r8   r   Nr   r   r   r   r   rK   r   r   r8   r6   r   r     s    " r8   r   c                       \ rS rSrSrS rSrg)PassiveAWS4Authi  a4  
This subclass does not perform any special handling of a mismatched request
and scope date, it signs the request and allows Requests to send it. It is
up to the calling code to handle a failed authentication response from AWS.

This behaviour mimics the behaviour of AWS4Auth for versions 0.7 and
earlier.

c                     g r   r   r   s     r6   rK   $PassiveAWS4Auth.handle_date_mismatch  s    r8   r   Nr   r   r8   r6   r   r     s    r8   r   )r   rV   rN   r   r   r   rH   collections.abcr.   ImportErrorcollectionsurllib.parser   r   r   r   requests.authr   aws4signingkeyr	   
exceptionsr
   r   r   r   r   r   r   r8   r6   <module>r     sw       	  ! < ; " * L Lr
x r
j X  Bh A  s   A& &
A32A3