§
    õ(Âjã  ã            	       ó  — d Z ddlZddlmZmZ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e
df                  deeee
f                  fd„Zeee
eeef         eeeef         ee         f         ZdS )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ÚOptionalÚUnioné   )Ú
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dS )Ú	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                 óp  — t          |t          ¦  «        r	|| _        dS t          |t          ¦  «        r|                     ¦   «         | _        dS t          |t
          ¦  «        ot          j        t          |¦  «        }|st          |¦  «        ‚| 
                    d¦  «        rFt          | 
                    d¦  «        ¦  «        }|dk    r|dz   nd}t          ||¦  «        | _        dS d„ | 
                    ddd¦  «        D ¦   «         }|d         }|d	k    rt          |¦  «        ‚t          |Ž | _        dS )
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.
        Né   éÿÿÿÿr   c                 ó4   — g | ]}|rt          |¦  «        nd ‘ŒS ©N)Úint)Ú.0Úgs     ú6/tmp/pip-target-1l1kndlc/lib/python/pypdf/pagerange.pyú
<listcomp>z&PageRange.__init__.<locals>.<listcomp>M   s'   € ÐFÐFÐF° Ð+•c˜!‘f”f�f tÐFÐFÐFó    é   é   é   r   )Ú
isinstanceÚsliceÚ_slicer	   Úto_sliceÚstrÚreÚmatchÚPAGE_RANGE_REr   Úgroupr   )Úselfr
   ÚmÚstartÚstopÚboundsÚsteps          r   Ú__init__zPageRange.__init__$   s  € õ0 �c�5Ñ!Ô!ð 	ØˆDŒKØˆFå�c�9Ñ%Ô%ð 	ØŸ,š,™.œ.ˆDŒKØˆFå�s�CÑ Ô ÐA¥R¤X­m¸SÑ%AÔ%AˆØð 	"Ý˜S‘/”/Ð!Ø�7Š7�1‰:Œ:ð 	)å˜Ÿš ™
œ
‘O”OˆEØ %¨¢ �5˜1‘9�9°ˆDÝ  tÑ,Ô,ˆDŒKˆKˆKàFÐF°Q·W²W¸QÀÀ1Ñ5EÔ5EÐFÑFÔFˆFØ˜!”9ˆDØ�qŠyˆyõ ! ‘o”oÐ%Ý ˜.ˆDŒKˆKˆKr   Úinputc                 ó´   — t          | t          t          f¦  «        rdS t          | t          ¦  «        sdS 	 t          | ¦  «         n# t          $ r Y dS w xY wdS )zè
        True if input is a valid initializer for a PageRange.

        Args:
            input: A possible PageRange string or a PageRange object.

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

        TF)r   r   r	   r   r   )r*   s    r   ÚvalidzPageRange.validU   st   € õ �e�e¥YÐ/Ñ0Ô0ð 	Ø�4Ý˜%¥Ñ%Ô%ð 	Ø�5ð	Ý�eÑÔÐÐøÝð 	ð 	ð 	Ø�5�5ð	øøøàˆts   ·A Á
AÁAc                 ó   — | j         S )z/Return the slice equivalent of this page range.)r   ©r#   s    r   r   zPageRange.to_slicek   s
   € àŒ{Ðr   c                 óþ   — | j         }|j        €=|j        �'|j        |j        dz   k    rt	          |j        ¦  «        S |j        |j        f}n|j        |j        |j        f}d                     d„ |D ¦   «         ¦  «        S )zA string like "1:2:3".Nr   ú:c              3   ó<   K  — | ]}|€dnt          |¦  «        V — Œd S )NÚ )r   )r   Úis     r   ú	<genexpr>z$PageRange.__str__.<locals>.<genexpr>z   s0   è è € ÐEÐE¸˜a˜i˜˜­S°©V¬VÐEÐEÐEÐEÐEÐEr   )r   r(   r%   r&   r   Újoin)r#   ÚsÚindicess      r   Ú__str__zPageRange.__str__o   sz   € àŒKˆàŒ6ˆ>ØŒwÐ" q¤v°´¸1±Ò'<Ð'<Ý˜1œ7‘|”|Ð#à”g˜qœv�oˆGˆGà”g˜qœv q¤vÐ-ˆGØ�xŠxÐEÐE¸WÐEÑEÔEÑEÔEÐEr   c                 óF   — 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¤9™oœoÑ-°Ñ3Ð3r   Únc                 ó6   — | 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   r7   )r#   r=   s     r   r7   zPageRange.indices€   s   € ð Œ{×"Ò" 1Ñ%Ô%Ð%r   Úotherc                 óP   — t          |t          ¦  «        sdS | j        |j        k    S )NF)r   r	   r   )r#   r?   s     r   Ú__eq__zPageRange.__eq__�   s(   € Ý˜%¥Ñ+Ô+ð 	Ø�5ØŒ{˜eœlÒ*Ð*r   c                 óp   — t          | j        | j        j        | j        j        | j        j        ff¦  «        S r   )ÚhashÚ	__class__r   r%   r&   r(   r.   s    r   Ú__hash__zPageRange.__hash__•   s-   € Ý�T”^ d¤kÔ&7¸¼Ô9IÈ4Ì;Ô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          t                   dt          fd„}dt          t                   dt          fd„} ||d         ¦  «         ||d         ¦  «        k    r||}} ||d         ¦  «         ||d         ¦  «        k    rt          d	¦  «        ‚ ||d         ¦  «         ||d         ¦  «        k    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¦  «        n| S )Nz-inf©Úfloat©rG   s    r   Ú
