o
    l>j?                     @  s  d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlZddlmZmZmZ dd	lmZmZmZ dd
lmZmZmZmZmZmZmZmZmZmZ ddlm Z  ddl!m"Z"m#Z# ej$ddZ%dZ&dZ'dZ(dZ)G dd de*eZ+G dd de*eZ,dd Z-dd Z.ddd Z/e%0d!ej1d"d#d$e'd%ej1d&d'd(dddddd&eef	dd=d>Z2e%0d?ddddd&eefdd@dAZ3e%0dBej1ddCe)dej1d&dDdEdej1ddFdGdej1dHd#d$e'd%ddddd&eefddMdNZ4e%0dOej1dPdQdRdej1dPdSdTdej1d"d#d$e'd%ddddd&eef
ddVdWZ5e%0dXej6dYe(dej1d&dZd[dddddd&eef	dd^d_Z7e%0d`ej6dYddej1e+j8dadbdej1dcddd$ded%ddddd&eef
ddhdiZ9e%0djej6dYe(dej1dYdkdldej1e,j:dmdndej1ddodpdej1dqdrdsdej1e+j8dadbdej1dcddd$ded%ddddd&eefddzd{Z;e%0d|ej1ddFd}dej1dHd#d$d~d%ddddd&eef	dddZ<e%0dddddd&eefdddZ=dS )zNotes commands.    )annotations)Enum)islice)Path)OptionalN)CLIAbort	get_stateservice_call)normalize_sync_cursorsearch_notes_by_titleselect_recent_notes)
DEFAULT_LOG_LEVELDEFAULT_OUTPUT_FORMATHttpProxyOptionHttpsProxyOptionLogLevelOptionNoVerifySslOptionOutputFormatOptionSessionDirOptionUsernameOptionstore_command_options)console_table)NoteLockedErrorNoteNotFoundz"Inspect, render, and export Notes.)helpNoteszMaximum notes to show.zNote id.z
Folder id.c                   @     e Zd ZdZdZdZdS )PreviewAppearancez$Supported Notes preview appearances.lightdarkN)__name__
__module____qualname____doc__LIGHTDARK r&   r&   P/home/thesage/.local/lib/python3.10/site-packages/pyicloud/cli/commands/notes.pyr   *       r   c                   @  r   )
ExportModezSupported Notes export modes.archivallightweightN)r    r!   r"   r#   ARCHIVALLIGHTWEIGHTr&   r&   r&   r'   r)   1   r(   r)   c                   s   t t fdd jdS )z8Return the Notes service with reauthentication handling.c                     s    j S Nnotesr&   apir&   r'   <lambda>;   s    z _notes_service.<locals>.<lambda>account_name)r	   NOTESr5   r1   r&   r1   r'   _notes_service8   s   r7   c              
   C  s>   z	t t|| jdW S  ttfy } ztt||d}~ww )z?Wrap Notes service calls with note-specific user-facing errors.r4   N)r	   r6   r5   r   r   r   str)r2   fnerrr&   r&   r'   _notes_call>   s   r;   titler8   returnNonec                 C  s&   | j t|g ddd |D  dS )z&Render note summary rows in text mode.)IDTitleFolderModifiedDeletedc              
   S  s*   g | ]}|j |j|j|jt|d dfqS )
is_deletedF)idr<   folder_namemodified_atgetattr.0rowr&   r&   r'   
<listcomp>N   s    
z$_print_note_rows.<locals>.<listcomp>N)consoleprintr   )stater<   rowsr&   r&   r'   _print_note_rowsG   s   rQ   recent
   z--limit   )minr   Fz--include-deletedz$Include notes from Recently Deleted.ctxtyper.Contextlimitintinclude_deletedboolusernamer   session_dirr   
http_proxyr   https_proxyr   no_verify_sslr   output_formatr   	log_levelr   c
              
     sj   t | |||||||	d t| }
|
 }t|t| fdd}|
jr-|
| dS t|
d| dS )zList recent notes.r\   r]   r^   r_   r`   ra   rb   c                     s   t  dS )NrX   rZ   r   r&   rZ   rX   r0   r&   r'   r3   ~   
    znotes_recent.<locals>.<lambda>NzRecent Notes)r   r   get_apir7   r;   json_output
