
    )g2                        S SK r S SKrS SKrS SKJrJrJr  \(       a  S SKJr  S SKJ	r	  0 r
\R                  S:  a  S\
S'   \ R                  " SSS0\
D6 " S	 S
5      5       r\ R                  " SSS0\
D6 " S S5      5       r\" S S 5      r\" S S5      r\" SS 5      r\R%                  \\5      r\R%                  \\5      r " S S5      rg)    N)OptionalTYPE_CHECKINGIterable)Self)Deb822Element)   
   Tslotsfrozenc                   T    \ rS rSr% Sr\\S'    \\S'    \S\4S j5       rS
S jr	Sr
g	)Position   zDescribes a "cursor" position inside a file

It consists of a line position (0-based line number) and a cursor position.  This is modelled
after the "Position" in Language Server Protocol (LSP).
line_positioncursor_positionreturnc                      U R                   S-   $ )z'The line number as human would count it   )r   selfs    @/usr/lib/python3/dist-packages/debian/_deb822_repro/locatable.pyline_numberPosition.line_number'   s     !!A%%    c                 X   U R                   S:X  a  U R                  S:X  a  U$ UR                   S:X  a  UR                  S:X  a  U $ U R                   S:X  a&  UR                   nUR                  U R                  -   nO%U R                   UR                   -   nU R                  n[        UU5      $ )am  Offsets the position relative to another position

This is useful to avoid the `position_in_file()` method by caching where
the parents position and then for its children you use `range_in_parent()`
plus `relative_to()` to rebase the range.

>>> parent: Locatable = ...                   # doctest: +SKIP
>>> children: Iterable[Locatable] = ...       # doctest: +SKIP
>>> # This will expensive
>>> parent_pos = parent.position_in_file()     # doctest: +SKIP
>>> for child in children:                    # doctest: +SKIP
...    child_pos = child.position_in_parent()
...    # Avoid a position_in_file() for each child
...    child_pos_in_file = child_pos.relative_to(parent_pos)
...    ...  # Use the child_pos_in_file for something

:param new_base: The position that should have been the origin rather than
  (0, 0).
:returns: The range offset relative to the base position.
r   )r   r   r   )r   new_baser   line_char_offsets       r   relative_toPosition.relative_to,   s    * "t';';q'@O!!Q&8+C+Cq+HK""00K'77$:N:NN,,x/E/EEK#33
 	
r    N)r   r   r   r   )__name__
__module____qualname____firstlineno____doc__int__annotations__propertyr   r   __static_attributes__r   r   r   r   r      sA    
   &S & &"
r   r   c                   X   \ rS rSr% Sr\\S'   \\S'   \S\4S j5       r	\S\4S j5       r
\S\4S j5       r\S\4S	 j5       r\S\4S
 j5       r\S\4S j5       r\S\4S j5       r\S\S\SS4S j5       rS\SS 4S jrSS jr\S\SS SS4S j5       r\S\S\S    SS4S j5       rSrg)RangeQ   a  Describes a range inside a file

This can be useful to describe things like "from line 4, cursor position 2
to line 7 to cursor position 10". When describing a full line including the
newline, use line N, cursor position 0 to line N+1. cursor position 0.

It is also used to denote the size of objects (in that case, the start position
is set to START_POSITION as a convention if the precise location is not
specified).

This is modelled after the "Range" in Language Server Protocol (LSP).
	start_posend_posr   c                 .    U R                   R                  $ )z{Describes the start line position as a 0-based line number

See start_line_number if you want a human-readable line number
)r,   r   r   s    r   start_line_positionRange.start_line_positionb   s     ~~+++r   c                 .    U R                   R                  $ )zDescribes the starting cursor position

When this value is 0, the position is at the start of a line. When it is 1, then
the position is between the first and the second character (etc.).
)r,   r   r   s    r   start_cursor_positionRange.start_cursor_positionj   s     ~~---r   c                 .    U R                   R                  $ )z-The start line number as human would count it)r,   r   r   s    r   start_line_numberRange.start_line_numbers   s     ~~)))r   c                 .    U R                   R                  $ )zwDescribes the end line position as a 0-based line number

