B
    è?F[e  ã               @   st   d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlm	Z	 G dd„ dej
jƒZG dd„ dejjƒZdS )é    )Úprint_functionN)Úawsqueryrequestc                   s   e Zd Z‡ fdd„Z‡  ZS )ÚNoCredentialsErrorc                s   d}t t| ƒ |¡ d S )NzUnable to find credentials)Úsuperr   Ú__init__)ÚselfÚs)Ú	__class__© ú:lib/python3.7/site-packages/boto/roboto/awsqueryservice.pyr      s    zNoCredentialsError.__init__)Ú__name__Ú
__module__Ú__qualname__r   Ú__classcell__r
   r
   )r	   r   r   
   s   r   c                   sX   e Zd ZdZdZdZdZdZdZdZ	dZ
g Z‡ fdd„Zd	d
„ Zdd„ Zdd„ Z‡  ZS )ÚAWSQueryServiceÚ zsign-v2ú/i»  ZawsZAWS_URLc                sÖ   || _ |  ¡  |  ¡  d| j krh| jrh| j  d| jd d ¡}x(| jD ]}|d |krF|d | j d< qFW d| j kr~| j| j d< d| j kr”| j| j d< ytt| ƒj	f | j Ž d | _
W n tjjk
rÐ   tƒ ‚Y nX d S )NÚhostÚregion_namer   ÚnameZendpointÚpathÚport)ÚargsÚcheck_for_credential_fileÚcheck_for_env_urlÚRegionsÚgetÚPathÚPortr   r   r   Zaws_responseÚbotoÚ	exceptionZNoAuthHandlerFoundr   )r   r   r   Zregion)r	   r
   r   r      s&    



zAWSQueryService.__init__c             C   sâ   dt jkrÞt jd }t j |¡}t j |¡}t j |¡rÖt|ƒ}| ¡ }| ¡  xŒ|D ]z}|d dkrVd|krV| 	dd¡\}}| 
¡ dkr¨d| jkrÐ| 
¡ }|| jd< qV| 
¡ dkrVd	| jkrV| 
¡ }|| jd	< qVW ntd
ƒ dS )aq  
        Checks for the existence of an AWS credential file.
        If the environment variable AWS_CREDENTIAL_FILE is
        set and points to a file, that file will be read and
        will be searched credentials.
        Note that if credentials have been explicitelypassed
        into the class constructor, those values always take
        precedence.
        ZAWS_CREDENTIAL_FILEr   ú#ú=é   ZAWSAccessKeyIdZaws_access_key_idZAWSSecretKeyZaws_secret_access_keyz+Warning: unable to read AWS_CREDENTIAL_FILEN)ÚosÚenvironr   Ú
expanduserÚ
expandvarsÚisfileÚopenÚ	readlinesÚcloseÚsplitÚstripr   Úprint)r   r   ÚfpÚlinesÚliner   Úvaluer
   r
   r   r   2   s*    





z)AWSQueryService.check_for_credential_filec             C   sî   | j  dd¡}|r| j d= |s6| jtjkr6tj| j }|rêt |¡}d| j krn|jdkrdd| j d< n
d| j d< |j}d}| d¡}t	|ƒdkr¢|d	 }t
|d ƒ}d
| j kr¶|| j d
< |rÎd| j krÎ|| j d< |jrêd| j krê|j| j d< dS )a¡  
        First checks to see if a url argument was explicitly passed
        in.  If so, that will be used.  If not, it checks for the
        existence of the environment variable specified in ENV_URL.
        If this is set, it should contain a fully qualified URL to the
        service you want to use.
        Note that any values passed explicitly to the class constructor
        will take precedence.
        ÚurlNZ	is_secureZhttpsTFú:r#   r   r   r   r   )r   r   ÚEnvURLr$   r%   ÚurlparseZschemeZnetlocr,   ÚlenÚintr   )r   r3   Zrsltr   r   Úlr
   r
   r   r   S   s.    








z!AWSQueryService.check_for_env_urlc             C   s   | j gS )N)ÚAuthentication)r   r
   r
   r   Ú_required_auth_capabilityx   s    z)AWSQueryService._required_auth_capability)r   r   r   ÚNameZDescriptionZ
APIVersionr:   r   r   ZProviderr5   r   r   r   r   r;   r   r
   r
   )r	   r   r      s   !%r   )Z
__future__r   r$   r6   r   Zboto.connectionZboto.jsonresponseZboto.exceptionZboto.robotor   r    ZBotoClientErrorr   Z
connectionZAWSQueryConnectionr   r
   r
   r
   r   Ú<module>   s   