
    \
j7                         d Z  G d d          Z G d d          Z G d d          Z G d de          Z G d	 d
e          Z G d de          Z G d de          Z G d de          ZdS )z4Run list encoding utilities.

.. versionadded:: 1.1
c                       e Zd Zd Zd ZdS )_Runc                 "    || _         || _        d S Nvaluecount)selfr   r   s      M/DATA/AppData/hermes/venv/lib/python3.11/site-packages/pyglet/text/runlist.py__init__z_Run.__init__*   s    



    c                 $    d| j         | j        fz  S )NzRun(%r, %d)r   r	   s    r
   __repr__z_Run.__repr__.   s    
DJ777r   N)__name__
__module____qualname__r   r    r   r
   r   r   )   s2          8 8 8 8 8r   r   c                   B    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
S )RunLista}  List of contiguous runs of values.

    A `RunList` is an efficient encoding of a sequence of values.  For
    example, the sequence ``aaaabbccccc`` is encoded as ``(4, a), (2, b),
    (5, c)``.  The class provides methods for modifying and querying the
    run list without needing to deal with the tricky cases of splitting and
    merging the run list entries.

    Run lists are used to represent formatted character data in pyglet.  A
    separate run list is maintained for each style attribute, for example,
    bold, italic, font size, and so on.  Unless you are overriding the
    document interfaces, the only interaction with run lists is via
    `RunIterator`.

    The length and ranges of a run list always refer to the character
    positions in the decoded list.  For example, in the above sequence,
    ``set_run(2, 5, 'x')`` would change the sequence to ``aaxxxbccccc``.
    c                 2    t          ||          g| _        dS )a
  Create a run list of the given size and a default value.

        :Parameters:
            `size` : int
                Number of characters to represent initially.
            `initial` : object
                The value of all characters in the run list.

        N)r   runs)r	   sizeinitials      r
   r   zRunList.__init__F   s     '4(()			r   c                     d}| j         D ]4}||cxk    r||j        z   k    rn n|xj        |z  c_        ||j        z  }5dS )ao  Insert characters into the run list.

        The inserted characters will take on the value immediately preceding
        the insertion point (or the value of the first character, if `pos` is
        0).

        :Parameters:
            `pos` : int
                Insertion index
            `length` : int
                Number of characters to insert.

            N)r   r   )r	   poslengthiruns        r
   insertzRunList.insertR   si     9 	 	CC((((1sy=(((((		V#		NAA	 	r   c                 R   d}| j         D ]b}||z
  dk    r nV||cxk    r||j        z   k    r6n n3t          ||z
  ||j        z   |z
            }|xj        |z  c_        ||z  }||j        z  }cd | j         D             | _         | j         st          |j        d          g| _         dS dS )zRemove characters from the run list.

        :Parameters:
            `start` : int
                Starting index to remove from.
            `end` : int
                End index, exclusive.

        r   c                 (    g | ]}|j         d k    |S r   r   .0rs     r
   
<listcomp>z"RunList.delete.<locals>.<listcomp>z       9991QWq[[Q[[[r   N)r   r   minr   r   )r	   startendr   r   trims         r
   deletezRunList.deleteg   s     9 	 	CU{aE****Q]*****3;CI(=>>		T!		tNAA99	999	 y 	-ci++,DIII	- 	-r   c                 d   ||z
  dk    rdS d}d}d}d}d}t          | j                  D ]E\  }	}
|
j        }||cxk     r	||z   k     r
n n|	}||z
  }||cxk     r	||z   k     r
n n|	}||z
  }||z  }F|]| j        |         }
