
    OAi*                    N   S r SSKJr  SSKJrJr  SSKJr  SSKJ	r	J
r
Jr  SSKJr  SSKJrJrJrJr  \	(       a  SSKJr  \\l        \\l         " S	 S
\" \5      5      r " S S\5      r " S S\\S9r " S S\\S9r " S S\\S9r " S S\\S9r " S S\\S9r " S S\\S9rg)at  Provide classes to stand in for PDF objects.

The purpose of these is to provide nice-looking classes to allow explicit
construction of PDF objects and more pythonic idioms and facilitate discovery
by documentation generators and linters.

It's also a place to narrow the scope of input types to those more easily
converted to C++.

There is some deliberate "smoke and mirrors" here: all of the objects are truly
instances of ``pikepdf.Object``, which is a variant container object. The
``__new__`` constructs a ``pikepdf.Object`` in each case, and the rest of the
class definition is present as an aide for code introspection.
    )annotations)IterableMapping)token_urlsafe)TYPE_CHECKINGAnycast)_core)MatrixObject
ObjectType	Rectangle)Pdfc                  "    \ rS rSrSrSS jrSrg)_ObjectMeta-   zSupport instance checking.c                Z    [        U5      [        La  gU R                  UR                  :H  $ )NF)typer   object_type
_type_code)selfinstances     K/var/www/html/land-ocr/venv/lib/python3.13/site-packages/pikepdf/objects.py__instancecheck___ObjectMeta.__instancecheck__0   s(    >'8#6#666     N)r   r   returnbool)__name__
__module____qualname____firstlineno____doc__r   __static_attributes__r   r   r   r   r   -   s
    $7r   r   c                  6    \ rS rSrSrSS jrS	S jrS
S jrSrg)_NameObjectMeta7   z9Support usage pikepdf.Name.Whatever -> Name('/Whatever').c                v    UR                  S5      (       d  US:X  a  [        [        U5      $ [        SU-   5      $ )N_r   /)
startswithgetattrr   Name)r   attrs     r   __getattr___NameObjectMeta.__getattr__:   s4    ??34=#8;--C$Jr   c                    [        S5      e)NzgAttributes may not be set on pikepdf.Name. Perhaps you meant to modify a Dictionary rather than a Name?)AttributeError)r   r/   values      r   __setattr___NameObjectMeta.__setattr__?   s     6
 	
r   c                \    UR                  S5      (       a  USS  n[        SU SU S35      e)Nr+      zHpikepdf.Name is not subscriptable. You probably meant:
    pikepdf.Name.z
or
    pikepdf.Name('/z')
)r,   	TypeError)r   items     r   __getitem___NameObjectMeta.__getitem__H   sD    ??38D  $v &""&t-
 	
r   r   N)r/   strr   r.   )r/   r=   r4   r   r   None)r:   r=   r   r>   )	r    r!   r"   r#   r$   r0   r5   r;   r%   r   r   r   r'   r'   7   s    C 


r   r'   c                  R    \ rS rSrSr\R                  rSS jr\	SS	S jj5       r
Srg)
r.   S   a2  Construct a PDF Name object.

Names can be constructed with two notations:

    1. ``Name.Resources``

    2. ``Name('/Resources')``

