
    9j[                        d Z ddlmZ ddlZddlZddlZ	 ddlmZ dd	dZ
edk(  r ej                   e
              yy# e$ r 	 ddl	mZ n# e$ r	 ddlmZ Y nw xY wY Cw xY w)
=Print or replace ImageDescription in first page of TIFF file.    )annotationsN   )tiffcommentc                   t        j                  dddt         j                        }|j                  dddd	       |j	                         }|j                  d
ddd       |j                  ddt        j
                  d      dd       |j                  ddt        dd       |j                  dddd       |j                  | dn| dd       }|j                  0|j                  5  |j                  j                         }ddd       n+|j                  	 |j                  j                  d      }nd}|j                  }|-t        j                   t"              5  t        |      }ddd       d}|j$                  D ]  }	 t'        ||j(                  |       }|s t+        |t,              r|j/                  d!"      }t1        |j$                        dkD  rt3        d#|        t3        |       t1        |j$                        dkD  st3                 |S # 1 sw Y   xY w# t        $ r |j                  d       Y w xY w# 1 sw Y   xY w# t4        $ r-}	t3        | d$|	 t6        j8                  %       d}Y d}	~	d}	~	ww xY w)&z-Tiffcomment command line usage main function.r   r   zExample: tiffcomment --set "my description" image.tif
When multiple files are given with --set or --set-file, the same comment is written to all of them.)progdescriptionepilogformatter_classfiles+filezTIFF file(s) to read or modify)nargsmetavarhelpz--setcommentzreplacement comment string)destr   r   z
--set-filecomment_filerbz2path to a file whose raw bytes replace the comment)r   typer   r   z--page	pageindexNz,index of page to read or modify (default: 0)z--tagtagcodecodez>tag code or name to read or modify (default: ImageDescription)Nr   asciizMcomment contains non-ASCII characters; use --set-file with a pre-encoded filer   )r   r   replace)errorsz# z: )r   )argparseArgumentParserRawDescriptionHelpFormatteradd_argumentadd_mutually_exclusive_groupFileTypeint
parse_argsr   readr   encodeUnicodeEncodeErrorerrorr   
contextlibsuppress
ValueErrorr   r   r   
isinstancebytesdecodelenprint	Exceptionsysstderr)
argvparsercomment_groupargsr   r   retr   resultexcs
             T/media/conek/DATA/Code/OCR/venv/lib/python3.12/site-packages/tifffile/tiffcomment.pymainr=      s   $$K; !<<F -	   779M)	   t$A   ;   M	   T\TtABx@D $ 	/'',,.G	/ 	/		!	ll))'2G  $G  , 	#'lG	# C

 	 gF fe,#]])]<Ftzz?Q&Btf+&ftzz?Q&G!" JK	/ 	/
 " 	LL:		# 	#  	TF"SE"4C	sB   *HH(  I	IH%(II	I	J"JJ__main__)N)r5   zlist[str] | Nonereturnr$   )__doc__
__future__r   r   r*   r3   tifffiler   ImportErrortifffile.tifffiler=   __name__exit     r<   <module>rI      sq    D "   
)%Xv zCHHTV E  ))1 )())s3   ? A AA AA AA A 