| j                            |t	          |
j        |                     |
xj        |z  c_        |||k    r||z  }|dz  }|K| j        |         }
| j                            |t	          |
j        |                     |
xj        |z  c_        d}| j        D ]'}
||k    r||
j        z   |k    r||
_        ||
j        z  }(| j        d         }| j        dd         D ]0}
|
j        |j        k    r|
xj        |j        z  c_        d|_        |
}1d | j        D             | _        dS )a  Set the value of a range of characters.

        :Parameters:
            `start` : int
                Start index of range.
            `end` : int
                End of range, exclusive.
            `value` : object
                Value to set over the range.

        r   N   c                 (    g | ]}|j         d k    |S r#   r$   r%   s     r
   r(   z#RunList.set_run.<locals>.<listcomp>   r)   r   )	enumerater   r   r    r   r   )r	   r+   r,   r   r   start_i
start_trimend_iend_trimrun_ir   r   last_runs                r
   set_runzRunList.set_run   s3    ;!F 
#DI.. 	 	JE3IE5$$$$1u9$$$$$"QY
3""""U"""""7JAA )G$CIWd39j&A&ABBBII#II G##
*H
)E"CIUDH$=$=>>>II!II 9 	 	Czza#)ms22!	NAA 9Q<9QRR= 	 	CyHN**		X^+		!"HH :9	999			r   c              #   ^   K   d}| j         D ] }|||j        z   |j        fV  ||j        z  }!d S Nr   )r   r   r   )r	   r   r   s      r
   __iter__zRunList.__iter__   sN      9 	 	CQ]CI----NAA	 	r   c                      t          |           S )zSGet an extended iterator over the run list.

        :rtype: `RunIterator`
        )RunIteratorr   s    r
   get_run_iteratorzRunList.get_run_iterator   s    
 4   r   c                     d}| j         D ]-}||cxk    r||j        z   k     rn n	|j        c S ||j        z  }.||k    r| j         d         j        S t          )zGet the value at a character position.

        :Parameters:
            `index` : int
                Index of character.  Must be within range and non-negative.

        :rtype: object
        r   )r   r   r   
IndexError)r	   indexr   r   s       r
   __getitem__zRunList.__getitem__   s}     9 	 	CE))))A	M)))))y   NAA A::9R=&&r   c                 :    t          t          |                     S r   )strlistr   s    r
   r   zRunList.__repr__   s    4::r   N)r   r   r   __doc__r   r    r.   r9   r<   r?   rD   r   r   r   r
   r   r   2   s         &
* 
* 
*  *- - -2=: =: =:~  ! ! !  *    r   r   c                       e Zd ZdZd Zd ZdS )AbstractRunIteratora  Range iteration over `RunList`.

    `AbstractRunIterator` objects allow any monotonically non-decreasing
    access of the iteration, including repeated iteration over the same index.
    Use the ``[index]`` operator to get the value at a particular index within
    the document.  For example::

        run_iter = iter(run_list)
        value = run_iter[0]
        value = run_iter[0]       # non-decreasing access is OK
        value = run_iter[15]
        value = run_iter[17]
        value = run_iter[16]      # this is illegal, the index decreased.

    Using `AbstractRunIterator` to access increasing indices of the value runs
    is more efficient than calling `RunList.__getitem__` repeatedly.

    You can also iterate over monotonically non-decreasing ranges over the
    iteration.  For example::
        
        run_iter = iter(run_list)
        for start, end, value in run_iter.ranges(0, 20):
            pass
        for start, end, value in run_iter.ranges(25, 30):
            pass
        for start, end, value in run_iter.ranges(30, 40):
            pass

    Both start and end indices of the slice are required and must be positive.
    c                     dS )zGet the value at a given index.

        See the class documentation for examples of valid usage.

        :Parameters:
            `index` : int   
                Document position to query.

        :rtype: object
        Nr   r	   rC   s     r
   rD   zAbstractRunIterator.__getitem__        r   c                     dS )ac  Iterate over a subrange of the run list.

        See the class documentation for examples of valid usage.

        :Parameters:
            `start` : int
                Start index to iterate from.
            `end` : int
                End index, exclusive.

        :rtype: iterator
        :return: Iterator over (start, end, value) tuples.
        Nr   r	   r+   r,   s      r
   rangeszAbstractRunIterator.ranges  rM   r   N)r   r   r   rH   rD   rP   r   r   r
   rJ   rJ      s<         >
 
 
    r   rJ   c                   &    e Zd Zd Zd Zd Zd ZdS )r>   c                 r    t          |          | _        t          |           \  | _        | _        | _        d S r   )iter_run_list_iternextr+   r,   r   )r	   run_lists     r
   r   zRunIterator.__init__"  s,    "8nn+/::(
DHdjjjr   c                 *    t          | j                  S r   )rU   rT   r   s    r
   __next__zRunIterator.__next__&  s    D'(((r   c                     	 || j         k    rC|| j        k    r8t          |           \  | _        | _         | _        || j         k    r|| j        k    8| j        S # t          $ r t
          w xY wr   )r,   r+   rU   r   StopIterationrB   rL   s     r
   rD   zRunIterator.__getitem__)  s~    	48##
