Your IP : 216.73.217.13


Current Path : /lib/python3/dist-packages/cloudinit/handlers/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/cloudinit/handlers/__pycache__/__init__.cpython-38.pyc

U

�Ad�&�
@s ddlZddlZddlmZddlmZddlmZmZddlm	Z	m
Z
mZe�e
�ZdZdZdZd	ZeegZd
gZdZdZd
dddd
dddddddd�Zeee���dd�d�ZGdd�dejd�Zdd �Zd!d"�Zd#d$�Z d%d&�Z!d'd(�Z"d)d*�Z#d+d,�Z$d-d.�Z%efd/d0�Z&d3d1d2�Z'dS)4�N)�importer)�log)�
type_utils�util)�FREQUENCIES�
PER_ALWAYS�PER_INSTANCEztext/x-not-multipartzapplication/octet-streamZ__end__Z	__begin__ztext/part-handlerzpart-handler-%03dz	part-%03dztext/x-include-urlztext/x-include-once-urlztext/x-shellscriptztext/cloud-configztext/cloud-boothookztext/cloud-config-archiveztext/cloud-config-jsonpztext/jinja2�text/x-shellscript-per-boot�text/x-shellscript-per-instance�text/x-shellscript-per-once)z#includez
#include-oncez#!z
#cloud-configz
#part-handlerz#cloud-boothookz#cloud-config-archivez#cloud-config-jsonpz## template: jinjar	r
rcCsdt|�S)Nr)�len)�e�r�=/usr/lib/python3/dist-packages/cloudinit/handlers/__init__.py�<lambda>?�r)�keyc@s4eZdZddd�Zdd�Zdd�Zejdd	��Zd
S)�Handler�cCs||_||_dS�N)�handler_version�	frequency)�selfr�versionrrr�__init__DszHandler.__init__cCsdt�|�|��fS)Nz%s: [%s])rZobj_name�
list_types�rrrr�__repr__HszHandler.__repr__cCs,t|d�std��ndd�t|d�D�SdS)N�prefixesz#Missing prefixes subclass attributecSsg|]}t|�qSr)�INCLUSION_TYPES_MAP)�.0�prefixrrr�
<listcomp>Ps�z&Handler.list_types.<locals>.<listcomp>)�hasattr�NotImplementedError�getattrrrrrrKs


�zHandler.list_typescOs
t��dSr)r$)r�args�kwargsrrr�handle_partUszHandler.handle_partN)r)	�__name__�
__module__�__qualname__rrr�abc�abstractmethodr(rrrrrCs


r)�	metaclassc	Cs|j}|tks"|tkr|tks"dSz|j}t|�}Wntttfk
rRd}YnX|d}zxt�	d|||||�|dkr�|�
||||||�nB|dkr�|�
|||||�n&|dkr�|�
||||�ntd|��Wn*tk
r�t�
td|||||�YnXdS)N��Content-Typez1Calling handler %s (%s, %s, %s) with frequency %s�rzUnknown module version %sz8Failed calling handler %s (%s, %s, %s) with frequency %s)rrrr�int�	TypeError�
ValueError�AttributeError�LOG�debugr(�	Exceptionr�logexc)	�mod�data�filename�payloadr�headersZmod_freqZmod_ver�content_typerrr�run_partZs^���
���r@cCsdti}t||dd||�dS�Nr0)�
CONTENT_STARTr@�r:r;rr>rrr�
call_begin�s�rDcCsdti}t||dd||�dSrA)�CONTENT_ENDr@rCrrr�call_end�s�rFc
	Cs�|d}t|}|d}tj�|dd|�}|�d�s@d|}t�||d�|d}z<tt�	|��}	t
|	|d	|�|j|	d
d�|d|d<Wn$tk
r�t�
td
||�YnXdS)NZhandlercountrZ
handlerdirz%sz.pyz%s.pyi��handlersr;T)Zinitializedr/z7Failed at registering python file: %s (part handler %s))�PART_HANDLER_FN_TMPL�os�path�join�endswithrZ
write_file�
fixup_handlerr�
import_modulerD�registerr8r9r6)
ZpdataZ_ctypeZ	_filenamer=Zcurcount�modnamerZmodfnamerGr:rrr�walker_handle_handler�s(
�rQcCs�z\t|t�r|�dd�d}n$|dd|�jdd��dd�d}t|�|krZ|d|�}Wn tk
r||d|�}YnX|S)N�
r/r��ignore)�errors)�
isinstance�str�split�decoder�UnicodeDecodeError)Zblob�size�startrrr�_extract_first_or_bytes�s
$r]cCsbz|�d�WSttfk
rJz|�d�WYStk
rDYnXYntk
r\YnX|S)NZ
string_escapeZunicode_escape)�encode�LookupErrorr3r5)�textrrr�_escape_string�s
racCs�|d}||�d�kr&t�d|�dS|tkr@t||||�dS|d}||krpt|||d|||d|�nN|r�t|d�}dt|�}|tkr�t�	d	||�q�t�	d
||�nt�d|�dS)Nr0Zexcludedzcontent_type "%s" is excludedrGr;r�z'%s...'z)Unhandled non-multipart (%s) userdata: %sz0Unhandled unknown content-type (%s) userdata: %szEmpty payload of type %s)
�getr6r7�PART_CONTENT_TYPESrQr@r]ra�NOT_MULTIPART_TYPE�warning)r;r<r=r>r?rGr\Zdetailsrrr�walker_callback�s@�
��rgc	Cs�d}|��D]t}|��dkrq|��}|dkr2t}|��}|sFt|}t|�}t�|�||d<t	�
|�}|||||�|d}qdS)NrZ	multipartr0r/)�walkZget_content_maintypeZget_content_type�
OCTET_TYPE�get_filename�PART_FN_TPL�dictr6r7rZfully_decoded_payload)	�msg�callbackr;Zpartnum�partZctyper<r>r=rrrrhs 

rhcCsRt|d�st|dd�t|d�s.t|d|�n |j}|rN|tkrNt�d||�|S)Nrr/rz&Handler %s has an unknown frequency %s)r#�setattrrrr6rf)r:Zdef_freqZfreqrrrrMs

rMcCsXzt�|���}Wntk
r*|YSX|��}tD]}|�|�r8t|Sq8|Sr)rZ
decode_binary�lowerrZ�lstrip�INCLUSION_SRCH�
startswithr)r=�defaultZ
payload_lcr`rrr�type_from_starts_with$s

rv)N)(r,rIZ	cloudinitrrZloggingrrZcloudinit.settingsrrrZ	getLoggerr)r6rerirErBZCONTENT_SIGNALSrdrHrkr�sorted�list�keysrs�ABCMetarr@rDrFrQr]rargrhrMrvrrrr�<module>sT
�
�0)