
    ʆh|                         S r SrSrS/rSrSrSrSrSrS	S
K	r	S	SK
Jr  S	S
Kr\R                  S	   S:  r\(       a  \r " S S\5      rSS jrg
)a  
paginate: helps split up large collections into individual pages
================================================================

What is pagination?
---------------------

This module helps split large lists of items into pages. The user is shown one page at a time and
can navigate to other pages. Imagine you are offering a company phonebook and let the user search
the entries. The entire search result may contains 23 entries but you want to display no more than
10 entries at once. The first page contains entries 1-10, the second 11-20 and the third 21-23.
Each "Page" instance represents the items of one of these three pages.

See the documentation of the "Page" class for more information.

How do I use it?
------------------

A page of items is represented by the *Page* object. A *Page* gets initialized with these arguments:

- The collection of items to pick a range from. Usually just a list.
- The page number you want to display. Default is 1: the first page.

Now we can make up a collection and create a Page instance of it::

    # Create a sample collection of 1000 items
    >> my_collection = range(1000)

    # Create a Page object for the 3rd page (20 items per page is the default)
    >> my_page = Page(my_collection, page=3)

    # The page object can be printed as a string to get its details
    >> str(my_page)
    Page:
    Collection type:  <type 'range'>
    Current page:     3
    First item:       41
    Last item:        60
    First page:       1
    Last page:        50
    Previous page:    2
    Next page:        4
    Items per page:   20
    Number of items:  1000
    Number of pages:  50

    # Print a list of items on the current page
    >> my_page.items
    [40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59]

    # The *Page* object can be used as an iterator:
    >> for my_item in my_page: print(my_item)
    40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59

    # The .pager() method returns an HTML fragment with links to surrounding pages.
    >> my_page.pager(url="http://example.org/foo/page=$page")

    <a href="http://example.org/foo/page=1">1</a>
    <a href="http://example.org/foo/page=2">2</a>
    3
    <a href="http://example.org/foo/page=4">4</a>
    <a href="http://example.org/foo/page=5">5</a>
    ..
    <a href="http://example.org/foo/page=50">50</a>'

    # Without the HTML it would just look like:
    # 1 2 [3] 4 5 .. 50

    # The pager can be customized:
    >> my_page.pager('$link_previous ~3~ $link_next (Page $page of $page_count)',
                     url="http://example.org/foo/page=$page")

    <a href="http://example.org/foo/page=2">&lt;</a>
    <a href="http://example.org/foo/page=1">1</a>
    <a href="http://example.org/foo/page=2">2</a>
    3
    <a href="http://example.org/foo/page=4">4</a>
    <a href="http://example.org/foo/page=5">5</a>
    <a href="http://example.org/foo/page=6">6</a>
    ..
    <a href="http://example.org/foo/page=50">50</a>
    <a href="http://example.org/foo/page=4">&gt;</a>
    (Page 3 of 50)

    # Without the HTML it would just look like:
    # 1 2 [3] 4 5 6 .. 50 > (Page 3 of 50)

    # The url argument to the pager method can be omitted when an url_maker is
    # given during instantiation:
    >> my_page = Page(my_collection, page=3,
                      url_maker=lambda p: "http://example.org/%s" % p)
    >> page.pager()

There are some interesting parameters that customize the Page's behavior. See the documentation on
``Page`` and ``Page.pager()``.


Notes
-------

Page numbers and item numbers start at 1. This concept has been used because users expect that the
first page has number 1 and the first item on a page also has number 1. So if you want to use the
page's items by their index number please note that you have to subtract 1.
zChristoph Haasz3Copyright 2007-2016 Christoph Haas and contributorszMike OrrMITz0.5.4zMarcin Lulek, Luke Crooksz#info@webreactor.eu, luke@pumalo.orgBeta    N)Template   c                       \ rS rSrSr     SS jrS rS r            SS jr           SS jr	S	 r
S
 r\S 5       rSrg)Page   a"  A list/iterator representing the items on one page of a larger collection.

An instance of the "Page" class is created from a _collection_ which is any
list-like object that allows random access to its elements.

The instance works as an iterator running from the first item to the last item on the given
page. The Page.pager() method creates a link list allowing the user to go to other pages.

A "Page" does not only carry the items on a certain page. It gives you additional information
about the page in these "Page" object attributes:

item_count
    Number of items in the collection

    **WARNING:** Unless you pass in an item_count, a count will be
    performed on the collection every time a Page instance is created.

page
    Number of the current page

items_per_page
    Maximal number of items displayed on a page

