Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
pagerange.cpython-313.pyc107 linesDownload Raw Back to __pycache__
1�

2s�j��	���SrSSKrSSKJrJr SSKJr SrS\S\S	\S	\S33	r"SS5r	\	"S
5r4S\\\\	S4S\\
\\	44Sjr\\\	\
\\4\
\\\4\\4rg)z�5Representation and utils for ranges of PDF file pages.6 7Copyright (c) 2014, Steve Witham <switham_github@mac-guyver.com>.8All rights reserved. This software is available under a BSD license;9see https://github.com/py-pdf/pypdf/blob/main/LICENSE10�N)�Any�Union�)�11ParseErrorz(0|-?[1-9]\d*)z^(z|(z?(:z?)?)))$c���\rSrSrSrS\\S\4SS4Sjr\	S\12S\4Sj5rS\4S	jr
S\4S13jrS\4SjrS\S\\\\44S
jrS\S\4SjrS\4SjrSSjrSrg)�	PageRange�a14A slice-like representation of a range of page indices.15 16For example, page numbers, only starting at zero.17 18The syntax is like what you would put between brackets [ ].19The slice is one of the few Python types that can't be subclassed,20but this class converts to and from slices, and allows similar use.21 22  -  PageRange(str) parses a string representing a page range.23  -  PageRange(slice) directly "imports" a slice.24  -  to_slice() gives the equivalent slice.25  -  str() and repr() allow printing.26  -  indices(n) is like slice.indices(n).27�arg�returnNc�@�[U[5(aXlg[U[5(aUR	5Ulg[U[285=(a [R"[U5nU(d[U5eURS5(a8[URS55nUS:waUS-OSn[X45Ulg[URSSS5Vs/sHoU(a[U5OSPM sn6Ulgs snf)a+29Initialize with either a slice -- giving the equivalent page range,30or a PageRange object -- making a copy,31or a string like32    "int", "[int]:[int]" or "[int]:[int]:[int]",33    where the brackets indicate optional ints.34Remember, page indices start with zero.35Page range expression examples:36 37    :     all pages.                   -1    last page.38    22    just the 23rd page.          :-1   all but the last page.39    0:3   the first three pages.       -2    second-to-last page.40    :3    the first three pages.       -2:   last two pages.41    5:    from the sixth page onward.  -3:-1 third & second to last.42The third, "stride" or "step" number is also recognized.43    ::2       0 2 4 ... to the end.    3:0:-1    3 2 1 but not 0.44    1:10:2    1 3 5 7 9                2::-1     2 1 0.45    ::-1      all pages in reverse order.46Note the difference between this notation and arguments to slice():47    slice(3) means the first three pages;48    PageRange("3") means the range of only the fourth page.49    However PageRange(slice(3)) means the first three pages.50N������r���)�51isinstance�slice�_slicer�to_slice�str�re�match�
PAGE_RANGE_REr�group�int)�selfr52�m�start�stop�gs      �UD:\code\apps\devtools\python\user_packages\Python313\site-packages\pypdf/pagerange.py�__init__�PageRange.__init__$s���0�c�5�!�!��K���c�9�%�%��,�,�.�D�K���s�C� �A�R�X�X�m�S�%A����S�/�!��7�7�1�:�:������53�O�E� %���5�1�9��D���,�D�K������A�q�AQ�!R�AQ�A�A�#�a�&�4�"7�AQ�!R�S�D�K��!Rs�4D�inputc��[U[[45=(d; [U[5=(a$ [	[54R"[U55$)z�55True if input is a valid initializer for a PageRange.56 57Args:58    input: A possible PageRange string or a PageRange object.59 60Returns:61    True, if the ``input`` is a valid PageRange.62 63)rrrr�boolrrr)r$s r!�valid�PageRange.validOs<���%�%��!3�4�64��u�c�"�K�t�B�H�H�]�E�,J�'K�	65�c��UR$)z/Return the slice equivalent of this page range.�r�rs r!r�PageRange.to_slice_s���{�{�r)c�Z�URnURcXURb2URURS-:Xa[	UR5$URUR4nO#URURUR4nSRSU55$)zA string like "1:2:3".r�:c3�@# �UHocSO66[U5v� M g7f)N�)r)�.0�is  r!�	<genexpr>�$PageRange.__str__.<locals>.<genexpr>ns���E�W��i��S��V�3�W�s�)r�steprrr�join)r�s�indicess   r!�__str__�PageRange.__str__cs}���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�S[[U55-S-$)z#A string like "PageRange('1:2:3')".z67PageRange(�))�reprrr,s r!�__repr__�PageRange.__repr__ps���d�3�t�9�o�-��3�3r)�nc�8�URRU5$)z�68Assuming a sequence of length n, calculate the start and stop indices,69and the stride length of the PageRange.70 71See help(slice.indices).72 73Args:74    n:  the length of the list of pages to choose from.75 76Returns:77    Arguments for range().78 79)rr9)rrAs  r!r9�PageRange.indicests���{�{�"�"�1�%�%r)�otherc�`�[U[5(dgURUR:H$)NF)rrr)rrDs  r!�__eq__�PageRange.__eq__�s%���%��+�+���{�{�e�l�l�*�*r)c��[URURRURRURR80445$)N)�hash�	__class__rrrr6r,s r!�__hash__�PageRange.__hash__�s;���T�^�^�d�k�k�&7�&7����9I�9I�4�;�;�K[�K[�%\�]�^�^r)c81��[U[5(d[S[U535eURR82cURR83b[
S5eURRURR4nURRURR4nUSUS:�aX2p2USUS:�a[
S5e[[US[USUS555$)NzCan't add PageRange and zCan't add PageRange with striderrzCan't add PageRanges with gap)rr�	TypeError�typerr6�84ValueErrorrrr�max)rrD�a�bs    r!�__add__�PageRange.__add__�s����%��+�+��6�t�E�{�m�D�E�E��;�;���'�5�<�<�+<�+<�+H��>�?�?��K�K���t�{�{�/�/�/���L�L������ 1� 1�1���Q�4�!�A�$�;��q�
�Q�4�!�A�$�;��<�=�=���q��t�S��1��q��t�_�5�6�6r)r+)rDrrr)�__name__�85__module__�__qualname__�__firstlineno__�__doc__rrrr"�staticmethodrr&r'rr:r?r�tupler9�objectrFrKrT�__static_attributes__�r)r!rrs���� )T�E�%��c�"9�:�)T�t�)T�V�
86�S�
87�T�
88��
89��%��F��F�4�#�4�&��&��s�C��}�!5�&� +�F�+�t�+�90_�#�_�7r)rr/�argsrc�X�/nSnSn/UQSPH�n[RU5(a7U(d[S5eUceURU[U545 SnMTU(aU(dURU[45 [U[5(aU5eUnSnM� U$)a�91Given a list of filenames and page ranges, return a list of (filename, page_range) pairs.92 93Args:94    args: A list where the first element is a filename. The other elements are95        filenames, page-range expressions, slice objects, or PageRange objects.96        A filename not followed by a page range indicates all pages of the file.97 98Returns:99    A list of (filename, page_range) pairs.100 101NFz8The first argument must be a filename, not a page range.T)rr'rP�append�PAGE_RANGE_ALLr)r`�pairs�pdf_filename�did_page_ranger102s     r!�parse_filename_page_rangesrg�s���*,�E�%)�L��N���}�t�}���?�?�3���� �N����?�"�?��L�L�,�	�#��7�8�!�N��N����l�N�;�<�!�#�y�1�1�6�3�6�1��L�"�N�#�$�Lr))rZr�typingrr�errorsr�_INT_RErrrc�listrr\rgr�
PageRangeSpecr_r)r!�<module>rms����103���104���W�I�R��y��G�9�C��y��H�
�H7�H7�V�3���$�105�u�S�)�T�)�*�106+�$�	�%��Y��107� �$�N�c�9�e�C��H�o�u�S�#�s�]�7K�T�RU�Y�V�W�
r)
codekingpro/portable-devtools · Team Ai