Ë
    *Rði  ã                   óâ   — d Z ddlZddlmZmZmZmZ ddlmZ dZ	dj                  e	¬«      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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/PyPDF2/blob/main/LICENSE
é    N)ÚAnyÚListÚTupleÚUnioné   )Ú
ParseErrorz(0|-?[1-9]\d*)z%^({int}|({int}?(:{int}?(:{int}?)?)))$)Úintc                   óž   — 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d„Zy)Ú	PageRangeaK  
    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|| _        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t        |j                  ddd«      D �cg c]  }|rt        |«      nd‘Œ c}Ž | _        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.
        Né   éÿÿÿÿr   é   é   é   )Ú
isinstanceÚsliceÚ_slicer   Úto_sliceÚstrÚreÚmatchÚPAGE_RANGE_REr   Úgroupr	   )Úselfr   ÚmÚstartÚstopÚgs         úK/var/www/html/Extract/venv/lib/python3.12/site-packages/PyPDF2/pagerange.pyÚ__init__zPageRange.__init__%   sÈ   € ô. �cœ5Ô!ØˆDŒKØä�cœ9Ô%ØŸ,™,›.ˆDŒKØä�sœCÓ ÒA¤R§X¡X¬m¸SÓ%AˆÙÜ˜S“/Ð!Ø�W‰W�QŒZä˜Ÿ™ ›
“OˆEØ %¨¢�5˜1’9°ˆDÜ  tÓ,ˆD�KäÀÇÁÈÈAÈqÓAQÖ!R¸A©A¤# a¤&°4Ñ"7Ò!RÐSˆD�KùÒ!Rs   ÃC;Úinputc                 óœ   — t        | t        t        f«      xs5 t        | t        «      xr# t	        t        j                  t        | «      «      S )z5True if input is a valid initializer for a PageRange.)r   r   r   r   Úboolr   r   r   )r$   s    r"   ÚvalidzPageRange.validO   s<   € ô ˜%¤%¬Ð!3Ó4ò 
Ü�uœcÓ"ÒK¤t¬B¯H©H´]ÀEÓ,JÓ'Kð	
ó    c                 ó   — | j                   S )z/Return the slice equivalent of this page range.)r   ©r   s    r"   r   zPageRange.to_sliceV   s   € à�{‰{Ðr(   c                 óT  — | j                   }|j                  €V|j                  �1|j                  |j                  dz   k(  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   ú:c              3   ó:   K  — | ]  }|€dn
t        |«      –— Œ y ­w)NÚ )r   )Ú.0Úis     r"   ú	<genexpr>z$PageRange.__str__.<locals>.<genexpr>e   s   è ø€ ÒE¸˜a˜i™¬S°«VÓ3ÑEùs   ‚)r   Ústepr   r    r   Újoin)r   ÚsÚindicess      r"   Ú__str__zPageRange.__str__Z   s}   € à�K‰Kˆà�6‰6ˆ>Ø�w‰wÐ" q§v¡v°·±¸1±Ò'<Ü˜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__g   s   € àœd¤3 t£9›oÑ-°Ñ3Ð3r(   Únc                 ó8   — | j                   j                  |«      S )zˆ
        n is the length of the list of pages to choose from.

        Returns arguments for range().  See help(slice.indices).
        )r   r5   )r   r;   s     r"   r5   zPageRange.indicesk   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   s"   € Ü˜%¤Ô+ØØ�{‰{˜eŸl™lÑ*Ð*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   |d   kD  r||}}|d   |d   kD  rt        d«      ‚t        t        |d   t        |d   |d   «      «      «      S )NzCan't add PageRange and zCan't add PageRange with strider   r   zCan't add PageRanges with gap)r   r   Ú	TypeErrorÚtyper   r2   Ú
ValueErrorr   r    r   Úmax)r   r=   ÚaÚbs       r"   Ú__add__zPageRange.__add__x   sã   € Ü˜%¤Ô+ÜÐ6´t¸E³{°mÐDÓEÐEØ�;‰;×ÑÐ'¨5¯<©<×+<Ñ+<Ð+HÜÐ>Ó?Ð?Ø�K‰K×Ñ˜tŸ{™{×/Ñ/Ð/ˆØ�L‰L×Ñ §¡× 1Ñ 1Ð1ˆàˆQ‰4�!�A‘$Š;Ø�aˆqˆAð ˆQ‰4�!�A‘$Š;äÐ<Ó=Ð=Üœ˜q ™t¤S¨¨1©¨q°©t£_Ó5Ó6Ð6r(   )r=   r   r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r#   Ústaticmethodr   r&   r'   r   r6   r:   r	   r   r5   r?   rG   © r(   r"   r   r      s¨   „ ñð"(T˜E %¨°cÐ"9Ñ:ð (T¸tó (TðT ð
�Sð 
˜Tò 
ó ð
ð˜%ó ðF˜ó Fð4˜#ó 4ð&˜ð &  s¨C° }Ñ!5ó &ð+˜Cð + Dó +ô
7r(   r   r,   Úargsr   c                 óè   — g }d}d}| dgz   D ]b  }t         j                  |«      r,|st        d«      ‚|j                  |t        |«      f«       d}ŒD|r|s|j                  |t        f«       |}d}Œd |S )a-  
    Given a list of filenames and page ranges, return a list of (filename, page_range) pairs.

    First arg must be a filename; other ags are filenames, page-range
    expressions, slice objects, or PageRange objects.
    A filename not followed by a page range indicates all pages of the file.
    NFz8The first argument must be a filename, not a page range.T)r   r'   rC   ÚappendÚPAGE_RANGE_ALL)rN   ÚpairsÚpdf_filenameÚdid_page_ranger   s        r"   Úparse_filename_page_rangesrU   �   sŒ   € ð *,€EØ€LØ€NØ�t�f‰}ò #ˆÜ�?‰?˜3ÔÙÜ ØNóð ð �L‰L˜,¬	°#«Ð7Ô8Ø!‰Nñ ¡NØ—‘˜l¬NÐ;Ô<àˆLØ"‰Nð#ð  €Lr(   )rK   r   Útypingr   r   r   r   Úerrorsr   Ú_INT_REÚformatr   r   rQ   r   rU   r	   ÚPageRangeSpecrM   r(   r"   ú<module>r[      s¬   ðñó 
ß *Ó *å à
€Ø7×>Ñ>À7Ð>ÓK€÷t7ñ t7ñn ˜3“€ðØ
ˆu�S˜) TÐ)Ñ*Ñ
+ðà	ˆ%��Y�Ñ
Ñ óð@ �c˜9 e¨C°¨H¡o°u¸SÀ#Às¸]Ñ7KÈTÐRUÉYÐVÑW�r(   