
    <	                         S r SSKJr  SSKJr  SSKJr  SSKrSSKrSSKJr  SSK	r	 " S S\	R                  R                  5      rg)	z=Protocol adapter class to allow requests to GET file:// URLs.    )absolute_import)division)unicode_literalsN)filesc                   .    \ rS rSrSr\S 5       rS rSrg)LocalFileAdapter   z7Protocol Adapter to allow Requests to GET file:// URLs.c                 &   U R                  5       S;  a  [        R                  R                  S4$ [        R
                  R                  U5      (       a  [        R                  R                  S4$ [        R
                  R                  U5      (       d  [        R                  R                  S4$ [        R                  " U[        R                  5      (       d  [        R                  R                  S4$ [        R                  R                  S4$ )z4Return an HTTP status for the given filesystem path.)getheadzMethod Not AllowedzPath Not A FilezFile Not FoundzAccess DeniedOK)lowerrequestscodesnot_allowedospathisdirbad_requestisfile	not_foundaccessR_OK	forbiddenok)methodr   s     -lib/googlecloudsdk/core/local_file_adapter.py_chkpathLocalFileAdapter._chkpath   s     ||~_,^^'')===	t		^^''):::WW^^D!!^^%%'777YYtRWW%%^^%%66^^$$    c                     [         R                  " UR                  5      n[        R                  " 5       nU R                  UR                  U5      u  Ul        Ul        UR                  S:X  aN  UR                  R                  5       S:w  a0   [        R                  " [         R                  " U5      5      Ul        UR"                  Ul        Xl        Xl        U$ ! [        [        4 a!  nSUl        [!        U5      Ul         SnANKSnAff = f)zReturn the file specified by the given request.

Args:
  req: PreparedRequest
  **kwargs: kwargs can include values for headers, timeout, stream, etc.

Returns:
  requests.Response object
   r   i  N)r   NormalizePathFromURLpath_urlr   Responser   r   status_codereasonr   ioBytesIOReadBinaryFileContentsrawOSErrorIOErrorstrurlrequest
connection)selfreqkwargsr   responseerrs         r   sendLocalFileAdapter.send-   s     %%cll3D  "H,0MM#**d,K)H(/s"szz'7'7'9V'C#zz%">">t"DE
 77HLO w #"c(#s   /C D,DD N)	__name__
__module____qualname____firstlineno____doc__staticmethodr   r7   __static_attributes__r9   r    r   r   r      s    ?% %r    r   )r>   
__future__r   r   r   r(   r   googlecloudsdk.core.utilr   r   adaptersBaseAdapterr   r9   r    r   <module>rE      s8    D &  ' 	 	 * )x((44 )r    