See end_line_number if you want a human-readable line number
)r-   r   r   s    r   end_line_positionRange.end_line_positionx   s     ||)))r   c                 .    U R                   R                  $ )z+The end line number as human would count it)r-   r   r   s    r   end_line_numberRange.end_line_number   s     ||'''r   c                 .    U R                   R                  $ )zDescribes the end cursor position

When this value is 0, the position is at the start of a line. When it is 1, then
the position is between the first and the second character (etc.).
)r-   r   r   s    r   end_cursor_positionRange.end_cursor_position   s     ||+++r   c                 4    U R                   U R                  -
  $ )ziThe number of lines (newlines) spanned by this range.

Will be zero when the range fits inside one line.
)r8   r/   r   s    r   
line_countRange.line_count   s     %%(@(@@@r   abr   c                     UR                   UR                   :  d4  UR                   UR                   :X  a  UR                  UR                  :  a  X!p!U " UU5      $ )aN  Computes the range between two positions

Unlike the constructor, this will always create a "positive" range.
That is, the "earliest" position will always be the start position
regardless of the order they were passed to `between`. When using
the Range constructor, you have freedom to do "inverse" ranges
in case that is ever useful
)r   r   )clsrC   rD   s      r   betweenRange.between   sO     ??Q__,OOq.13D3DqGXGX3Xq
 	
r   r   c                     U[         :X  a  U $ [        U R                  R                  U5      U R                  R                  U5      5      $ )ao  Offsets the range relative to another position

This is useful to avoid the `position_in_file()` method by caching where
the parents position and then for its children you use `range_in_parent()`
plus `relative_to()` to rebase the range.

>>> parent: Locatable = ...                   # doctest: +SKIP
>>> children: Iterable[Locatable] = ...       # doctest: +SKIP
>>> # This will expensive
>>> parent_pos = parent.position_in_file()     # doctest: +SKIP
>>> for child in children:                    # doctest: +SKIP
...    child_range = child.range_in_parent()
...    # Avoid a position_in_file() for each child
...    child_range_in_file = child_range.relative_to(parent_pos)
...    ...  # Use the child_range_in_file for something

:param new_base: The position that should have been the origin rather than
  (0, 0).
:returns: The range offset relative to the base position.
)START_POSITIONr*   r,   r   r-   )r   r   s     r   r   Range.relative_to   sB    * ~%KNN&&x0LL$$X.
 	
r   c                     U R                   [        :X  a  U $ U R                  nU(       a  U R                  nOU R                  U R                  -
  nUn[        [        [        UU5      5      $ )a  Reduces the range to a "size"

The returned range will always have its start position to (0, 0) and
its end position shifted accordingly if it was not already based at
(0, 0).

The original range is not mutated and, if it is already at (0, 0), the
method will just return it as-is.
)r,   rJ   rA   r>   r2   r*   r   )r   rA   new_end_cursor_positiondeltas       r   as_sizeRange.as_size   sg     >>^+K__
&*&>&>#,,t/I/IIE&+#'
 	
r   basesizec                     UR                   nUR                  nUR                  5       nUR                  nU(       a  X6-  nUR                  nOUR                  UR
                  -
  nXG-  nU " U[        UU5      5      $ )a  Compute a range from a position and the size of another range

This provides you with a range starting at the base position that has
the same effective span as the size parameter.

:param base: The desired starting position
:param size: A range, which will be used as a size (that is, it will
  be reduced to a size via the `as_size()` method) for the resulting
  range
:returns: A range at the provided base position that has the size of
  the provided range.
r   r   rO   rA   r>   r2   r   )rF   rQ   rR   r   r   size_rebasedlinesrN   s           r   from_position_and_sizeRange.from_position_and_size   s     **..||~''"M*>>O 44|7Y7YYE$O
 	
r   sizesc                    UR                   nUR                  nU HU  nUR                  5       nUR                  nU(       a  X7-  nUR                  nM8  UR                  UR
                  -
  nXH-  nMW     U " U[        UU5      5      $ )a  Compute a range from a position and the size of number of ranges

:param base: The desired starting position
:param sizes: All the ranges that combined makes up the size of the
  desired position. Note that order can affect the end result. Particularly
  the end character offset gets reset every time a size spans a line.
:returns: A range at the provided base position that has the size of
  the provided range.
rT   )	rF   rQ   rY   r   r   rR   rU   rV   rN   s	            r   from_position_and_sizesRange.from_position_and_sizes   s     **..D<<>L ++E&"."B"B$88<;];]](  
 	
r   r   N)r   r*   )r    r!   r"   r#   r$   r   r&   r'   r%   r/   r2   r5   r8   r;   r>   rA   classmethodrG   r   rO   rW   r   r[   r(   r   r   r   r*   r*   Q   sl    ,S , , .s . . *3 * * *3 * * ( ( ( ,S , , AC A A 
 
X 
& 
 
$
H 
 
8
4 
( 
' 
f 
 
> 
8 
HW<M 
RX 
 
r   r*   r   c                   `    \ rS rSrSr\S 5       rS\4S jrS\	4S jr
S\4S jrS\	4S jrSrg	)
	Locatablei%  r   c                     [         eNNotImplementedErrorr   s    r   parent_elementLocatable.parent_element(  s
     "!r   r   c                    ^  T R                   nUc  [        S5      e[        R                  " U 4S jUR	                  5       5      n[
        R                  [        S U 5       5      nUR                  $ )zThe start position of this token/element inside its parent

This is operation is generally linear to the number of "parts" (elements/tokens)
inside the parent.
z:Cannot determine the position since the object is detachedc                    > U TL$ ra   r   )xr   s    r   <lambda>.Locatable.position_in_parent.<locals>.<lambda>7  s	    q}r   c              3   @   #    U  H  oR                  5       v   M     g 7fra   )rR   ).0rh   s     r   	<genexpr>/Locatable.position_in_parent.<locals>.<genexpr>:  s     .~!VVXX~s   )	rd   	TypeError	itertools	takewhile
iter_partsr*   r[   rJ   r-   )r   parentrelevant_partsspans   `   r   position_in_parentLocatable.position_in_parent-  sd     $$>XYY",,-DfFWFWFYZ,,.~.
 ||r   c                 j    U R                  5       n[        R                  UU R                  5       5      $ )zThe range of this token/element inside its parent

This is operation is generally linear to the number of "parts" (elements/tokens)
inside the parent.
)rv   r*   rW   rR   )r   poss     r   range_in_parentLocatable.range_in_parent>  s1     %%'++IIK
 	
r   c                     U R                  5       nU R                  nUb!  UR                  5       nUR                  U5      nU$ )aD  The start position of this token/element in this file

This is an *expensive* operation and in many cases have to traverse
the entire file structure to answer the query.  Consider whether
you can maintain the parent's position and then use
`position_in_parent()` combined with
`child_position.relative_to(parent_position)`

)rv   rd   position_in_filer   )r   positionrs   parent_positions       r   r}   Locatable.position_in_fileJ  sF     **,$$$557O++O<Hr   c                     [         e)z/Describe the objects size as a continuous rangerb   r   s    r   rR   Locatable.size[  s    !!r   N)r    r!   r"   r#   	__slots__r'   rd   r   rv   r*   rz   r}   rR   r(   r   r   r   r_   r_   %  sI    I" "H "

 

( ""e "r   r_   r   )dataclassesrp   systypingr   r   r   r   debian._deb822_repro.parsingr   _DATA_CLASS_OPTIONAL_ARGSversion_info	dataclassr   r*   rJ   SECOND_CHAR_POSSECOND_LINE_POSrG   ONE_CHAR_RANGEONE_LINE_RANGEr_   r   r   r   <module>r      s      
 4 4:  w *.g& @d@&?@9
 9
 A9
x @d@&?@I
 I
 AI
X !Q1a.1a.~?~?8" 8"r   