o
    .&ßaØ  ã                   @   sP   d Z ddlmZ dZG dd„ deƒZdd„ Zdd	„ Zd
d„ ZG dd„ deƒZ	dS )z+Add S3 specific event streaming output arg.é    )ÚCustomArgumentz(Filename where the records will be savedc                   @   s   e Zd ZdS )ÚDocSectionNotFoundErrorN)Ú__name__Ú
__module__Ú__qualname__© r   r   ú@/usr/lib/python3/dist-packages/awscli/customizations/s3events.pyr      s    r   c                 C   s   |   dt¡ |  dt¡ d S )Nz3building-argument-table.s3api.select-object-contentz&doc-output.s3api.select-object-content)ÚregisterÚadd_event_stream_output_argÚregister_lastÚreplace_event_stream_docs)Úevent_handlersr   r   r   Úregister_event_stream_arg   s   þþr   c                 K   s$   t dtdd|jjd |d�| d< d S )NÚoutfileÚstringTÚpayload)ÚnameÚ	help_textÚcli_type_nameÚpositional_argÚ
stream_keyÚsession)ÚS3SelectStreamOutputArgumentÚSTREAM_HELP_TEXTÚoutput_shapeÚserialization)Úargument_tableÚoperation_modelr   Úkwargsr   r   r   r
   "   s   
ür
   c                 K   sZ   | j }d}|dkr!z| ¡ }W n ty   td|  ƒ‚w |dks	| d¡ | d¡ d S )NÚ z======
Output
======z7Could not find the "output" section for the command: %sz======
Output
======
zdThis command generates no output.  The selected object content is written to the specified outfile.
)ÚdocÚ	pop_writeÚ
IndexErrorr   Úwrite)Úhelp_commandr   r    Úcurrentr   r   r   r   +   s   ÿÿýý
	r   c                       s0   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Z‡  ZS )r   Tc                    s,   t t| ƒjdi |¤Ž || _d | _|| _d S )Nr   )Úsuperr   Ú__init__Ú_stream_keyÚ_output_fileÚ_session)Úselfr   r   r   ©Ú	__class__r   r   r'   ?   s   
z%S3SelectStreamOutputArgument.__init__c                 C   s   || _ | j d| j¡ d S )Nz!after-call.s3.SelectObjectContent)r)   r*   r	   Ú	save_file)r+   Ú
parametersÚvaluer   r   r   Úadd_to_paramsG   s   ÿz*S3SelectStreamOutputArgument.add_to_paramsc                 K   st   | j |vrd S || j  }t| jdƒ�}|D ]}d|v r$| |d d ¡ qW d   ƒ n1 s/w   Y  || j = d S )NÚwbÚRecordsÚPayload)r(   Úopenr)   r#   )r+   Úparsedr   Úevent_streamÚfpÚeventr   r   r   r.   L   s   

€þÿz&S3SelectStreamOutputArgument.save_file)r   r   r   Ú_DOCUMENT_AS_REQUIREDr'   r1   r.   Ú__classcell__r   r   r,   r   r   <   s
    r   N)
Ú__doc__Úawscli.argumentsr   r   Ú	Exceptionr   r   r
   r   r   r   r   r   r   Ú<module>   s   
	