write_jsonrQ   )rV   rX   rZ   r\   r]   r^   r_   r`   ra   rb   rO   r2   payloadr&   rf   r'   notes_recent\   s*   

rl   foldersc              
     s|   t | |||||||d t| }| }	t|	 t|	 fdd}
|jr+||
 dS |jt	dg ddd |
D  dS )	zList note folders.rc   c                     s   t   S r.   )listrm   r&   r/   r&   r'   r3      s    znotes_folders.<locals>.<lambda>NzNote Folders)r?   NamezHas SubfoldersCountc                 S      g | ]}|j |j|j|jfqS r&   )rE   namehas_subfolderscountrI   r&   r&   r'   rL           z!notes_folders.<locals>.<listcomp>
r   r   rh   r7   r;   ri   rj   rM   rN   r   )rV   r\   r]   r^   r_   r`   ra   rb   rO   r2   rk   r&   r/   r'   notes_folders   s0   

rw   rn   z--folder-idz--allzIterate all notes.z--sincez"Incremental sync cursor for --all.2   	folder_idOptional[str]	all_notessincec              
     s    r	|r	t dr|st dt| |||||	|
|d t| }| }t| r8t| fdd}n|rFt|fdd}n
t|fdd}|jrZ|| dS t	|d	| dS )
zList notes.z-Choose either --folder-id or --all, not both.z"The --since option requires --all.rc   c                     s   t j dS )N)rX   )rn   	in_folderr&   )ry   rX   r0   r&   r'   r3      s    znotes_list.<locals>.<lambda>c                        t tjd S N)r|   )rn   r   iter_allr&   rX   r0   r|   r&   r'   r3          c                     s   t  ddS )NFrd   re   r&   )rX   r0   r&   r'   r3      rg   Nr   )
typerBadParameterr   r   rh   r7   r;   ri   rj   rQ   )rV   ry   r{   r|   rX   r\   r]   r^   r_   r`   ra   rb   rO   r2   rk   r&   )ry   rX   r0   r|   r'   
notes_list   sD   



r   search z--titlezExact note title.z--title-containsz&Case-insensitive note title substring.title_containsc              
     s     s  stdt| ||||||	|
d t| }| }t|t| fdd}|jr:|| dS t	|d| dS )zSearch notes by title.z1Pass --title or --title-contains to search notes.rc   c                     s   t  dS )N)r<   r   rX   )r   r&   rX   r0   r<   r   r&   r'   r3     s    znotes_search.<locals>.<lambda>NzMatching Notes)
stripr   r   r   rh   r7   r;   ri   rj   rQ   )rV   r<   r   rX   r\   r]   r^   r_   r`   ra   rb   rO   r2   rk   r&   r   r'   notes_search   s.   
	
r   get.z--with-attachmentszInclude attachment metadata.note_idwith_attachmentsc
              
     s   t | |||||||	d t| }
|
 }t|t| fdd}|
jr-|
| dS |
j|j	 d|j
 d |jrH|
jd|j  |jrU|
jd|j  |jr_|
j|j rx|jrz|
jtd	g d
dd |jD  dS dS dS )zGet one note.rc   c                     s   j  dS )N)r   )r   r&   r   r0   r   r&   r'   r3   D  s    znotes_get.<locals>.<lambda>Nz []zFolder: z
Modified: Attachments)r?   FilenameUTISizec                 S  rq   r&   )rE   filenameutisize)rJ   attr&   r&   r'   rL   U  ru   znotes_get.<locals>.<listcomp>)r   r   rh   r7   r;   ri   rj   rM   rN   r<   rE   rF   rG   textattachmentsr   )rV   r   r   r\   r]   r^   r_   r`   ra   rb   rO   r2   noter&   r   r'   	notes_get#  sF   


r   renderz--preview-appearancezPreview appearance preference.iX  z--pdf-heightzEmbedded PDF height in pixels.preview_appearance
pdf_heightc              
     sv   t | ||||||	|