(:(:37::0
DHdj 48##
(:(: : 	 	 		s   AA A)c              #     K   	 || j         k    r-t          |           \  | _        | _         | _        || j         k    -|t	          | j         |          | j        fV  || j         k    rSt          |           \  | _        | _         | _        | j        t	          | j         |          | j        fV  || j         k    Qd S d S # t
          $ r Y d S w xY wr   )r,   rU   r+   r   r*   rZ   rO   s      r
   rP   zRunIterator.ranges2  s      	48##37::0
DHdj 48##TXs++TZ7777..37::0
DHdjj#dh"4"4dj@@@@ ......  	 	 	FF	s   B3B; ;
C	C	N)r   r   r   r   rX   rD   rP   r   r   r
   r>   r>   !  sP        6 6 6) ) )  	 	 	 	 	r   r>   c                   $    e Zd ZdZd Zd Zd ZdS )OverriddenRunIteratorzYIterator over a `RunIterator`, with a value temporarily replacing
    a given range.
    c                 >    || _         || _        || _        || _        dS )a  Create a derived iterator.

        :Parameters:
            `start` : int
                Start of range to override
            `end` : int
                End of range to override, exclusive
            `value` : object
                Value to replace over the range

        N)rS   override_startoverride_endoverride_value)r	   base_iteratorr+   r,   r   s        r
   r   zOverriddenRunIterator.__init__C  s)     "	##r   c              #     K   || j         k    s|| j        k    r$| j                            ||          D ]}|V  d S || j         cxk     r|k     r*n n'| j                            || j                   D ]}|V  t	          | j         |          t          | j        |          | j        fV  || j        cxk     r|k     r+n d S | j                            | j        |          D ]}|V  d S d S r   )r_   r`   rS   rP   maxr*   ra   )r	   r+   r,   r'   s       r
   rP   zOverriddenRunIterator.rangesT  sR     $%%%$2C)C)CY%%eS11    t*0000S00000))%1DEE  AGGGGt*E22t(#..&( ( ( ( t(....3......))$*;SAA  AGGGG /. r   c                 ^    | j         |cxk    r| j        k     r
n n| j        S | j        |         S r   )r_   r`   ra   rS   rL   s     r
   rD   z!OverriddenRunIterator.__getitem__e  s@    %;;;;$*;;;;;;&&9U##r   Nr   r   r   rH   r   rP   rD   r   r   r
   r]   r]   >  sK         $ $ $"  "$ $ $ $ $r   r]   c                   $    e Zd ZdZd Zd Zd ZdS )FilteredRunIteratorz`Iterate over an `AbstractRunIterator` with filtered values replaced
    by a default value.
    c                 0    || _         || _        || _        dS )a  Create a filtered run iterator.

        :Parameters:
            `base_iterator` : `AbstractRunIterator`
                Source of runs.
            `filter` : ``lambda object: bool``
                Function taking a value as parameter, and returning ``True``
                if the value is acceptable, and ``False`` if the default value
                should be substituted.
            `default` : object
                Default value to replace filtered values.

        NrS   filterdefault)r	   rb   rk   rl   s       r
   r   zFilteredRunIterator.__init__q  s     "	r   c              #      K   | j                             ||          D ]/\  }}}|                     |          r|||fV  #||| j        fV  0d S r   )rS   rP   rk   rl   )r	   r+   r,   r   s       r
   rP   zFilteredRunIterator.ranges  sz      !%!1!1%!=!= 	/ 	/E3{{5!! /S%'''''S$,.....		/ 	/r   c                 X    | j         |         }|                     |          r|S | j        S r   rj   )r	   rC   r   s      r
   rD   zFilteredRunIterator.__getitem__  s/    	% ;;u 	L|r   Nrf   r   r   r
   rh   rh   l  sK           $/ / /    r   rh   c                   $    e Zd ZdZd Zd Zd ZdS )ZipRunIteratorz1Iterate over multiple run iterators concurrently.c                     || _         d S r   range_iterators)r	   rs   s     r
   r   zZipRunIterator.__init__  s    .r   c              #     K   	 fd| j         D             }t          d |D              \  }}}t          |          }t          |          }t          |          }k     r]t          |          }||fV  |t	          |          D ]-\  }}	||         |k    rt          |	          \  ||<   ||<   ||<   .k     [d S d S # t          $ r Y d S w xY w)Nc                 <    g | ]}|                               S r   )rP   )r&   r   r,   r+   s     r
   r(   z)ZipRunIterator.ranges.<locals>.<listcomp>  s'    LLL!%--LLLr   c                 ,    g | ]}t          |          S r   )rU   )r&   r   s     r
   r(   z)ZipRunIterator.ranges.<locals>.<listcomp>  s    (D(D(DQa(D(D(Dr   )rs   ziprG   r*   r2   rU   rZ   )
r	   r+   r,   	iteratorsstartsendsvaluesmin_endr   iterators
    ``       r
   rP   zZipRunIterator.ranges  s     	LLLLLt7KLLLI#&(D(D)(D(D(D#E FD&&\\F::D&\\F#++d))Wf,,,,#,Y#7#7 G GKAxAw'))8<X5q	47F1I #++++++  	 	 	FF	s   B9C 
CCc                 *    fd| j         D             S )Nc                      g | ]
}|         S r   r   )r&   r   rC   s     r
   r(   z.ZipRunIterator.__getitem__.<locals>.<listcomp>  s    777Q%777r   rr   rL   s    `r
   rD   zZipRunIterator.__getitem__  s     7777$"67777r   Nrf   r   r   r
   rp   rp     sG        ;;/ / /  "8 8 8 8 8r   rp   c                   *    e Zd ZdZd Zd Zd Zd ZdS )ConstRunIteratorz9Iterate over a constant value without creating a RunList.c                 0    || _         || _        || _        d S r   )r   r,   r   )r	   r   r   s      r
   r   zConstRunIterator.__init__  s    


r   c              #   ,   K   d| j         | j        fV  d S r;   )r   r   r   s    r
   rX   zConstRunIterator.__next__  s#      dj((((((r   c              #   "   K   ||| j         fV  d S r   r   rO   s      r
   rP   zConstRunIterator.ranges  s!      S$*$$$$$$r   c                     | j         S r   r   rL   s     r
   rD   zConstRunIterator.__getitem__  s
    zr   N)r   r   r   rH   r   rX   rP   rD   r   r   r
   r   r     sV        CC  
) ) )% % %    r   r   N)	rH   r   r   rJ   r>   r]   rh   rp   r   r   r   r
   <module>r      su  F 8 8 8 8 8 8 8 8p p p p p p p pf9 9 9 9 9 9 9 9x    %   :+$ +$ +$ +$ +$/ +$ +$ +$\" " " " "- " " "J8 8 8 8 8( 8 8 86    *     r   