first_page
    Number of the first page - usually 1 :)

last_page
    Number of the last page

previous_page
    Number of the previous page. If this is the first page it returns None.

next_page
    Number of the next page. If this is the last page it returns None.

page_count
    Number of pages

items
    Sequence/iterator of items on the current page

first_item
    Index of first item on the current page - starts with 1

last_item
    Index of last item on the current page
Nc                    Ub  Uc  Xl         OU" U5      U l         O/ U l         [        U5      U l        Ub  X`l        OU R                  U l        Xpl         [        U5      U l        U R                  S:  a  SU l        X0l
         U R                  S-
  U-  nX-   n	[        U R                   X 5      U l        Ub  X@l        O[!        U R                   5      U l        U R                  S:  GaU  SU l        U R                  S-
  U R                  -  S-   U l        U R"                  U R$                  -   S-
  U l        U R                  U R&                  :  a  U R&                  U l        O+U R                  U R"                  :  a  U R"                  U l        U R                  S-
  U-  S-   U l        [+        U R(                  U-   S-
  U R                  5      U l        U R                  U R"                  :  a  U R                  S-
  U l        OSU l        U R                  U R&                  :  a  U R                  S-   U l        O@SU l        O8SU l        SU l        SU l        SU l        SU l        SU l        SU l        / U l        [        R3                  X R                  5        g! [        [        4 a    SU l         GNLf = f! [        [        4 a2  n
[        SR                  [        U R                   5      5      5      eSn
A
ff = f)a  Create a "Page" instance.

Parameters:

collection
    Sequence representing the collection of items to page through.

page
    The requested page number - starts with 1. Default: 1.

items_per_page
    The maximal number of items to be displayed per page.
    Default: 20.

item_count (optional)
    The total number of items in the collection - if known.
    If this parameter is not given then the paginator will count
    the number of elements in the collection every time a "Page"
    is created. Giving this parameter will speed up things. In a busy
    real-life application you may want to cache the number of items.

url_maker (optional)
    Callback to generate the URL of other pages, given its numbers.
    Must accept one int parameter and return a URI string.
N   z9Your collection of type {} cannot be handled by paginate.r   )
collectiontypecollection_type	url_maker_default_url_makerkwargsintpage
ValueError	TypeErroritems_per_pagelistitemsKeyErrorformat
item_countlen
first_page
page_count	last_page
first_itemmin	last_itemprevious_page	next_page__init__)selfr   r   r   r   wrapper_classr   r   firstlastexcs              I/opt/services/DDDS/venv/lib/python3.13/site-packages/paginate/__init__.pyr%   Page.__init__   s   F !$", #0
"; DO#J/ &N!44DN 	D	DI 99q=DI,	YY]n4E)Ddooe9:DJ !(O!$//2DO ??QDO $! 38K8KKqPDO!__t>BDN yy4>>) NN	T__, OO	  $yy1}>BDO >!AA!EtWDN yy4??*%)YY]"%)"yy4>>)!%Q!% #DODO!DN"DO!DN!%D!DNDJ 	dJJ'Y I& 	DI	. )$ 	%vd4??&;< 	s*   J 2J5 J21J25K7-K22K7c                 $    SR                  U 5      $ )Na  Page:
Collection type:        {0.collection_type}
Current page:           {0.page}
First item:             {0.first_item}
Last item:              {0.last_item}
First page:             {0.first_page}
Last page:              {0.last_page}
Previous page:          {0.previous_page}
Next page:              {0.next_page}
Items per page:         {0.items_per_page}
Total number of items:  {0.item_count}
Number of pages:        {0.page_count}
)r   r&   s    r+   __str__Page.__str__=  s    7 &,	    c                 N    SR                  U R                  U R                  5      $ )Nz<paginate.Page: Page {0}/{1}>)r   r   r   r.   s    r+   __repr__Page.__repr__M  s    .55diiQQr1   c                    U	=(       d    0 n	U
=(       d    0 n
U=(       d    0 nXl         X@l        Xl        Xl        X l        U=(       d    U R
                  U l        U R                  S:X  d  U R                  S:X  a  U(       d  g[        R                  " SU5      nU(       a  UR                  S5      nOSn[        U5      nXl        U R                  UUUUUUUUU	U
US9nU R                  X5      n[        R                  " SUU5      nU R                   U R"                  :  =(       a    U R                  US   5      =(       d    SnU R                   U R$                  :  =(       a    U R                  US   5      =(       d    SnU R&                  =(       a    U R                  US	   5      =(       d    SnU R(                  =(       a    U R                  US
   5      =(       d    Sn[+        U5      R-                  U R"                  U R$                  U R                   U R                  U R.                  U R0                  U R2                  U R4                  UUUUS.5      nU$ )a  
Return string with links to other pages (e.g. '1 .. 5 6 7 [8] 9 10 11 .. 50').

format:
    Format string that defines how the pager is rendered. The string
    can contain the following $-tokens that are substituted by the
    string.Template module:

    - $first_page: number of first reachable page
    - $last_page: number of last reachable page
    - $page: number of currently selected page
    - $page_count: number of reachable pages
    - $items_per_page: maximal number of items per page
    - $first_item: index of first item on the current page
    - $last_item: index of last item on the current page
    - $item_count: total number of items
    - $link_first: link to first page (unless this is first page)
    - $link_last: link to last page (unless this is last page)
    - $link_previous: link to previous page (unless this is first page)
    - $link_next: link to next page (unless this is last page)

    To render a range of pages the token '~3~' can be used. The
    number sets the radius of pages around the current page.
    Example for a range with radius 3:

    '1 .. 5 6 7 [8] 9 10 11 .. 50'

    Default: '~2~'

url
    The URL that page links will point to. Make sure it contains the string
    $page which will be replaced by the actual page number.
    Must be given unless a url_maker is specified to __init__, in which
    case this parameter is ignored.

symbol_first
    String to be displayed as the text for the $link_first link above.

    Default: '&lt;&lt;' (<<)

symbol_last
    String to be displayed as the text for the $link_last link above.

    Default: '&gt;&gt;' (>>)

symbol_previous
    String to be displayed as the text for the $link_previous link above.

    Default: '&lt;' (<)

symbol_next
    String to be displayed as the text for the $link_next link above.

    Default: '&gt;' (>)

separator:
    String that is used to separate page links/numbers in the above range of pages.

    Default: ' '

show_if_single_page:
    if True the navigator will be shown even if there is only one page.

    Default: False

link_attr (optional)
    A dictionary of attributes that get added to A-HREF links pointing to other pages. Can
    be used to define a CSS style or class to customize the look of links.

    Example: { 'style':'border: 1px solid green' }
    Example: { 'class':'pager_link' }

curpage_attr (optional)
    A dictionary of attributes that get added to the current page number in the pager (which
    is obviously not a link). If this dictionary is not empty then the elements will be
    wrapped in a SPAN tag with the given attributes.

    Example: { 'style':'border: 3px solid blue' }
    Example: { 'class':'pager_curpage' }

dotdot_attr (optional)
    A dictionary of attributes that get added to the '..' string in the pager (which is
    obviously not a link). If this dictionary is not empty then the elements will be wrapped
    in a SPAN tag with the given attributes.

    Example: { 'style':'color: #808080' }
    Example: { 'class':'pager_dotdot' }

link_tag (optional)
    A callable that accepts single argument `page` (page link information)
    and generates string with html that represents the link for specific page.
    Page objects are supplied from `link_map()` so the keys are the same.


r   r    ~(\d+)~   )r   urlshow_if_single_page	separatorsymbol_firstsymbol_lastsymbol_previoussymbol_next	link_attrcurpage_attrdotdot_attrr   r   r#   r$   )r   r   r   r   r   r    r"   r   
link_first	link_lastlink_previous	link_next)rA   r;   r@   rB   r9   default_link_taglink_tagr   researchgroupr   radiuslink_map_rangesubr   r   r   r#   r$   r   safe_substituter   r    r"   r   )r&   r   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rH   	regex_resrL   rM   links_markupresultrC   rD   rE   rF   s                         r+   pager
Page.pagerP  s   \ O	#)r!'R(""& 9D$9$9 ??aDOOq$8ATIIj&1	__Q'FFV== 3%#+#%# ! 
 {{84 
L&9 II'QDMM(<:P,QWUW 	 II&O4==+9N+OUSU 	 K4==/1J#KQr 	 NNKt}}Xk5J'KQr	&!11"oo!^^		"oo"&"5"5"oo!^^"oo(&!.&
" r1   c           
         U	=(       d    0 n	U
=(       d    0 n
U=(       d    0 nXl         X@l        Xl        Xl        X l        [
        R                  " SU5      nU(       a  UR                  S5      nOSn[        U5      nXl	        U R                  (       a#  [        U R                  U R                  U-
  5      OSnU R                  (       a#  [        U R                  U R                  U-   5      OSnSSSSSU R                  / S.nUb  Uc  U$ S[        U5      U R                  U R                  U R!                  U R                  5      S.US'   XR                  -
  S:  a$  US   R#                  S	S
U R                  SSS.5        [%        XS-   5       H  nUU R                  :X  aa  US   R#                  S[        U5      UU R                   U R!                  U5      S.5        UU R                   SU R!                  U5      S.US'   Mt  US   R#                  S[        U5      UU R                  U R!                  U5      S.5        M     U R                  U-
  S:  a$  US   R#                  S	S
U R                  SSS.5        S[        U5      U R                  U R!                  U R                  5      U R                  S.US'   S[        U5      U R                  U R&                  =(       d    U R                  U R!                  U R&                  =(       d    U R                  5      S.US'   S[        U5      U R                  U R(                  =(       d    U R                  U R!                  U R(                  =(       d    U R                  5      S.US'   U$ )a0  Return map with links to other pages if default pager() function is not suitable solution.
format:
    Format string that defines how the pager would be normally rendered rendered. Uses same arguments as pager()
    method, but returns a simple dictionary in form of:
    {'current_page': {'attrs': {},
                             'href': 'http://example.org/foo/page=1',
                             'value': 1},
            'first_page': {'attrs': {},
                           'href': 'http://example.org/foo/page=1',
                           'type': 'first_page',
                           'value': 1},
            'last_page': {'attrs': {},
                          'href': 'http://example.org/foo/page=8',
                          'type': 'last_page',
                          'value': 8},
            'next_page': {'attrs': {}, 'href': 'HREF', 'type': 'next_page', 'value': 2},
            'previous_page': None,
            'range_pages': [{'attrs': {},
                             'href': 'http://example.org/foo/page=1',
                             'type': 'current_page',
                             'value': 1},
                             ....
                            {'attrs': {}, 'href': '', 'type': 'span', 'value': '..'}]}


    The string can contain the following $-tokens that are substituted by the
    string.Template module:

    - $first_page: number of first reachable page
    - $last_page: number of last reachable page
    - $page: number of currently selected page
    - $page_count: number of reachable pages
    - $items_per_page: maximal number of items per page
    - $first_item: index of first item on the current page
    - $last_item: index of last item on the current page
    - $item_count: total number of items
    - $link_first: link to first page (unless this is first page)
    - $link_last: link to last page (unless this is last page)
    - $link_previous: link to previous page (unless this is first page)
    - $link_next: link to next page (unless this is last page)

    To render a range of pages the token '~3~' can be used. The
    number sets the radius of pages around the current page.
    Example for a range with radius 3:

    '1 .. 5 6 7 [8] 9 10 11 .. 50'

    Default: '~2~'

url
    The URL that page links will point to. Make sure it contains the string
    $page which will be replaced by the actual page number.
    Must be given unless a url_maker is specified to __init__, in which
    case this parameter is ignored.

symbol_first
    String to be displayed as the text for the $link_first link above.

    Default: '&lt;&lt;' (<<)

symbol_last
    String to be displayed as the text for the $link_last link above.

    Default: '&gt;&gt;' (>>)

symbol_previous
    String to be displayed as the text for the $link_previous link above.

    Default: '&lt;' (<)

symbol_next
    String to be displayed as the text for the $link_next link above.

    Default: '&gt;' (>)

separator:
    String that is used to separate page links/numbers in the above range of pages.

    Default: ' '

show_if_single_page:
    if True the navigator will be shown even if there is only one page.

    Default: False

link_attr (optional)
    A dictionary of attributes that get added to A-HREF links pointing to other pages. Can
    be used to define a CSS style or class to customize the look of links.

    Example: { 'style':'border: 1px solid green' }
    Example: { 'class':'pager_link' }

curpage_attr (optional)
    A dictionary of attributes that get added to the current page number in the pager (which
    is obviously not a link). If this dictionary is not empty then the elements will be
    wrapped in a SPAN tag with the given attributes.

    Example: { 'style':'border: 3px solid blue' }
    Example: { 'class':'pager_curpage' }

dotdot_attr (optional)
    A dictionary of attributes that get added to the '..' string in the pager (which is
    obviously not a link). If this dictionary is not empty then the elements will be wrapped
    in a SPAN tag with the given attributes.

    Example: { 'style':'color: #808080' }
    Example: { 'class':'pager_dotdot' }
r7   r   r8   N)r   r   r#   r$   current_pagerL   range_pagesr   )r   valueattrsnumberhrefrX   spanz..r6   )r   rY   rZ   r\   r[   rW   )r   rY   r[   rZ   r\   )rY   rZ   r   r\   r   r   r#   r$   )rA   r;   r@   rB   r9   rI   rJ   rK   r   rL   r   maxr   r   r!   unicoder   appendranger#   r$   )r&   r   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rQ   rL   leftmost_pagerightmost_page	nav_itemsthispages                     r+   rM   Page.link_map  s?   t O	#)r!'R(""&IIj&1	__Q'FFV ;?//C$))f"46t 	 :>CV!35T 	
 ! kk
	  N$: !\*^^ooNN4??3#
	, ??*Q.m$++"!!--" ma-?@H499$-(// .!(!2"*!%!2!2 $x 8 &!..* NN84	-	.) -(// &!(!2"*!% $x 8+ AB >>N*Q.m$++"!!--"  [)^^NN4>>2nn"
	+ $_-^^((;DOONN4#5#5#HI&
	/"  [)^^nn6NN4>>#CT^^D"
	+ r1   c                    [        U R                  U R                  U-
  5      n[        U R                  U R                  U-   5      n/ nU R                  U R                  :w  aT  U R                  U:  aD  US   R                  5       n[        US   5      US'   UR                  U R                  U5      5        US    H#  nUR                  U R                  U5      5        M%     U R                  U R                  :w  aS  X@R                  :  aD  US   R                  5       n[        US   5      US'   UR                  U R                  U5      5        U R                  R                  U5      $ )zC
Return range of linked pages to substitute placeholder in pattern
r   r[   rY   rX   r   )r^   r   r   r!   r   copyr_   r`   rH   r;   join)r&   rM   rL   rb   rc   rd   r   items           r+   rN   Page._range  s&   
 DOOdii&.@BT^^dii&.@B	 99'DOOm,KL)..0D#DN3DMT]]401]+DT]]401 ,
 99&>NN+JK(--/D#DN3DMT]]401~~""9--r1   c                     U R                   c  [        S5      eSU R                   ;  a  [        S5      eU R                   R                  S[        U5      5      $ )NzGYou need to specify a 'url' parameter containing a '$page' placeholder.z$pagez7The 'url' parameter must contain a '$page' placeholder.)r9   	Exceptionreplacer_   )r&   page_numbers     r+   r   Page._default_url_maker!  sR    88Y  $(("UVVxx)=>>r1   c                     U S   nU S   nU S   (       a	  U S   S;   a   U S   (       a  [        S0 U S   D6U-   S-   nU$ [        S	XS.U S   D6$ )
z3
Create an A-HREF tag that points to another page.
rY   r\   r   )r]   rW   rZ   z</span>)textr\   )r]   )a)make_html_tag)rj   rr   
target_urls      r+   rG   Page.default_link_tag,  sg    
 G}&\
F|tF|/GGG}$=tG}=DyPKNtNWNNr1   )r   r   rA   rB   r    r   r   r   r   r   r"   r   r@   rH   r$   r   r   r#   rL   r;   r9   r   )r      NNN)~2~NF &lt;&lt;&gt;&gt;&lt;&gt;NNNN)rx   NFry   rz   r{   r|   r}   NNN)__name__
__module____qualname____firstlineno____doc__r%   r/   r3   rT   rM   rN   r   staticmethodrG   __static_attributes__ r1   r+   r   r      s    .f G(R R
 !qj !@D.8	? O Or1   r   c                     Sn[        UR                  5       5       H*  u  pEUR                  S5      nUSR                  XE5      -  nM,     SR                  X5      nU(       a  USR                  X5      -  nU$ )a  Create an HTML tag string.

tag
    The HTML tag to use (e.g. 'a', 'span' or 'div')

text
    The text to enclose between opening and closing tag. If no text is specified then only
    the opening tag is returned.

Example::
    make_html_tag('a', text="Hello", href="/another/page")
    -> <a href="/another/page">Hello</a>

To use reserved Python keywords like "class" as a parameter prepend it with
an underscore. Instead of "class='green'" use "_class='green'".

Warning: Quotes and apostrophes are not escaped.r6   _z
 {0}="{1}"z<{0}{1}>z	{0}</{1}>)sortedr   lstripr   )tagrr   paramsparams_stringkeyrY   
tag_strings          r+   rt   rt   <  sx    $ M V\\^,
 jjo--c99 - ##C7J l))$44
r1   )N)r   
__author____copyright____credits____license____version____maintainer__	__email__
__status__rI   stringr   sysversion_infoPY3strr_   r   r   rt   r   r1   r+   <module>r      sx   gR 
El,1	
 
  
 
qQGv
O4 v
Or#r1   