U
    W+de                     @   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__ ?/tmp/pip-unpacked-wheel-dlxw5sjy/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rd| jrd| j d| jd d }| jD ]}|d |krD|d | j d< qDd| j krz| j| j d< d| j kr| j| j d< z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regionr	   r   r   r      s(    




zAWSQueryService.__init__c                 C   s   dt jkrt jd }t j|}t j|}t j|rt|}| }|  |D ]z}|d dkrTd|krT|	dd\}}|
 dkrd| jkr|
 }|| jd< qT|
 dkrTd	| jkrT|
 }|| jd	< qTn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 }|rt|}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
< |rd| j kr|| j d< |jrd| 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_securehttpsTF:r$   r   r   r   r   )r   r   EnvURLr%   r&   urlparseschemenetlocr-   lenintr   )r   r4   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   NameDescriptionZ
APIVersionr>   r   r   ZProviderr7   r   r   r   r   r?   r   r   r   r	   r   r      s   !%r   )
__future__r   r%   r8   r    Zboto.connectionZboto.jsonresponseZboto.exceptionZboto.robotor   r!   ZBotoClientErrorr   
connectionZAWSQueryConnectionr   r   r   r   r   <module>   s   