The two are semantically equivalent. The former is preferred for names
that are normally expected to be in a PDF. The latter is preferred for
dynamic names and attributes.
c                    [        U[        5      (       a  [        S5      e[        U[        5      (       a  U$ [        R
                  " U5      $ )zConstruct a PDF Name.zName should be str)
isinstancebytesr9   r.   r
   	_new_nameclsnames     r   __new__Name.__new__c   s>     dE""011dD!!Kt$$r   c                N    [        U5      n[        R                  " SU U 35      $ )a  Generate a cryptographically strong, random, valid PDF Name.

If you are inserting a new name into a PDF (for example,
name for a new image), you can use this function to generate a
cryptographically strong random name that is almost certainly already
not already in the PDF, and not colliding with other existing names.

This function uses Python's secrets.token_urlsafe, which returns a
URL-safe encoded random number of the desired length. An optional
*prefix* may be prepended. (The encoding is ultimately done with
:func:`base64.urlsafe_b64encode`.) Serendipitously, URL-safe is also
PDF-safe.

When the length parameter is 16 (16 random bytes or 128 bits), the result
is probably globally unique and can be treated as never colliding with
other names.

The length of the returned string may vary because it is encoded,
but will always have ``8 * len_`` random bits.

Args:
    len_: The length of the random string.
    prefix: A prefix to prepend to the random string.
r+   )r   r
   rD   )rF   len_prefixrandom_strings       r   randomName.randomm   s(    4 &d+6(=/:;;r   r   N)rG   z
str | Namer   r.   )    )rK   intrL   r=   r   r.   )r    r!   r"   r#   r$   r   name_r   rH   classmethodrN   r%   r   r   r   r.   r.   S   s-     ""K% < <r   r.   )	metaclassc                  :    \ rS rSrSr\R                  rSS jrSr	g)Operator   a  Construct an operator for use in a content stream.

An Operator is one of a limited set of commands that can appear in PDF content
streams (roughly the mini-language that draws objects, lines and text on a
virtual PDF canvas). The commands :func:`parse_content_stream` and
:func:`unparse_content_stream` create and expect Operators respectively, along
with their operands.

pikepdf uses the special Operator "INLINE IMAGE" to denote an inline image
in a content stream.
c                B    [        S[        R                  " U5      5      $ )zConstruct an operator.rW   )r	   r
   _new_operatorrE   s     r   rH   Operator.__new__   s    J 3 3D 9::r   r   N)rG   r=   r   rW   )
r    r!   r"   r#   r$   r   operatorr   rH   r%   r   r   r   rW   rW      s    
 %%K;r   rW   c                  :    \ rS rSrSr\R                  rSS jrSr	g)String   zConstruct a PDF String object.c                    [        U[        5      (       a  [        R                  " U5      $ [        R                  " U5      $ )zConstruct a PDF String.

Args:
    s: The string to use. String will be encoded for
        PDF, bytes will be constructed without encoding.
)rB   rC   r
   _new_string_new_string_utf8)rF   ss     r   rH   String.__new__   s3     a$$Q''%%a((r   r   N)rc   zstr | bytesr   r^   )
r    r!   r"   r#   r$   r   stringr   rH   r%   r   r   r   r^   r^      s    (##K	)r   r^   c                  >    \ rS rSrSr\R                  rSSS jjrSr	g)Array   zConstruct a PDF Array object.Nc                F   [        U[        [        -  5      (       a  [        S5      eUc  / nO_[        U[        [
        -  5      (       a  UR                  5       $ [        U[        5      (       a  [        [        UR                  5       5      $ [        R                  " U5      $ )zConstruct a PDF Array.

Args:
    a: An iterable of objects. All objects must be either
        `pikepdf.Object` or convertible to `pikepdf.Object`.
z.Strings cannot be converted to arrays of chars)rB   r=   rC   r9   r   r   as_arrayrg   r	   __copy__r
   
_new_array)rF   as     r   rH   Array.__new__   sz     au%%LMM9A9v-..::<5!!qzz|,,""r   r   N)rm   z$Iterable | Rectangle | Matrix | Noner   rg   )
r    r!   r"   r#   r$   r   arrayr   rH   r%   r   r   r   rg   rg      s    '""K# #r   rg   c                  >    \ rS rSrSr\R                  rSSS jjrSr	g)
Dictionary   z"Construct a PDF Dictionary object.Nc                   U(       a  Ub  [        S5      eU(       a=  [        R                  " UR                  5        VVs0 s H  u  p4SU-   U_M     snn5      $ [	        U[
        5      (       a  UR                  5       $ U(       d  0 nU(       a0  [        S UR                  5        5       5      (       a  [        S5      e[        R                  " U5      $ s  snnf )a  Construct a PDF Dictionary.

Works from either a Python ``dict`` or keyword arguments.

These two examples are equivalent:

.. code-block:: python

    pikepdf.Dictionary({'/NameOne': 1, '/NameTwo': 'Two'})

    pikepdf.Dictionary(NameOne=1, NameTwo='Two')

In either case, the keys must be strings, and the strings
correspond to the desired Names in the PDF Dictionary. The values
must all be convertible to `pikepdf.Object`.
z1Cannot use both a mapping object and keyword argsr+   c              3  d   #    U  H&  oS :H  =(       d    UR                  S 5      (       + v   M(     g7f)r+   N)r,   ).0keys     r   	<genexpr>%Dictionary.__new__.<locals>.<genexpr>   s&     OhsCZ:s~~c':#::hs   .0z3Dictionary created from strings must begin with '/')

ValueErrorr
   _new_dictionaryitemsrB   rr   rk   anykeysKeyError)rF   dkwargskvs        r   rH   Dictionary.__new__   s    " amPQQ ((6<<>)R>4137Q;>)RSSa$$::<AOaffhOOOPQQ$$Q'' *Ss    C
r   ro   )r   zMapping | Noner   rr   )
r    r!   r"   r#   r$   r   
dictionaryr   rH   r%   r   r   r   rr   rr      s    ,''K( (r   rr   c                  >    \ rS rSrSr\R                  rSSS jjrSr	g)Stream   zConstruct a PDF Stream object.Nc                    Uc  [        S5      eSnU(       d  U(       a  [        U40 UD6n[        R                  " X5      nU(       a  XVl        U$ )a  Create a new stream object.

Streams stores arbitrary binary data and may or may not be compressed.
It also may or may not be a page or Form XObject's content stream.

A stream dictionary is like a pikepdf.Dictionary or Python dict, except
it has a binary payload of data attached. The dictionary describes
how the data is compressed or encoded.

The dictionary may be initialized just like pikepdf.Dictionary is initialized,
using a mapping object or keyword arguments.

Args:
    owner: The Pdf to which this stream shall be attached.
    data: The data bytes for the stream.
    d: An optional mapping object that will be used to construct the stream's
        dictionary.
    kwargs: Keyword arguments that will define the stream dictionary. Do not set
        /Length here as pikepdf will manage this value. Set /Filter
        if the data is already encoded in some format.

Examples:
    Using kwargs:
        >>> pdf = pikepdf.Pdf.new()
        >>> s1 = pikepdf.Stream(
        ...     pdf,
        ...     b"uncompressed image data",
        ...     BitsPerComponent=8,
        ...     ColorSpace=pikepdf.Name.DeviceRGB,
        ... )
    Using dict:
        >>> pdf = pikepdf.Pdf.new()
        >>> d = pikepdf.Dictionary(Key1=1, Key2=2)
        >>> s2 = pikepdf.Stream(
        ...     pdf,
        ...     b"data",
        ...     d
        ... )

.. versionchanged:: 2.2
    Support creation of ``pikepdf.Stream`` from existing dictionary.

.. versionchanged:: 3.0
    ``obj`` argument was removed; use ``data``.
Nz!Must make Stream from binary data)r9   rr   r
   _new_streamstream_dict)rF   ownerdatar   r   r   streams          r   rH   Stream.__new__   sM    \ <?@@$Q1&1K""5/!,r   r   )NN)r   r   r   zbytes | Noner   r   )
r    r!   r"   r#   r$   r   r   r   rH   r%   r   r   r   r   r      s    (##K8 8r   r   N)r$   
__future__r   collections.abcr   r   secretsr   typingr   r   r	   pikepdfr
   pikepdf._corer   r   r   r   r   r    r!   r   r   r'   r.   rW   r^   rg   rr   r   r   r   r   <module>r      s    # - " + +  ? ?
   
 7$v, 7
k 
85<6_ 5<p;v ;()V{ )"#Fk #0#(; #(L=V{ =r   