
    %h                         S r SSKrSSKJrJrJrJr  SSKJr  Sr	SR                  \	S9r " S	 S
5      r\" S5      rS\\\\S4      S\\\\4      4S jr\\\\\\4   \\\\4   \\   4   rg)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                       \ rS rSrSrS\\S \4   SS4S jr\	S\
S\4S j5       rS\4S	 jrS\4S
 jrS\4S jrS\S\\\\4   4S jrS\
S\4S jrSS jrSrg)	PageRange   a  
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                 @   [        U[        5      (       a  Xl        g[        U[        5      (       a  UR	                  5       U l        g[        U[
        5      =(       a    [        R                  " [        U5      nU(       d  [        U5      eUR                  S5      (       a8  [        UR                  S5      5      nUS:w  a  US-   OSn[        X45      U l        g[        UR                  SSS5       Vs/ s H  oU(       a  [        U5      OSPM     sn6 U l        gs  snf )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         H/var/www/auris/envauris/lib/python3.13/site-packages/PyPDF2/pagerange.py__init__PageRange.__init__%   s    . c5!!Kc9%%,,.DKsC ARXXmS%AS/!WWQZZ
OE %519D,DKAqAQ!RAQAA#a&4"7AQ!RSDK!Rs   4Dinputc                     [        U [        [        45      =(       d;    [        U [        5      =(       a$    [	        [
        R                  " [        U 5      5      $ )z5True if input is a valid initializer for a PageRange.)r   r   r   r   boolr   r   r   )r&   s    r#   validPageRange.validO   s<     %%!34 
uc"KtBHH]E,J'K	
    c                     U R                   $ )z/Return the slice equivalent of this page range.r   r   s    r#   r   PageRange.to_sliceV   s    {{r+   c                 Z   U R                   nUR                  cX  UR                  b2  UR                  UR                  S-   :X  a  [	        UR                  5      $ UR                  UR                  4nO#UR                  UR                  UR                  4nSR                  S U 5       5      $ )zA string like "1:2:3".r   :c              3   @   #    U  H  oc  SO
[        U5      v   M     g 7f)N )r   ).0is     r#   	<genexpr>$PageRange.__str__.<locals>.<genexpr>e   s     EWiSV3Ws   )r   stepr    r!   r   join)r   sindicess      r#   __str__PageRange.__str__Z   s}    KK66>ww"qvv1'<177|#ggqvvoGggqvvqvv-GxxEWEEEr+   c                 6    S[        [        U 5      5      -   S-   $ )z#A string like "PageRange('1:2:3')".z
PageRange())reprr   r.   s    r#   __repr__PageRange.__repr__g   s    d3t9o-33r+   nc                 8    U R                   R                  U5      $ )zp
n is the length of the list of pages to choose from.

Returns arguments for range().  See help(slice.indices).
)r   r;   )r   rC   s     r#   r;   PageRange.indicesk   s     {{""1%%r+   otherc                 `    [        U[        5      (       d  gU R                  UR                  :H  $ )NF)r   r   r   )r   rF   s     r#   __eq__PageRange.__eq__s   s%    %++{{ell**r+   c           
         [        U[        5      (       d  [        S[        U5       35      eU R                  R
                  c  UR                  R
                  b  [        S5      eU R                  R                  U R                  R                  4nUR                  R                  UR                  R                  4nUS   US   :  a  X2p2US   US   :  a  [        S5      e[        [        US   [        US   US   5      5      5      $ )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   r8   
ValueErrorr    r!   r   max)r   rF   abs       r#   __add__PageRange.__add__x   s    %++6tE{mDEE;;'5<<+<+<+H>??KKt{{///LL 1 11Q4!A$;q Q4!A$;<==qtS1qt_566r+   r-   )rF   r   r   r   )__name__
__module____qualname____firstlineno____doc__r   r   r   r$   staticmethodr   r(   r)   r   r<   rA   r	   r   r;   rH   rQ   __static_attributes__ r+   r#   r   r      s    "(TE%c"9: (Tt (TT 
S 
T 
 
% F F4# 4& &sC}!5 &+C +D +
7r+   r   r1   argsr   c                    / nSnSnU S/-    Hx  n[         R                  U5      (       a2  U(       d  [        S5      eUR                  U[        U5      45        SnMO  U(       a  U(       d  UR                  U[        45        UnSnMz     U$ )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)   rM   appendPAGE_RANGE_ALL)r[   pairspdf_filenamedid_page_ranger   s        r#   parse_filename_page_rangesrb      s     *,ELNtf}??3 N  LL,	#78!N NlN;<L"N   Lr+   )rW   r   typingr   r   r   r   errorsr   _INT_REformatr   r   r^   r   rb   r	   PageRangeSpecrZ   r+   r#   <module>rh      s    
 * * 
7>>7>Kt7 t7n 3
uS)T)*
+	%Y
 @ c9eCHouS#s]7KTRUYVWr+   