
    h5j
                    h    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
 erddlmZ  G d d	      Zy
)z9DocumentInfo dictionary access with type-safe operations.    )annotations)Iterator)TYPE_CHECKING)clean)Name)Pdfc                  @    e Zd ZdZd	dZd
dZddZddZddZddZ	y)DocinfoStorezWrapper for PDF DocumentInfo dictionary operations.

    Handles reading and writing values with proper encoding (ASCII/UTF-16)
    and character cleaning.
    c                    || _         y)ztInitialize with PDF reference.

        Args:
            pdf: The PDF document to manage DocumentInfo for.
        N)_pdf)selfpdfs     V/var/www/html/qr/venv/lib/python3.12/site-packages/pikepdf/models/metadata/_docinfo.py__init__zDocinfoStore.__init__   s     	    c                    || j                   j                  vry| j                   j                  |   }|t        |      S dS )zGet DocumentInfo value.

        Args:
            name: The DocumentInfo key (e.g., Name.Title).

        Returns:
            The value as string, or None if not present.
        N)r   docinfostr)r   namevals      r   getzDocinfoStore.get!   s@     tyy(((ii%?s3x44r   c                    | j                   j                   t        |      }	 |j                  d      | j                   j                  |<   y# t        $ r || j                   j                  |<   Y yw xY w)a  Set DocumentInfo value with proper encoding.

        Values that can be encoded as ASCII are stored as ASCII,
        otherwise stored as UTF-16 with BOM.

        Args:
            name: The DocumentInfo key (e.g., Name.Title).
            value: The string value to set.
        asciiN)r   r   r   encodeUnicodeEncodeError)r   r   values      r   setzDocinfoStore.set/   s_     			e	,&+ll7&;DIId#! 	,&+DIId#	,s   (A "A10A1c                d    || j                   j                  v r| j                   j                  |= yy)zDelete DocumentInfo key.

        Args:
            name: The DocumentInfo key to delete.

        Returns:
            True if key was present and deleted, False if not present.
        TFr   r   r   r   s     r   deletezDocinfoStore.deleteC   s.     499$$$		!!$'r   c                2    || j                   j                  v S )z$Check if key exists in DocumentInfo.r   r    s     r   __contains__zDocinfoStore.__contains__Q   s    tyy((((r   c              #  h   K   | j                   j                  j                         E d{    y7 w)zIterate DocumentInfo keys.N)r   r   keys)r   s    r   r%   zDocinfoStore.keysU   s"     99$$))+++s   (202N)r   r   )r   r   returnz
str | None)r   r   r   r   r&   None)r   r   r&   bool)r&   zIterator[Name])
__name__
__module____qualname____doc__r   r   r   r!   r#   r%    r   r   r
   r
      s%    5,(),r   r
   N)r,   
__future__r   collections.abcr   typingr   "pikepdf.models.metadata._constantsr   pikepdf.objectsr   pikepdfr   r
   r-   r   r   <module>r4      s,    @ " $   4  E, E,r   