_start_keyz%PageRange.__add__.<locals>._start_key¡   s   € Ø$% I•5˜‘=”=�=°1Ð4r   c                 ó(   — | €t          d¦  «        n| S )NÚinfrI   rK   s    r   Ú	_stop_keyz$PageRange.__add__.<locals>._stop_key¤   s   € Ø#$ 9•5˜‘<”<�<°!Ð3r   r   r   zCan't add PageRanges with gap)r   r	   Ú	TypeErrorÚtyper   r(   Ú
ValueErrorr%   r&   r   r   rJ   r   )r#   r?   ÚaÚbrL   rO   r&   s          r   Ú__add__zPageRange.__add__˜   s�  € Ý˜%¥Ñ+Ô+ð 	FÝÐDµt¸E±{´{ÐDÐDÑEÔEÐEØŒ;ÔÐ'¨5¬<Ô+<Ð+HÝÐ>Ñ?Ô?Ð?ØŒKÔ˜tœ{Ô/Ð/ˆØŒLÔ ¤Ô 1Ð1ˆð	5�(¥3œ-ð 	5­Eð 	5ð 	5ð 	5ð 	5ð	4�¥#œð 	4­5ð 	4ð 	4ð 	4ð 	4ð ˆ:�a˜”dÑÔ˜j˜j¨¨1¬Ñ.Ô.Ò.Ð.Ø�aˆqˆAð ˆ:�a˜”dÑÔ˜i˜i¨¨!¬™oœoÒ-Ð-åÐ<Ñ=Ô=Ð=Ø �y  1¤‘”¨¨°1°Q´4©¬Ò8Ð8ˆq�Œtˆt¸aÀ¼dˆÝ�˜q œt TÑ*Ô*Ñ+Ô+Ð+r   )r?   r	   r   r	   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r)   Ústaticmethodr   Úboolr,   r   r8   r<   r   Útupler7   ÚobjectrA   rE   rU   © r   r   r	   r	      sT  € € € € € ðð ð /)˜E %¨°cÐ"9Ô:ð /)¸tð /)ð /)ð /)ð /)ðb ð�Sð ˜Tð ð ð ñ „\ðð*˜%ð ð ð ð ðF˜ð Fð Fð Fð Fð4˜#ð 4ð 4ð 4ð 4ð&˜ð &  s¨C° }Ô!5ð &ð &ð &ð &ð +˜Fð + tð +ð +ð +ð +ð
_˜#ð _ð _ð _ð _ð,ð ,ð ,ð ,ð ,ð ,r   r	   r0   Úargsr   c                 óV  — g }d}d}g | ¢d‘D ]›}t                                |¦  «        r<|st          d¦  «        ‚|€J ‚|                     |t          |¦  «        f¦  «         d}ŒX|r|s|                     |t          f¦  «         t          |t           ¦  «        r
J |¦   «         ‚|}d}Œœ|S )a©  
    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.

    NFz8The first argument must be a filename, not a page range.T)r	   r,   rR   ÚappendÚPAGE_RANGE_ALLr   )r_   ÚpairsÚpdf_filenameÚdid_page_ranger
   s        r   Úparse_filename_page_rangesrf   µ   sá   € ð *,€EØ%)€LØ€NØ�ˆ}�tˆ}ð #ð #ˆÝ�?Š?˜3ÑÔð 	#Øð Ý ØNñô ð ð �?�?�?Ø�LŠL˜,­	°#©¬Ð7Ñ8Ô8Ð8Ø!ˆNˆNð ð = Nð =Ø—’˜l­NÐ;Ñ<Ô<Ð<å! #¥yÑ1Ô1Ð6Ð6°3Ñ6Ô6Ð6ØˆLØ"ˆNˆNØ€Lr   )rY   r   Útypingr   r   r   Úerrorsr   Ú_INT_REr!   r	   rb   Úlistr   r\   rf   r   ÚPageRangeSpecr^   r   r   ú<module>rl      s.  ððð ð 
€	€	€	Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'à Ð Ð Ð Ð Ð à
€ØH�WÐHÐH ÐHÐH¨GÐHÐH¸ÐHÐHÐH€ð\,ð \,ð \,ð \,ð \,ñ \,ô \,ð \,ð~ �˜3‘”€ð$Ø
ˆu�S˜) TÐ)Ô*Ô
+ð$à	ˆ%��Y�Ô
Ô ð$ð $ð $ð $ðN �c˜9 e¨C°¨H¤o°u¸SÀ#Às¸]Ô7KÈTÐRUÌYÐVÔW€€€r   