d t| }| }t|t| fdd}|jr1| |d dS |jj|dd dS )zRender a note to HTML.rc   c                     s   j  jdS )N)r   pdf_object_height)render_notevaluer&   r   r0   r   r   r&   r'   r3     s
    znotes_render.<locals>.<lambda>)r   htmlNT)	soft_wrap	r   r   rh   r7   r;   ri   rj   rM   rN   )rV   r   r   r   r\   r]   r^   r_   r`   ra   rb   rO   r2   r   r&   r   r'   notes_renderZ  s*   
r   exportz--output-dirzDestination directory.z--export-modezExport mode.z--assets-dirz1Directory for downloaded assets in archival mode.Tz--full-page/--fragmentz)Wrap exported output in a full HTML page.
output_dirr   export_mode
assets_dirPath | None	full_pagec              
     sz   t | ||	|
||||d t| }| }t|t| fdd}|jr5||d dS |j| dS )zExport a note to disk.rc   c                	     s,   j tj rt nd jdS )N)r   r   r   r   r   )export_noter8   r   r&   r   r   r   r   r0   r   r   r   r&   r'   r3     s    znotes_export.<locals>.<lambda>)r   pathNr   )rV   r   r   r   r   r   r   r   r\   r]   r^   r_   r`   ra   rb   rO   r2   r   r&   r   r'   notes_export  s*   )
r   changeszSync cursor.zMaximum changes to show.
str | Nonec
              
     s   t | |||||||	d t| }
|
 }t|t| fdd}|
jr-|
| dS |
jt	dg ddd |D  dS )	z!List note changes since a cursor.rc   c                     r~   r   )rn   r   iter_changesr&   r   r&   r'   r3     r   znotes_changes.<locals>.<lambda>NzNote Changes)TypezNote IDrA   rB   c                 S  s&   g | ]}|j |jj|jj|jjfqS r&   )typer   rE   rF   rG   rI   r&   r&   r'   rL     s    z!notes_changes.<locals>.<listcomp>rv   )rV   r|   rX   r\   r]   r^   r_   r`   ra   rb   rO   r2   rk   r&   r   r'   notes_changes  s:   

r   zsync-cursorc              
     sj   t | |||||||d t| }| }	t|	 t|	 fdd}
|jr-|t|
 dS |j	|
 dS )z$Print the current Notes sync cursor.rc   c                     s      S r.   )sync_cursorr&   r/   r&   r'   r3     s    z#notes_sync_cursor.<locals>.<lambda>N)
r   r   rh   r7   r;   ri   rj   r
   rM   rN   )rV   r\   r]   r^   r_   r`   ra   rb   rO   r2   cursorr&   r/   r'   notes_sync_cursor  s$   
r   )r<   r8   r=   r>   )rV   rW   rX   rY   rZ   r[   r\   r   r]   r   r^   r   r_   r   r`   r   ra   r   rb   r   r=   r>   )rV   rW   r\   r   r]   r   r^   r   r_   r   r`   r   ra   r   rb   r   r=   r>   )rV   rW   ry   rz   r{   r[   r|   rz   rX   rY   r\   r   r]   r   r^   r   r_   r   r`   r   ra   r   rb   r   r=   r>   )rV   rW   r<   r8   r   r8   rX   rY   r\   r   r]   r   r^   r   r_   r   r`   r   ra   r   rb   r   r=   r>   )rV   rW   r   r8   r   r[   r\   r   r]   r   r^   r   r_   r   r`   r   ra   r   rb   r   r=   r>   )rV   rW   r   r8   r   r   r   rY   r\   r   r]   r   r^   r   r_   r   r`   r   ra   r   rb   r   r=   r>   ) rV   rW   r   r8   r   r   r   r)   r   r   r   r[   r   r   r   rY   r\   r   r]   r   r^   r   r_   r   r`   r   ra   r   rb   r   r=   r>   )rV   rW   r|   r   rX   rY   r\   r   r]   r   r^   r   r_   r   r`   r   ra   r   rb   r   r=   r>   )>r#   
__future__r   enumr   	itertoolsr   pathlibr   typingr   r   pyicloud.cli.contextr   r   r	   pyicloud.cli.normalizer
   r   r   pyicloud.cli.optionsr   r   r   r   r   r   r   r   r   r   pyicloud.cli.outputr   pyicloud.services.notes.servicer   r   Typerappr6   _MAX_NOTES_TO_SHOW_HELP_NOTE_ID_HELP_FOLDER_ID_HELPr8   r   r)   r7   r;   rQ   commandOptionrl   rw   r   r   Argumentr   r$   r   r,   r   r   r   r&   r&   r&   r'   <module>   sX   0
	-&>263G.