3 \me|& @sddlZddlZddlZddlmZmZmZddlmZm Z m Z ej e Z dZdZdZdZeegZdgZd Zd Zd d d dddddddddd ZeeejdddZGdddejdZddZdd Zd!d"Zd#d$Z d%d&Z!d'd(Z"d)d*Z#d+d,Z$e fd-d.Z%d1d/d0Z&dS)2N)importer type_utilsutil) 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-jsonpz text/jinja2ztext/x-shellscript-per-bootztext/x-shellscript-per-instanceztext/x-shellscript-per-once) z#includez #include-oncez#!z #cloud-configz #part-handlerz#cloud-boothookz#cloud-config-archivez#cloud-config-jsonpz## template: jinjaztext/x-shellscript-per-bootztext/x-shellscript-per-instanceztext/x-shellscript-per-oncecCs dt|S)Nr)len)er /usr/lib/python3.6/__init__.py>sr )keyc@s4eZdZd ddZddZddZejdd Zd S) HandlercCs||_||_dS)N)handler_version frequency)selfrversionr r r __init__CszHandler.__init__cCsdtj||jfS)Nz%s: [%s])rZobj_name list_types)rr r r __repr__GszHandler.__repr__cCs,t|dstdnddt|dDSdS)Nprefixesz#Missing prefixes subclass attributecSsg|] }t|qSr )INCLUSION_TYPES_MAP).0prefixr r r Psz&Handler.list_types..)hasattrNotImplementedErrorgetattr)rr r r rJs  zHandler.list_typescOs tdS)N)r)rargskwargsr r r handle_partTszHandler.handle_partN)r) __name__ __module__ __qualname__rrrabcabstractmethodr!r r r r rBs  r) metaclassc Cs|j}|tkp|tko|tks"dSy|j}t|}Wntttfk rRd}YnX|d}yxtj d||||||dkr|j ||||||nB|dkr|j |||||n&|dkr|j ||||n td|Wn,t k rt j td|||||YnXdS)Nz Content-Typez1Calling handler %s (%s, %s, %s) with frequency %srzUnknown module version %sz8Failed calling handler %s (%s, %s, %s) with frequency %s)rrrrint TypeError ValueErrorAttributeErrorLOGdebugr! Exceptionrlogexc) moddatafilenamepayloadrheadersZmod_freqZmod_ver content_typer r r run_partYsF  r8cCsdti}t||dd||dS)Nz Content-Type) CONTENT_STARTr8)r2r3rr6r r r call_beginsr:cCsdti}t||dd||dS)Nz Content-Type) CONTENT_ENDr8)r2r3rr6r r r call_endsr<c Cs|d}t|}|d}tjj|dd|}|jds@d|}tj||d|d}yrarsortedlistkeysriABCMetarr8r:r<rGrSrWr]r^rCrlr r r r  sL 0)