Mini Shell

Direktori : /lib/python3.6/site-packages/pykickstart/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/pykickstart/__pycache__/load.cpython-36.pyc

3

�
LdU�@sxddlZddlZddlZddlmZddlmZddlmZm	Z	dd�Z
dZdd	�Zd
d�Z
dd
�Zdd�Zdd�ZdS)�N)�KickstartError)�_)�SSLError�RequestExceptioncCsd|kS)Nz://�)�locationrr�/usr/lib/python3.6/load.py�<lambda>sr	TcCst|�rt|�St|�SdS)z�Load a destination URL or file into a string.
    Type of input is inferred automatically.

    Arguments:
    location -- URL or file name to load

    Returns: string with contents
    Raises: KickstartError on error readingN)�_is_url�	_load_url�
_load_file)rrrr�load_to_str s
r
cCs�t|�r|t|�}y$t|d��}|j|�WdQRXWnBtk
rv}z&ttd�|djt|�d���WYdd}~XnX|St	||�|SdS)a(Load a destination URL or file into a file name.
    Type of input is inferred automatically.

    Arguments:
    location -- URL or file name to load
    destination -- destination file name to write to

    Returns: file name with contents
    Raises: KickstartError on error reading or writing�wNzError writing file "%s":z: {e})�e)
r
r�open�write�IOErrorrr�format�str�
_copy_file)r�destination�contents�fhrrrr�load_to_file/s2
rcCs�ytj|td�}Wn�tk
rT}z&ttd�|djt|�d���WYdd}~XnBtk
r�}z&ttd�|djt|�d���WYdd}~XnX|j	tj
jkr�ttd�|djt|j	�d���|jS)	z?Load a location (URL or filename) and return contents as string)Zverifyz!Error securely accessing URL "%s"z: {e})rNzError accessing URL "%s"z: {c})�c)
�requests�get�
SSL_VERIFYrrrrrrZstatus_codeZcodes�ok�text)rZrequestrrrrrIs02"rcCs�yNtjr.t|d��}|j�jd�}WdQRXnt|d��}|j�}WdQRXWn6tk
r�}zttd�t|���WYdd}~XnX|S)z2Load a file's contents and return them as a string�rbzutf-8N�rzError opening file: %s)	�sixZPY3r�read�decoderrrr)�filenamerrrrrrrXs&rcCsPytj||�Wn:ttfk
rJ}zttd�t|���WYdd}~XnXdS)zCopy file to destinationzError copying file: %sN)�shutilZcopyfile�OSErrorrrrr)r%rrrrrrgsr)rr&r"Zpykickstart.errorsrZpykickstart.i18nrZrequests.exceptionsrrr
rr
rrrrrrrr�<module>s