
                          v    d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlZ G d d	e	      Z
	 	 	 dd
Zd Zy)z<This package facilitates HTTP/REST requests to the registry.    )absolute_import)division)print_function)docker_creds)docker_nameNc                   R     e Zd ZdZ fdZed        Zed        Zed        Z xZ	S )BadStatusExceptionz6Exceptions when an unexpected HTTP status is returned.c                 n    dj                  ||      }t        t        |   |       || _        || _        y )Nz#Response:
{resp}
Content:
{content})respcontent)formatsuperr	   __init___resp_content)selfr   r   message	__class__s       ;lib/third_party/containerregistry/client/v1/docker_http_.pyr   zBadStatusException.__init__   s;    6==7 > $G	
d,W5DJDM    c                     | j                   S N)r   r   s    r   r   zBadStatusException.resp#   s    ::r   c                 .    | j                   j                  S r   )r   statusr   s    r   r   zBadStatusException.status'   s    ::r   c                     | j                   S r   )r   r   s    r   r   zBadStatusException.content+   s    ==r   )
__name__
__module____qualname____doc__r   propertyr   r   r   __classcell__)r   s   @r   r	   r	      sG    >      r   r	   c                     |r|nd|j                         dt        j                  d}| j                  ||rdnd||      \  }}|j                  |vrt        ||      ||fS )aE  Wrapper containing much of the boilerplate REST logic for Registry calls.

  Args:
    transport: the HTTP transport to use for requesting url
    url: the URL to which to talk
    credentials: the source of the Authorization header
    accepted_codes: the list of acceptable http status codes
    body: the body to pass into the PUT request (or None for GET)
    content_type: the mime-type of the request (or None for JSON)

  Raises:
    BadStatusException: the status codes wasn't among the acceptable set.

  Returns:
    The response of the HTTP request, and its contents.
  zapplication/jsontrue)zcontent-typeAuthorizationzX-Docker-Tokenz
user-agentPUTGET)bodyheaders)Getr   
USER_AGENTrequestr   r	   )		transporturlcredentialsaccepted_codesr(   content_typer)   r   r   s	            r   Requestr2   1   sw    . '3l8J"(**	' ##	D5e$ $ A-$ 
[[&
T7
++	wr   c                 (    | j                  d      ryy)z<Returns https scheme for all the endpoints except localhost.z
localhost:httphttps)
startswith)endpoints    r   Schemer8   W   s    &r   )NNN)r    
__future__r   r   r   containerregistry.clientr   r   httplib2	Exceptionr	   r2   r8    r   r   <module>r>      s?    C &  % 1 0  6 "#Lr   