
                         L    d Z ddlZddlZddlZddlZddlZd Z G d de      Zy)z=Context managers for patching libraries for use in PAR files.    Nc                 \   t         j                  j                  t        j                        ryt        j                  dd      }t         j                  j                  | d      }t        |d      5 }|j                  |       ddd       |t        _        y# 1 sw Y   |t        _        yxY w)a%  Patch things so that httplib2 works properly in a PAR.

  Manually extract certificates to file to make OpenSSL happy and avoid error:
     ssl.SSLError: [Errno 185090050] _ssl.c:344: error:0B084002:x509 ...

  Args:
    extract_dir: the directory into which we extract the necessary files.
  Nhttplib2zcacerts.txtwb)
ospathisfiler   CA_CERTSpkgutilget_datajoinopenwrite)extract_dircacerts_contentscacerts_filenamefs       3lib/third_party/containerregistry/tools/patched_.py_monkey_patch_httplib2r      sz     WW^^H%%&
%%j-@WW\\+}=d#qGG $&( $&(s   1BB+c                       e Zd Zd Zd Zd Zy)Httplib2c                 6    t        j                         | _        y N)tempfilemkdtemp_tmpdirselfs    r   __init__zHttplib2.__init__.   s    ##%DL    c                 0    t        | j                         | S r   )r   r   r   s    r   	__enter__zHttplib2.__enter__2   s    4<<(Kr   c                 B    t        j                  | j                         y r   )shutilrmtreer   )r   unused_typeunused_valueunused_tracebacks       r   __exit__zHttplib2.__exit__6   s    
MM$,,r   N)__name__
__module____qualname__r   r!   r(    r   r   r   r   ,   s    & r   r   )	__doc__r   r
   r#   r   r   r   objectr   r,   r   r   <module>r/      s+    D 	    '& v  r   