
    !\iRG                     >   S r SSKrSSKrSSKJr  SSKJrJr  \R                  " \	5      r
 SSKr " S S5      r " S S	\5      r " S
 S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      rS rg! \ a    \
R                  S5        Sr Nkf = f)z+Abstraction for sessions in various clouds.    N)SimpleNamespace)_parse_path_UnparsedPathz>Could not import boto3, continuing with reduced functionality.c                       \ rS rSrSr\S 5       rS r\SS j5       r	\S 5       r
\S 5       r\S	 5       r\S
 5       rSrg)Session   zBase for classes that configure access to secured resources.

Attributes
----------
credentials : dict
    Keys and values for session credentials.

Notes
-----
This class is not intended to be instantiated.

c                     [         $ )Determine if the given configuration has proper credentials

Parameters
----------
cls : class
    A Session class.
config : dict
    GDAL configuration as a dict.

Returns
-------
bool

NotImplementedclsconfigs     S/var/www/html/kml_chatgpt/mouzaenv/lib/python3.13/site-packages/rasterio/session.pyhascredsSession.hascreds!   s
          c                     [         $ EGet credentials as GDAL configuration options

Returns
-------
dict

r   selfs    r   get_credential_optionsSession.get_credential_options3   s
     r   Nc                 4    U(       d
  [        5       $ U" U 5      $ )zCreate a session object matching the foreign `session`.

Parameters
----------
session : obj
    A foreign session object.
cls : Session class, optional
    The class to return.

Returns
-------
Session

)DummySession)sessionr   s     r   from_foreign_sessionSession.from_foreign_session=   s      >!w<r   c                 
   U (       d  [         $ [        U 5      n [        U [        5      (       d  U R                  (       a  [         $ U R
                  S:X  d  SU R                  ;   a8  SU R                  ;  a(  [        b  [        $ [        R                  S5        [         $ U R
                  S:X  d  SU R                  ;   a  [        $ U R                  R                  S5      (       a  [        $ U R
                  S:X  a  [        $ [         $ )	zFind the session class suited to the data at `path`.

Parameters
----------
path : str
    A dataset path or identifier.

Returns
-------
class

s3zamazonaws.comzX-Amz-Signaturez4boto3 not available, falling back to a DummySession.osszaliyuncs.comz
/vsiswift/az)r   r   
isinstancer   is_localschemepathboto3
AWSSessionloginfo
OSSSession
startswithSwiftSessionAzureSession)r'   s    r   cls_from_pathSession.cls_from_pathR   s     4 dM**dmm KK4?dii#?#tyy0 !!OP##[[E!^tyy%@YY!!,//[[D   r   c                 8    [         R                  U 5      " U0 UD6$ )a+  Create a session object suited to the data at `path`.

Parameters
----------
path : str
    A dataset path or identifier.
args : sequence
    Positional arguments for the foreign session constructor.
kwargs : dict
    Keyword arguments for the foreign session constructor.

Returns
-------
Session

)r   r0   )r'   argskwargss      r   	from_pathSession.from_path   s    $ $$T*D;F;;r   c                  <    [         b  [        U 0 UD6$ [        U 0 UD6$ )a3  Create an AWSSession if boto3 is available, else DummySession

Parameters
----------
path : str
    A dataset path or identifier.
args : sequence
    Positional arguments for the foreign session constructor.
kwargs : dict
    Keyword arguments for the foreign session constructor.

Returns
-------
Session

)r(   r)   r   )r3   r4   s     r   aws_or_dummySession.aws_or_dummy   s*    $ t.v..000r   c                       [         R                  " U 0 UD6nUR                    U$ ! [         a+  n[        R                  S5        [        U 0 UD6n SnAU$ SnAff = f)a(  Create a session object suited to the environment.

Parameters
----------
path : str
    A dataset path or identifier.
args : sequence
    Positional arguments for the foreign session constructor.
kwargs : dict
    Keyword arguments for the foreign session constructor.

Returns
-------
Session

zACredentials in environment have expired. Creating a DummySession.N)r   r8   credentialsRuntimeErrorr*   warningr   )r3   r4   r   excs       r   from_environSession.from_environ   s_    $	4**D;F;G   	4KK[\"D3F3G	4s   "& 
A AA N)__name__
__module____qualname____firstlineno____doc__classmethodr   r   staticmethodr   r0   r5   r8   r?   __static_attributes__rA   r   r   r   r      s      "    ( ,  , \ < <& 1 1,  r   r   c                   4    \ rS rSrSrS r\S 5       rS rSr	g)r      zYA dummy session.

Attributes
----------
credentials : dict
    The session credentials.

c                      S U l         0 U l        g rB   _sessionr;   )r   r3   r4   s      r   __init__DummySession.__init__   s    r   c                     g)r
   TrA   r   s     r   r   DummySession.hascreds   s      r   c                     0 $ r   rA   r   s    r   r   #DummySession.get_credential_options   s	     	r   rN   N)
rC   rD   rE   rF   rG   rP   rH   r   r   rJ   rA   r   r   r   r      s%      "r   r   c                   P    \ rS rSrSr    S	S jr\S 5       r\S 5       r	S r
Srg)
r)      z=Configures access to secured resources stored in AWS S3.
    Nc
                 `   Uc   [        [        R                  " SS5      5      nU(       a  Xl        O3U(       a  [	        US9U l        O[
        R                  " UUUUUS9U l        Xl        X l        Xl	        U R                  (       d   U R                  R                  5       U l        gSU l        g)a  Create a new AWS session

Parameters
----------
session : optional
    A boto3 session object.
aws_unsigned : bool, optional (default: False)
    If True, requests will be unsigned.
aws_access_key_id : str, optional
    An access key id, as per boto3.
aws_secret_access_key : str, optional
    A secret access key, as per boto3.
aws_session_token : str, optional
    A session token, as per boto3.
region_name : str, optional
    A region name, as per boto3.
profile_name : str, optional
    A shared credentials profile name, as per boto3.
endpoint_url: str, optional
    An endpoint_url, as per GDAL's AWS_S3_ENPOINT
requester_pays : bool, optional
    True if the requester agrees to pay transfer costs (default:
    False)
NAWS_NO_SIGN_REQUESTF)region_name)aws_access_key_idaws_secret_access_keyaws_session_tokenrZ   profile_name)
parse_boolosgetenvrO   r   r(   r   requester_paysunsignedendpoint_urlget_credentials_creds)
r   r   aws_unsignedr[   r\   r]   rZ   r^   rd   rb   s
             r   rP   AWSSession.__init__   s    : %bii0Eu&MNL#M+DDM!MM"3&;"3')+DM -$( == MM))+ 	  	r   c                 <    SU;   =(       a    SU;   =(       d    SU;   $ )r
   AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYrY   rA   r   s     r   r   AWSSession.hascreds+  s&      $v-S2IV2SwXmqwXwwr   c                    0 nU R                   (       az  U R                   R                  5       nUR                  (       a  UR                  US'   UR                  (       a  UR                  US'   UR                  (       a  UR                  US'   U R
                  R                  (       a  U R
                  R                  US'   U R                  (       a  SUS'   U R                  (       a  U R                  US'   U$ )!The session credentials as a dictr[   r\   r]   
aws_region	requesteraws_request_payeraws_s3_endpoint)	rf   get_frozen_credentials
access_key
secret_keytokenrO   rZ   rb   rd   )r   resfrozen_credss      r   r;   AWSSession.credentials=  s     ;;;;==?L&&+7+B+B'(&&/;/F/F+,!!+7+=+='(==$$ $ 9 9C'2C#$%)%6%6C!"
r   c                 n   U R                   (       a[  SS0nUR                  U R                  R                  5        VVs0 s H  u  p#US;   d  M  UR	                  5       U_M      snn5        U$ U R                  R                  5        VVs0 s H  u  p#UR	                  5       U_M     snn$ s  snnf s  snnf )r   rY   YES)ro   rr   )rc   updater;   itemsupper)r   optskvs       r   r   !AWSSession.get_credential_optionsQ  s     ==)51DKK$2B2B2H2H2J C2J$! AA &A2J C DK-1-=-=-C-C-EF-ETQAGGIqL-EFF	C Gs   B+
B+

B1)rf   rO   rd   rb   rc   )	NNNNNNNNFrC   rD   rE   rF   rG   rP   rH   r   propertyr;   r   rJ   rA   r   r   r)   r)      sM     FJ:>>B 	3
j x x"  &Gr   r)   c                   H    \ rS rSrSrS	S jr\S 5       r\S 5       r	S r
Srg)
r,   ib  zHConfigures access to secured resources stored in Alibaba Cloud OSS.
    Nc                     UUUS.U l         g)a+  Create new Alibaba Cloud OSS session

Parameters
----------
oss_access_key_id: string, optional (default: None)
    An access key id
oss_secret_access_key: string, optional (default: None)
    An secret access key
oss_endpoint: string, optional (default: None)
    the region attached to the bucket
)oss_access_key_idoss_secret_access_keyoss_endpointNrf   )r   r   r   r   s       r   rP   OSSSession.__init__e  s     "3%:(
r   c                 $    SU;   =(       a    SU;   $ )r
   OSS_ACCESS_KEY_IDOSS_SECRET_ACCESS_KEYrA   r   s     r   r   OSSSession.hascredsx  s      #f,R1HF1RRr   c                     U R                   $ rn   r   r   s    r   r;   OSSSession.credentials       {{r   c                     U R                   R                  5        VVs0 s H  u  pUR                  5       U_M     snn$ s  snnf r   r;   r}   r~   r   r   r   s      r   r   !OSSSession.get_credential_options  9     *.)9)9)?)?)AB)A	1)ABBB   ?r   )NNNr   rA   r   r   r,   r,   b  s<    
& S S"  Cr   r,   c                   H    \ rS rSrSrS	S jr\S 5       r\S 5       r	S r
Srg)
	GSSessioni  zJConfigures access to secured resources stored in Google Cloud Storage
    Nc                 ,    Ub
  SU0U l         g0 U l         g)zCreate new Google Cloud Storage session

Parameters
----------
google_application_credentials: string
    Path to the google application credentials JSON file.
Ngoogle_application_credentialsr   )r   r   s     r   rP   GSSession.__init__  s     *5;=[\DKDKr   c                     SU;   $ )r
   GOOGLE_APPLICATION_CREDENTIALSrA   r   s     r   r   GSSession.hascreds  s      0699r   c                     U R                   $ r   r   r   s    r   r;   GSSession.credentials  r   r   c                     U R                   R                  5        VVs0 s H  u  pUR                  5       U_M     snn$ s  snnf r   r   r   s      r   r    GSSession.get_credential_options  r   r   r   rB   r   rA   r   r   r   r     s:     : :"  Cr   r   c                   N    \ rS rSrSr   S	S jr\S 5       r\S 5       r	S r
Srg)
r.   i  zUConfigures access to secured resources stored in OpenStack Swift Object Storage.
    Nc                     U(       a  U(       a  UUS.U l         gSSKJn  U(       a  Xl        OU" UUUS9U l        U R                  R	                  5       S   U R                  R	                  5       S   S.U l         g)a  Create new OpenStack Swift Object Storage Session.

Three methods are possible:
    1. Create session by the swiftclient library.
    2. The SWIFT_STORAGE_URL and SWIFT_AUTH_TOKEN (this method is recommended by GDAL docs).
    3. The SWIFT_AUTH_V1_URL, SWIFT_USER and SWIFT_KEY (This depends on the swiftclient library).

Parameters
----------
session: optional
    A swiftclient connection object
swift_storage_url:
    the storage URL
swift_auth_token:
    the value of the x-auth-token authorization token
swift_storage_url: string, optional
    authentication URL
swift_user: string, optional
    user name to authenticate as
swift_key: string, optional
    key/password to authenticate with

Examples
--------
>>> import rasterio
>>> from rasterio.session import SwiftSession
>>> fp = '/vsiswift/bucket/key.tif'
>>> conn = Connection(authurl='http://127.0.0.1:7777/auth/v1.0', user='test:tester', key='testing')
>>> session = SwiftSession(conn)
>>> with rasterio.Env(session):
>>>     with rasterio.open(fp) as src:
>>>         print(src.profile)

)swift_storage_urlswift_auth_tokenr   )
Connection)authurluserkey   N)rf   swiftclient.clientr   rO   get_auth)r   r   r   r   swift_auth_v1_url
swift_user	swift_keyr   s           r   rP   SwiftSession.__init__  sq    J !1%6$4DK
 6 ' *-#!! &*]]%;%;%=a%@$(MM$:$:$<Q$?DKr   c                 $    SU;   =(       a    SU;   $ )zDetermine if the given configuration has proper credentials
Parameters
----------
cls : class
    A Session class.
config : dict
    GDAL configuration as a dict.
Returns
-------
bool
SWIFT_STORAGE_URLSWIFT_AUTH_TOKENrA   r   s     r   r   SwiftSession.hascreds
  s     #f,M1Cv1MMr   c                     U R                   $ r   r   r   s    r   r;   SwiftSession.credentials  r   r   c                     U R                   R                  5        VVs0 s H  u  pUR                  5       U_M     snn$ s  snnf )zCGet credentials as GDAL configuration options
Returns
-------
dict
r   r   s      r   r   #SwiftSession.get_credential_options  s9     *.)9)9)?)?)AB)A	1)ABBBr   )rf   rO   )NNNNNNr   rA   r   r   r.   r.     sF    #9=CG8t N N  Cr   r.   c                   N    \ rS rSrSr   S	S jr\S 5       r\S 5       r	S r
Srg)
r/   i'  zSConfigures access to secured resources stored in Microsoft Azure Blob Storage.
    Nc                    [        [        R                  " SU5      5      U l        U=(       d    [        R                  " S5      U l        U=(       d    [        R                  " S5      U l        U(       a
  SU0U l        gU R                  (       d  U R                  U R
                  S.U l        gSU R                  0U l        g)at  Create new Microsoft Azure Blob Storage session

Parameters
----------
azure_storage_connection_string: string
    A connection string contains both an account name and a secret key.
azure_storage_account: string
    An account name
azure_storage_access_key: string
    A secret key
azure_unsigned : bool, optional (default: False)
    If True, requests will be unsigned.
AZURE_NO_SIGN_REQUESTAZURE_STORAGE_ACCOUNTAZURE_STORAGE_ACCESS_KEYazure_storage_connection_string)azure_storage_accountazure_storage_access_keyr   N)r_   r`   ra   rc   storage_accountstorage_access_keyrf   )r   r   r   r   azure_unsigneds        r   rP   AzureSession.__init__*  s    " #299-Dn#UV4Z		BY8Z":"cbiiHb>c*13RDK )-)=)=,0,C,CDK ()=)=DKr   c                 l    SU;   =(       d)    SU;   =(       a    SU;   =(       d    SU;   =(       a    SU;   $ )r
   AZURE_STORAGE_CONNECTION_STRINGr   r   r   rA   r   s     r   r   AzureSession.hascredsM  sE    " .7 Y'61Z6PTZ6ZY'61W6MQW6W	
r   c                     U R                   $ r   r   r   s    r   r;   AzureSession.credentialsc  r   r   c                     U R                   (       a  SU R                  S.$ U R                  R                  5        VVs0 s H  u  pUR	                  5       U_M     snn$ s  snnf )r   r{   )r   r   )rc   r   r;   r}   r~   r   s      r   r   #AzureSession.get_credential_optionsh  sX     ==).)-)=)= 
 .2-=-=-C-C-EF-ETQAGGIqL-EFFFs   A)rf   r   r   rc   )NNNFr   rA   r   r   r/   r/   '  sD    7;FJ %!F 
 
*  Gr   r/   c                     [        U [        5      (       a  U $ [        U [        5      (       a  U R                  5       S;  $ [        U 5      $ )zCPLTestBool equivalent)nofalseoff0)r$   boolstrlower)r   s    r   r_   r_   x  s<    !T!S779 ;;<7Nr   )rG   loggingr`   typesr   rasterio._pathr   r   	getLoggerrC   r*   r(   ImportErrordebugr   r   r)   r,   r   r.   r/   r_   rA   r   r   <module>r      s    1  	 ! 5 !q qh(7 (VmG mG`5C 5Cp0C 0CfWC7 WCtOG7 OGbU  IINOEs   B   BB