+
    Ti              	           R t ^ RIt^ RIHtHt ^RIHt RtR] R] R] R] R2	t ! R	 R
4      t	]	! R4      t
R R lt]]]	]]]3,          ]]]]3,          ]],          3,          tR# )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)
ParseErrorz(0|-?[1-9]\d*)z^(z|(z?(:z?)?)))$c                      a  ] tR t^t o RtV 3R lR lt]V 3R lR l4       tV 3R lR ltV 3R lR	 lt	V 3R
 lR lt
V 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltRtV tR# )	PageRangea  
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).
c                <   < V ^8  d   QhRS[ S[RS[3,          RR/# )   argr   returnN)r   slicestr)format__classdict__s   "Z/home/kuhnn/.local/share/uv/tools/nano-pdf/lib/python3.14/site-packages/pypdf/pagerange.py__annotate__PageRange.__annotate__$   s+     )T )TE%c"9: )Tt )T    c                ^   \        V\        4      '       d	   Wn        R# \        V\        4      '       d   VP	                  4       V n        R# \        V\
        4      ;'       d    \        P                  ! \        V4      pV'       g   \        V4      hVP                  ^4      '       d?   \        VP                  ^4      4      pVR8w  d
   V^,           MRp\        W44      V n        R# \        VP                  ^^^4       Uu. uF  qU'       d   \        V4      MRNK  	  up!  V n        R# u upi )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)
isinstancer   _slicer   to_slicer   rematchPAGE_RANGE_REr   groupint)selfr	   mstartstopgs   &&    r   __init__PageRange.__init__$   s    0 c5!!Kc9%%,,.DKsC AARXXmS%AS/!771::
OE %519D,DKAqAQ!RAQAA#a&4"7AQ!RSDK!Rs   D*c                &   < V ^8  d   QhRS[ RS[/# )r   inputr
   )r   bool)r   r   s   "r   r   r   P   s     
 
S 
T 
r   c                    \        V \        \        34      ;'       g=    \        V \        4      ;'       d%    \	        \
        P                  ! \        V 4      4      # )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.

)r   r   r   r   r&   r   r   r   )r%   s   &r   validPageRange.validO   sD     %%!34 
 
uc"KKtBHH]E,J'K	
r   c                    < V ^8  d   QhRS[ /# r   r
   )r   )r   r   s   "r   r   r   _   s      % r   c                    V P                   # )z/Return the slice equivalent of this page range.r   r   s   &r   r   PageRange.to_slice_   s    {{r   c                    < V ^8  d   QhRS[ /# r+   r   )r   r   s   "r   r   r   c   s     F F Fr   c                h   V P                   pVP                  f_   VP                  e8   VP                  VP                  ^,           8X  d   \	        VP                  4      # VP                  VP                  3pM#VP                  VP                  VP                  3pRP                  R V 4       4      # )zA string like "1:2:3".:c              3   B   "   T F  qf   RM
\        V4      x  K  	  R # 5i)N r1   ).0is   & r   	<genexpr>$PageRange.__str__.<locals>.<genexpr>n   s     EWiSV3Ws   )r   stepr   r    r   join)r   sindicess   &  r   __str__PageRange.__str__c   s}    KK66>ww"qvv1'<177|#ggqvvoGggqvvqvv-GxxEWEEEr   c                    < V ^8  d   QhRS[ /# r+   r1   )r   r   s   "r   r   r   p   s     4 4# 4r   c                F    R\        \        V 4      4      ,           R,           # )z#A string like "PageRange('1:2:3')".z
PageRange())reprr   r.   s   &r   __repr__PageRange.__repr__p   s    d3t9o-33r   c                @   < V ^8  d   QhRS[ RS[S[ S[ S[ 3,          /# )r   nr
   )r   tuple)r   r   s   "r   r   r   t   s&     & & &sC}!5 &r   c                8    V P                   P                  V4      # )z
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   r=   )r   rG   s   &&r   r=   PageRange.indicest   s     {{""1%%r   c                &   < V ^8  d   QhRS[ RS[/# )r   otherr
   )objectr&   )r   r   s   "r   r   r      s     + +F +t +r   c                d    \        V\        4      '       g   R # V P                  VP                  8H  # )F)r   r   r   )r   rL   s   &&r   __eq__PageRange.__eq__   s%    %++{{ell**r   c                    < V ^8  d   QhRS[ /# r+   )r   )r   r   s   "r   r   r      s     _ _# _r   c                    \        V P                  V P                  P                  V P                  P                  V P                  P
                  334      # )N)hash	__class__r   r   r    r:   r.   s   &r   __hash__PageRange.__hash__   s;    T^^dkk&7&79I9I4;;K[K[%\]^^r   c                "   < V ^8  d   QhRRRR/# )r   rL   r   r
    )r   r   s   "r   r   r      s     7 7[ 7[ 7r   c           
     X   \        V\        4      '       g   \        R \        V4       24      hV P                  P
                  f   VP                  P
                  e   \        R4      hV P                  P                  V P                  P                  3pVP                  P                  VP                  P                  3pV^ ,          V^ ,          8  d   Y2r2V^ ,          V^,          8  d   \        R4      h\        \        V^ ,          \        V^,          V^,          4      4      4      # )zCan't add PageRange and zCan't add PageRange with stridezCan't add PageRanges with gap)r   r   	TypeErrortyper   r:   
ValueErrorr   r    r   max)r   rL   abs   &&  r   __add__PageRange.__add__   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-   N)__name__
__module____qualname____firstlineno____doc__r"   staticmethodr(   r   r>   rD   r=   rO   rU   r`   __static_attributes____classdictcell__)r   s   @r   r   r      su      )T )TV 
 
 F F4 4& & + +
_ _7 7r   r   r3   c                    V ^8  d   QhR\         \        \        \        R3,          ,          R\         \        \        \        3,          ,          /# )r   argsNr
   )listr   r   r   rH   )r   s   "r   r   r      s;     $ $
uS)T)*
+$	%Y
 $r   c                d   . pRpRp. V ORN F  p\         P                  V4      '       d:   V'       g   \        R4      hVf   Q hVP                  V\        V4      34       RpKW  V'       d    V'       g   VP                  V\        34       \        V\         4      '       d   Q V4       hTpRpK  	  V# )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(   r\   appendPAGE_RANGE_ALLr   )rk   pairspdf_filenamedid_page_ranger	   s   &    r   parse_filename_page_rangesrs      s     *,E%)LN}t}??3 N  ?"?LL,	#78!N NlN;<!#y116361L"N# $ Lr   )rf   r   typingr   r   errorsr   _INT_REr   r   ro   rs   r   rH   r   rl   PageRangeSpecrX   r   r   <module>rx      s    
  
WIRyG9CyHH7 H7V 3$N c9eCHouS#s]7KTRUYVWr   