Ë
    F<k¯!  ã            	       óè   — d Z ddlZddlmZmZ ddlmZ ddlmZ dZ	de	› d	e	› d
e	› d
e	› d�	Z
 G d„ d«      Z ed«      Zdeeez  dz     deeeef      fd„Zeez  eeef   z  eeeef   z  ee   z  Zy)zö
Representation and utils for ranges of PDF file pages.

Copyright (c) 2014, Steve Witham <switham_github@mac-guyver.com>.
All rights reserved. This software is available under a BSD license;
see https://github.com/py-pdf/pypdf/blob/main/LICENSE
é    N)ÚAnyÚUnioné   )Údeprecate_no_replacement)Ú
ParseErrorz(0|-?[1-9]\d*)z^(z|(z?(:z?)?)))$c                   óª   — e Zd ZdZdeed ef   ddfd„Zede	de
fd„«       Zdefd„Zdefd	„Zdefd
„Zdedeeeef   fd„Zdede
fd„Zdefd„Zdd„Zy)Ú	PageRangeaJ  
    A slice-like representation of a range of page indices.

    For example, page numbers, only starting at zero.

    The syntax is like what you would put between brackets [ ].
    The slice is one of the few Python types that can't be subclassed,
    but this class converts to and from slices, and allows similar use.

      -  PageRange(str) parses a string representing a page range.
      -  PageRange(slice) directly "imports" a slice.
      -  to_slice() gives the equivalent slice.
      -  str() and repr() allow printing.
      -  indices(n) is like slice.indices(n).
    ÚargÚreturnNc                 ó`  — t        |t        «      r"|j                  dk(  rt        |«      ‚|| _        yt        |t
        «      r|j                  «       | _        yt        |t        «      xr t        j                  t        |«      }|st        |«      ‚|j                  d«      r8t        |j                  d«      «      }|dk7  r|dz   nd}t        ||«      | _        y|j                  ddd«      D �cg c]  }|rt        |«      nd‘Œ }}|d   }|dk(  rt        |«      ‚t        |Ž | _        yc c}w )	aÓ  
        Initialize with either a slice -- giving the equivalent page range,
        or a PageRange object -- making a copy,
        or a string like
            "int", "[int]:[int]" or "[int]:[int]:[int]",
            where the brackets indicate optional ints.
        Remember, page indices start with zero.
        Page range expression examples:

            :     all pages.                   -1    last page.
            22    just the 23rd page.          :-1   all but the last page.
            0:3   the first three pages.       -2    second-to-last page.
            :3    the first three pages.       -2:   last two pages.
            5:    from the sixth page onward.  -3:-1 third & second to last.
        The third, "stride" or "step" number is also recognized.
            ::2       0 2 4 ... to the end.    3:0:-1    3 2 1 but not 0.
            1:10:2    1 3 5 7 9                2::-1     2 1 0.
            ::-1      all pages in reverse order.
        Note the difference between this notation and arguments to slice():
            slice(3) means the first three pages;
            PageRange("3") means the range of only the fourth page.
            However PageRange(slice(3)) means the first three pages.
        r   Né   éÿÿÿÿr   é   é   é   )Ú
isinstanceÚsliceÚstepr   Ú_slicer	   Úto_sliceÚstrÚreÚmatchÚPAGE_RANGE_REÚgroupÚint)Úselfr
   ÚmÚstartÚstopÚgÚboundsr   s           úR/var/www/tapir-food/flask_app/venv/lib/python3.12/site-packages/pypdf/pagerange.pyÚ__init__zPageRange.__init__%   s  € ô0 �cœ5Ô!Ø�x‰x˜1Š}Ü  “oÐ%ØˆDŒKØä�cœ9Ô%ØŸ,™,›.ˆDŒKØä�sœCÓ ÒA¤R§X¡X¬m¸SÓ%AˆÙÜ˜S“/Ð!Ø�7‰7�1Œ:ä˜Ÿ™ ›
“OˆEØ %¨¢�5˜1’9°ˆDÜ  tÓ,ˆD�Kà56·W±W¸QÀÀ1Ó5EÖF°¡”c˜!”f tÑ+ÐFˆFÐFØ˜!‘9ˆDØ�qŠyô ! “oÐ%Ü ˜.ˆD�Kùò Gs   Ã0D+Úinputc                 óŠ   — t        | t        «      ryt        | t        t        f«      sy	 t        | «       y# t        $ r Y yw xY w)zî
        True if input is a valid initializer for a PageRange.

        Args:
            input: A possible PageRange string, slice, or PageRange object.

        Returns:
            True, if the ``input`` is a valid PageRange.

        TF)r   r	   r   r   r   )r%   s    r#   ÚvalidzPageRange.validX   sH   € ô �eœYÔ'ØÜ˜%¤#¤u Ô.Øð	Ü�eÔð øô ò 	Ùð	ús   ª6 ¶	AÁAc                 ó   — | j                   S )z/Return the slice equivalent of this page range.)r   ©r   s    r#   r   zPageRange.to_slicen   s   € à�{‰{Ðó    c                 ór  — | j                   }|j                  €e|j                  �@|j                  |j                  dz   k(  r$|j                  dk7  rt	        |j                  «      S |j                  |j                  f}n#|j                  |j                  |j                  f}dj                  d„ |D «       «      S )zA string like "1:2:3".r   r   ú:c              3   ó:   K  — | ]  }|€dn
t        |«      –— Œ y ­w)NÚ )r   )Ú.0Úis     r#   ú	<genexpr>z$PageRange.__str__.<locals>.<genexpr>   s   è ø€ ÒE¸˜a˜i™¬S°«VÓ3ÑEùs   ‚)r   r   r   r    r   Újoin)r   ÚsÚindicess      r#   Ú__str__zPageRange.__str__r   s‰   € à�K‰Kˆà�6‰6ˆ>ð �w‰wÐ" q§v¡v°·±¸1±Ò'<ÀÇÁÈBÂÜ˜1Ÿ7™7“|Ð#à—g‘g˜qŸv™v�o‰Gà—g‘g˜qŸv™v q§v¡vÐ-ˆGØ�x‰xÑE¸WÔEÓEÐEr*   c                 ó6   — dt        t        | «      «      z   dz   S )z#A string like "PageRange('1:2:3')".z
PageRange(ú))Úreprr   r)   s    r#   Ú__repr__zPageRange.__repr__�   s   € àœd¤3 t£9›oÑ-°Ñ3Ð3r*   Únc                 ó8   — | j                   j                  |«      S )a/  
        Assuming a sequence of length n, calculate the start and stop indices,
        and the stride length of the PageRange.

        See help(slice.indices).

        Args:
            n:  the length of the list of pages to choose from.

        Returns:
            Arguments for range().

        )r   r4   )r   r:   s     r#   r4   zPageRange.indices…   s   € ð �{‰{×"Ñ" 1Ó%Ð%r*   Úotherc                 óV   — t        |t        «      sy| j                  |j                  k(  S )NF)r   r	   r   )r   r<   s     r#   Ú__eq__zPageRange.__eq__•   s"   € Ü˜%¤Ô+ØØ�{‰{˜eŸl™lÑ*Ð*r*   c                 ó®   — t        | j                  | j                  j                  | j                  j                  | j                  j
                  ff«      S )N)ÚhashÚ	__class__r   r   r    r   r)   s    r#   Ú__hash__zPageRange.__hash__š   s;   € Ü�T—^‘^ d§k¡k×&7Ñ&7¸¿¹×9IÑ9IÈ4Ï;É;×K[ÑK[Ð%\Ð]Ó^Ð^r*   c                 óÖ  — t        |t        «      st        dt        |«      › �«      ‚| j                  j
                  €|j                  j
                  �t        d«      ‚| j                  j                  | j                  j                  f}|j                  j                  |j                  j                  f}dt        d z  dt        fd„}dt        d z  dt        fd„} ||d   «       ||d   «       f ||d   «       ||d   «       fkD  r||}} ||d   «       ||d   «      kD  rt        d	«      ‚ ||d   «       ||d   «      kD  r|d   n|d   }t        t        |d   |«      «      S )
NzCan't add PageRange and zCan't add PageRange with strideÚvr   c                 ó    — | €t        d«      S | S )Nz-inf©Úfloat©rD   s    r#   Ú
_start_keyz%PageRange.__add__.<locals>._start_key¦   s   € Ø$% I”5˜“=Ð4°1Ð4r*   c                 ó    — | €t        d«      S | S )NÚinfrF   rH   s    r#   Ú	_stop_keyz$PageRange.__add__.<locals>._stop_key©   s   € Ø#$ 9”5˜“<Ð3°!Ð3r*   r   r   zCan't add PageRanges with gap)r   r	   Ú	TypeErrorÚtyper   r   Ú
ValueErrorr   r    r   rG   r   )r   r<   ÚaÚbrI   rL   r    s          r#   Ú__add__zPageRange.__add__�   sc  € Ü˜%¤Ô+ÜÐ6´t¸E³{°mÐDÓEÐEØ�;‰;×ÑÐ'¨5¯<©<×+<Ñ+<Ð+HÜÐ>Ó?Ð?Ø�K‰K×Ñ˜tŸ{™{×/Ñ/Ð/ˆØ�L‰L×Ñ §¡× 1Ñ 1Ð1ˆð	5œ# ™*ð 	5¬ó 	5ð	4œ˜t™ð 	4¬ó 	4ñ
 �q˜‘tÓ™y¨¨1©›Ð.Ð/±:¸aÀ¹dÓ3CÁiÐPQÐRSÑPTÃoÐEUÐ2VÒVØ�aˆqˆAñ �a˜‘dÓ™i¨¨!©›oÒ-äÐ<Ó=Ð=Ù   1¡“©°1°Q±4«Ò8ˆq�Št¸aÀ¹dˆÜœ˜q ™t TÓ*Ó+Ð+r*   )r<   r	   r   r	   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r$   Ústaticmethodr   Úboolr'   r   r5   r9   r   Útupler4   Úobjectr>   rB   rR   © r*   r#   r	   r	      s³   „ ñð 1)˜E %¨°cÐ"9Ñ:ð 1)¸tó 1)ðf ð�Sð ˜Tò ó ðð*˜%ó ðF˜ó Fð4˜#ó 4ð&˜ð &  s¨C° }Ñ!5ó &ð +˜Fð + tó +ð
_˜#ó _ô,r*   r	   r,   Úargsr   c                 ó6  — t        dd«       g }d}d}g | ¢d‘D ]}  }t        j                  |«      r0|st        d«      ‚|€J ‚|j	                  |t        |«      f«       d}ŒH|r|s|j	                  |t
        f«       t        |t        «      rJ |«       ‚|}d}Œ |S )ad  
    Given a list of filenames and page ranges, return a list of (filename, page_range) pairs.

    Args:
        args: A list where the first element is a filename. The other elements are
            filenames, page-range expressions, slice objects, or PageRange objects.
            A filename not followed by a page range indicates all pages of the file.

    Returns:
        A list of (filename, page_range) pairs.

    .. deprecated:: 7.2.0
        ``parse_filename_page_ranges`` is deprecated and will be removed in
        pypdf 8.0.0. pypdf does not use it since the ``pdfcat`` script was removed.

    Úparse_filename_page_rangesz8.0.0NFz8The first argument must be a filename, not a page range.T)r   r	   r'   rO   ÚappendÚPAGE_RANGE_ALLr   )r\   ÚpairsÚpdf_filenameÚdid_page_ranger
   s        r#   r^   r^   ¼   s¸   € ô& Ð9¸7ÔCØ)+€EØ#€LØ€NØ�ˆ}�tˆ}ò #ˆÜ�?‰?˜3ÔÙÜ ØNóð ð �?Ð"�?Ø�L‰L˜,¬	°#«Ð7Ô8Ø!‰Nñ ¡NØ—‘˜l¬NÐ;Ô<ä! #¤yÔ1Ð6°3Ó6Ð1ØˆLØ"‰Nð##ð$ €Lr*   )rV   r   Útypingr   r   Ú_utilsr   Úerrorsr   Ú_INT_REr   r	   r`   Úlistr   rY   r^   r   ÚPageRangeSpecr[   r*   r#   ú<module>rj      s¹   ðñó 
ß å ,Ý à
€Ø�W�I˜R ˜y¨¨G¨9°C¸°yÀÐH€÷b,ñ b,ñJ ˜3“€ð)Ø
ˆs�Y‰ Ñ%Ñ
&ð)à	ˆ%��Y�Ñ
Ñ ó)ðX �i‘ %¨¨S¨¡/Ñ1°E¸#¸sÀC¸-Ñ4HÑHÈ4ÐPSÉ9ÑT�r*   