HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/mercurial/utils/__pycache__/stringutil.cpython-310.pyc
o

�]Lb�r�@s�ddlmZddlZddlZddlZddlZddlZddlm	Z	ddl
mZddlm
Z
mZmZe�d�Zdd	�eD�Zd
d	�eD�Zdd�ZdJdd�ZdJdd�Zdd�Zdd�Zdd�Zdd�ZdKdd�ZdLdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Z ej!dd'�Gd(d)�d)e"��Z#d*d+�Z$d,d-�Z%d.d/�Z&e�'d0�Z(d1d2�Z)dMd4d5�Z*d6d7�Z+d8d9�Z,d:d;�Z-d<d=�Z.d>d?�a/dNdAdB�Z0dddddd
d
d
d
d
dC�
Z1dDdE�Z2dFdG�Z3dHdI�Z4dS)O�)�absolute_importN�)�_)�attr)�encoding�error�pycompats()[]{}?*+-|^$\.&~# 	

cCs i|]}t|�d|�d��qS)�\�latin1)�ord�decode��.0�i�r�</usr/lib/python3/dist-packages/mercurial/utils/stringutil.py�
<dictcomp>s rcCsi|]}|d|�qS)r	rr
rrrrscCs8d}t|t�rd}|�d�}|�t�}|r|S|�d�S)z"Drop-in replacement for re.escape.TFr
)�
isinstance�bytesr�	translate�_regexescapemap�encode)�pat�wantunirrr�reescape"s



rFcCsd�t||||d��S)zPretty print an object.���bprefix�indent�level)�join�	pprintgen)�orrrrrr�pprint1sr#ccs��t|t�r|rdt|�VdSdt|�VdSt|t�r*dtt|��VdSt|t�r�|s6dVdSdV|rI|d7}dVd	||Vt|�D]*\}}t||||d
�D]}|VqY|dt|�krw|rtdVd	||VqMdVqM|r�|d8}dVd	||Vd
VdSt|t��r	|s�dVdSdV|r�|d7}dVd	||Vtt	|�
���D]=\}\}}t||||d
�D]}|Vq�dVt||||d
�D]}|Vq�|dt|�kr�|r�dVd	||Vq�dVq�|�r|d8}dVd	||VdVdSt|t��rw|�sdVdSdV|�r+|d7}dVd	||Vtt	|��D]/\}}t||||d
�D]}|V�q=|dt|�k�r_|�r\dVd	||V�q1dV�q1|�rr|d8}dVd	||VdVdSt|t��r�|�s�dVdSdV|�r�|d7}dVd	||Vt|�D]/\}}t||||d
�D]}|V�q�|dt|�k�r�|�r�dVd	||V�q�dV�q�|�r�|d8}dVd	||VdVdSt|t
j��rizt|�}	Wnt�y�dVYdSwdV|�r|d7}dVd	||Vd}
|
�sS|	}zt|�}	Wnt�y,d}
Ynwt||||d
�D]}|V�q5|
�sP|�rMdVd	||VndV|
�r|�rd|d8}dVd	||Vd
VdSt�|�VdS)a�Pretty print an object to a generator of atoms.

    ``bprefix`` is a flag influencing whether bytestrings are preferred with
    a ``b''`` prefix.

    ``indent`` controls whether collections and nested data structures
    span multiple lines via the indentation amount in spaces. By default,
    no newlines are emitted.

    ``level`` specifies the initial indent level. Used if ``indent > 0``.
    sb'%s's'%s'sbytearray['%s']s[]N�[��
� rs,
s, �]s{}�{s: �}sset([])sset([s])s()�(�)sgen[]sgen[FT)rr�	escapestr�	bytearray�list�	enumerater!�len�dict�sorted�items�set�tuple�types�
GeneratorType�next�
StopIterationr�byterepr)r"rrrr�a�chunk�k�v�nextitem�last�currentrrrr!6s(�




��

�
��

�
�

�
�
��
�
�
r!cCs�g}t�|�}d}}|t|�krtd}|�d|d�}|dkr$t|�}n||dkr=|�d|d�r=|�d|d|d�}|dkrD|}n|d7}|�dd|�|�dd|�}|dks\J�|�||||���f�||}}|t|�ksd�	d	d
�|D��S)z9Pretty print a representation of a possibly-nested objectr����<r%�=r'�>r&css �|]\}}d||VqdS)s  Nr)r�l�srrr�	<genexpr>s�zprettyrepr.<locals>.<genexpr>)
rr;r1�find�
startswith�rfind�count�append�rstripr )r"�lines�rs�p0�p1�q0�q1rGrrr�
prettyrepr�s&


�rVcCsX|durdSt|t�r|dt�tj|dd��St|t�r!|St|�r(|�St|�S)arFormat an optional printable representation from unexpanded bits

    ========  =================================
    type(r)   example
    ========  =================================
    tuple     ('<not %r>', other)
    bytes     '<branch closed>'
    callable  lambda: '<branch %r>' % sorted(b)
    object    other
    ========  =================================
    Nrrr%)rr6r�rapply�maybebytestrr�callabler#)�rrrr�	buildreprs

r[cCst|od|v�S)z&return true if a string is binary data�)�bool�rHrrr�binary5�r_cCs<|�d�r
d|dd�fS|�d�rd|dd�fSd|fS)Nsre:�re�sliteral:�literal�)rK)�patternrrr�
_splitpattern:s


rfTc
s�t|�\}}|dkr8zd}|stj}t�||�}Wntjy1}zt�td�t|���d}~ww|||jfS|dkrR|rB|j	}nt
�|���fdd�}|||fSt�d|��)	a�
    accepts a string, possibly starting with 're:' or 'literal:' prefix.
    returns the matcher name, pattern, and matcher function.
    missing or unknown prefixes are treated as literal matches.

    helper for tests:
    >>> def test(pattern, *tests):
    ...     kind, pattern, matcher = stringmatcher(pattern)
    ...     return (kind, pattern, [bool(matcher(t)) for t in tests])
    >>> def itest(pattern, *tests):
    ...     kind, pattern, matcher = stringmatcher(pattern, casesensitive=False)
    ...     return (kind, pattern, [bool(matcher(t)) for t in tests])

    exact matching (no prefix):
    >>> test(b'abcdefg', b'abc', b'def', b'abcdefg')
    ('literal', 'abcdefg', [False, False, True])

    regex matching ('re:' prefix)
    >>> test(b're:a.+b', b'nomatch', b'fooadef', b'fooadefbar')
    ('re', 'a.+b', [False, False, True])

    force exact matches ('literal:' prefix)
    >>> test(b'literal:re:foobar', b'foobar', b're:foobar')
    ('literal', 're:foobar', [False, True])

    unknown prefixes are ignored and treated as literals
    >>> test(b'foo:bar', b'foo', b'bar', b'foo:bar')
    ('literal', 'foo:bar', [False, False, True])

    case insensitive regex matches
    >>> itest(b're:A.+b', b'nomatch', b'fooadef', b'fooadefBar')
    ('re', 'A.+b', [False, False, True])

    case insensitive literal matches
    >>> itest(b'ABCDEFG', b'abc', b'def', b'abcdefg')
    ('literal', 'ABCDEFG', [False, False, True])
    rar�invalid regular expression: %sNrccs�t�|�kS)N)r�lowerr^��ipatrr�<lambda>yszstringmatcher.<locals>.<lambda>�unhandled pattern kind: %s)
rf�remod�I�compiler�
ParseErrorr�forcebytestr�search�__eq__rrh�ProgrammingError)re�
casesensitive�kind�flags�regex�e�matchrrir�
stringmatcherBs*&���

r{c
Cs|t|�\}}|dkr*zt�||�WStjy)}zt�td�t|���d}~ww|dkr7t�t�|�|�St�d|��)a�Build a regexp object from a string pattern possibly starting with
    're:' or 'literal:' prefix.

    helper for tests:
    >>> def test(pattern, *tests):
    ...     regexp = substringregexp(pattern)
    ...     return [bool(regexp.search(t)) for t in tests]
    >>> def itest(pattern, *tests):
    ...     regexp = substringregexp(pattern, remod.I)
    ...     return [bool(regexp.search(t)) for t in tests]

    substring matching (no prefix):
    >>> test(b'bcde', b'abc', b'def', b'abcdefg')
    [False, False, True]

    substring pattern should be escaped:
    >>> substringregexp(b'.bc').pattern
    '\\.bc'
    >>> test(b'.bc', b'abc', b'def', b'abcdefg')
    [False, False, False]

    regex matching ('re:' prefix)
    >>> test(b're:a.+b', b'nomatch', b'fooadef', b'fooadefbar')
    [False, False, True]

    force substring matches ('literal:' prefix)
    >>> test(b'literal:re:foobar', b'foobar', b're:foobar')
    [False, True]

    case insensitive literal matches
    >>> itest(b'BCDE', b'abc', b'def', b'abcdefg')
    [False, False, True]

    case insensitive regex matches
    >>> itest(b're:A.+b', b'nomatch', b'fooadef', b'fooadefBar')
    [False, False, True]
    rargNrcrl)	rfrmrorrprrq�escapert)rerwrvryrrr�substringregexps&���r}cCs�|�d�}|dkr|d|�}|�d�}|dkr ||dd�}|�d�}|dkr/|d|�}|�d�}|dkr>|d|�}|S)z>Return a short representation of a user name or email address.�@rNrDr%r'�.�rJ��user�frrr�	shortuser�s



r�cCsD|�d�}|dkr|d|�}|�d�}|dkr ||dd�}|S)z,Return the user portion of an email address.r~rNrDr%r�r�rrr�	emailuser�s

r�cCs,|�d�}|dkrd}||�d�d|�S)zget email of author.rFrCNrDr%r�)�authorrZrrr�email�s
r�cCsVd|vr|S|�d�}|dkr|d|��d��dd�S|�d�}|d|��dd	�S)
a�Returns the name before an email address,
    interpreting it as per RFC 5322

    >>> person(b'foo@bar')
    'foo'
    >>> person(b'Foo Bar <foo@bar>')
    'Foo Bar'
    >>> person(b'"Foo Bar" <foo@bar>')
    'Foo Bar'
    >>> person(b'"Foo "buz" Bar" <foo@bar>')
    'Foo "buz" Bar'
    >>> # The following are invalid, but do exist in real-life
    ...
    >>> person(b'Foo "buz" Bar <foo@bar>')
    'Foo "buz" Bar'
    >>> person(b'"Foo Bar <foo@bar>')
    'Foo Bar'
    r~rDrCNs "s\"�"rr')rJ�strip�replace)r�r�rrr�person�s

r�)�hashc@s$eZdZdZe��Zejdd�ZdS)�mailmappingz>Represents a username/email key or value in
    a mailmap fileN)�default)�__name__�
__module__�__qualname__�__doc__r�ibr��namerrrrr��sr�cCs|p|ot|�dkS)auReturns True if the parsed names and emails
    in a mailmap entry are invalid.

    >>> # No names or emails fails
    >>> names, emails = [], []
    >>> _ismailmaplineinvalid(names, emails)
    True
    >>> # Only one email fails
    >>> emails = [b'email@email.com']
    >>> _ismailmaplineinvalid(names, emails)
    True
    >>> # One email and one name passes
    >>> names = [b'Test Name']
    >>> _ismailmaplineinvalid(names, emails)
    False
    >>> # No names but two emails passes
    >>> names = []
    >>> emails = [b'proper@email.com', b'commit@email.com']
    >>> _ismailmaplineinvalid(names, emails)
    False
    r)r1)�names�emailsrrr�_ismailmaplineinvalid�sr�cCsi}|dur|S|��D]t}|���d�rqgg}}g}|��D]6}|�d�r*n.|�d�rR|�d�rR|�|dd��|rI|�d�|��g}t|�dkrQnq!|�|�q!t||�r^qt	|dt|�dkrl|dndd	�}t	|d
|rz|d
ndd	�||<q|S)axParses data in the .mailmap format

    >>> mmdata = b"\n".join([
    ... b'# Comment',
    ... b'Name <commit1@email.xx>',
    ... b'<name@email.xx> <commit2@email.xx>',
    ... b'Name <proper@email.xx> <commit3@email.xx>',
    ... b'Name <proper@email.xx> Commit <commit4@email.xx>',
    ... ])
    >>> mm = parsemailmap(mmdata)
    >>> for key in sorted(mm.keys()):
    ...     print(key)
    mailmapping(email='commit1@email.xx', name=None)
    mailmapping(email='commit2@email.xx', name=None)
    mailmapping(email='commit3@email.xx', name=None)
    mailmapping(email='commit4@email.xx', name='Commit')
    >>> for val in sorted(mm.values()):
    ...     print(val)
    mailmapping(email='commit1@email.xx', name='Name')
    mailmapping(email='name@email.xx', name=None)
    mailmapping(email='proper@email.xx', name='Name')
    mailmapping(email='proper@email.xx', name='Name')
    N�#rDrFr%rCr'r)r�r�r)
�
splitlines�lstriprK�split�endswithrNr r1r�r�)�mailmapcontent�mailmap�liner�r��namebuilder�element�
mailmapkeyrrr�parsemailmaps>

�
��r�c	Cs�t|�r|s|Stt|�t|�d�}z||}Wnty0t|jd�}|�|tdd��}Ynwd|jr8|jn|j|jrB|jfS|jfS)a.Returns the author field according to the mailmap cache, or
    the original author field.

    >>> mmdata = b"\n".join([
    ...     b'# Comment',
    ...     b'Name <commit1@email.xx>',
    ...     b'<name@email.xx> <commit2@email.xx>',
    ...     b'Name <proper@email.xx> <commit3@email.xx>',
    ...     b'Name <proper@email.xx> Commit <commit4@email.xx>',
    ... ])
    >>> m = parsemailmap(mmdata)
    >>> mapname(m, b'Commit <commit1@email.xx>')
    'Name <commit1@email.xx>'
    >>> mapname(m, b'Name <commit2@email.xx>')
    'Name <name@email.xx>'
    >>> mapname(m, b'Commit <commit3@email.xx>')
    'Name <proper@email.xx>'
    >>> mapname(m, b'Commit <commit4@email.xx>')
    'Name <proper@email.xx>'
    >>> mapname(m, b'Unknown Name <unknown@email.com>')
    'Unknown Name <unknown@email.com>'
    )r�r�)r�Ns%s <%s>)�isauthorwellformedr�r�r��KeyError�getr�)r�r��commit�proper�commit2rrr�mapnamehs�
��r�s^[^<]+\s<[^<>]+@[^<>]+>$cCst�|�duS)a&Return True if the author field is well formed
    (ie "Contributor Name <contrib@email.dom>")

    >>> isauthorwellformed(b'Good Author <good@author.com>')
    True
    >>> isauthorwellformed(b'Author <good@author.com>')
    True
    >>> isauthorwellformed(b'Bad Author')
    False
    >>> isauthorwellformed(b'Bad Author <author@author.com')
    False
    >>> isauthorwellformed(b'Bad Author author@author.com')
    False
    >>> isauthorwellformed(b'<author@author.com>')
    False
    >>> isauthorwellformed(b'Bad Author <author>')
    False
    N)�_correctauthorformatrz)r�rrrr��sr��cCstj||dd�S)zCTrim string to at most maxlength (default: 400) columns in display.s...)�ellipsis)r�trim)�text�	maxlengthrrrr��r`r�cCs t|t�r	t|�}t�|�dS�Nr)r�
memoryviewr�codecs�
escape_encoder^rrrr-�s
r-cCst�|�dSr�)r��
escape_decoder^rrr�unescapestr�sr�c	Cs4zt�|�WStyt�t�t|���YSw)zLPortably format an arbitrary object (e.g. exception) into a byte
    string.)r�bytestr�UnicodeEncodeErrorr�
strtolocal�str)�objrrrrq�s
�rqcCst�t�|���dd�S)Ns\\r	)rr;r�r�r^rrr�uirepr�sr�cKs$Gdd�dtj�}|a|di|��S)Nc@s(eZdZdZdd�Zdd�Zdd�ZdS)	z_MBTextWrapper.<locals>.twa8
        Extend TextWrapper for width-awareness.

        Neither number of 'bytes' in any encoding nor 'characters' is
        appropriate to calculate terminal columns for specified string.

        Original TextWrapper implementation uses built-in 'len()' directly,
        so overriding is needed to use width information of each characters.

        In addition, characters classified into 'ambiguous' width are
        treated as wide in East Asian area, but as narrow in other.

        This requires use decision to determine width of such characters.
        cSsZd}tj}t�t|��D]}||||�7}||kr(|d|�||d�fSq|dfS)Nrr)r�	ucolwidthr�xranger1)�self�ucstr�
space_leftrG�colwidthrrrr�_cutdown�s�z#_MBTextWrapper.<locals>.tw._cutdowncSsXt||d�}|jr|�|d|�\}}|�|�||d<dS|s*|�|���dSdS)Nr%rC)�max�break_long_wordsr�rN�pop)r��reversed_chunks�cur_line�cur_len�widthr��cut�resrrr�_handle_long_word�s
�z,_MBTextWrapper.<locals>.tw._handle_long_wordc	Sstj}g}|jdkrtd|j��|��|r�g}d}|r!|j}n|j}|jt|�}|jr;|d�	�dkr;|r;|d=|rX||d�}|||krU|�
|���||7}nn|s=|rj||d�|krj|�||||�|jrz|rz|d�	�dkrz|d=|r�|�
|d�
|��|s|S)Nrsinvalid width %r (must be > 0)rC�)rr�r��
ValueError�reverse�subsequent_indent�initial_indentr1�drop_whitespacer�rNr�r�r )	r��chunksr�rPr�r�rr�rGrrr�_wrap_chunks�sB

����3z'_MBTextWrapper.<locals>.tw._wrap_chunksN)r�r�r�r�r�r�r�rrrr�tw�s

r�r)�textwrap�TextWrapper�_MBTextWrapper)�kwargsr�rrrr��sgr�rcCs�tt|�t|��}||krtd|d�}|�t�tj�t�tj��}|�t�tj�t�tj��}|�t�tj�t�tj��}t|||d�}|�|��	t�tj��S)N�Nr%)r�r�r�)
r�r1rr�sysstrr�encodingmoder��fillr)r�r��
initindent�
hangindent�	maxindent�wrapperrrr�wrap>s&

�

�

��r�)
�1syesstruesonsalways�0snosfalsesoffsnevercCst�|��d�S)zLParse s into a boolean.

    If s is not a valid boolean, returns None.
    N)�	_booleansr�rhr^rrr�	parseboolcsr�csV��fdd����fdd���fdd��|dur%t|t�r%�|�d��}n|}|p*gS)	z�parse a configuration value as a list of comma/space separated strings

    >>> parselist(b'this,is "a small" ,test')
    ['this', 'is', 'a small', 'test']
    csJd}|t|�kr<|||d���s|||d�dkr<d}|d7}|t|�kr<|||d���s|||d�dks|t|�krGd||fS|rN|�d�|||d�dkrc|dsc�||dfS|||d�dkr�|ddd�dkr�|ddd�|||d�|d<�||dfS|d|||d�7<�||dfS)	NFr%�,Trr�rCr	)r1�isspacerN)�partsrH�offset�
whitespace)�_parse_plain�_parse_quoterrr�rs,���

($zparselist.<locals>._parse_plaincs�|t|�krV|||d�dkrV|�d�|d7}|t|�krQ|||d���s3|||d�dkrQ|d7}|t|�krQ|||d���s3|||d�dks3�||fS|t|�kr�|||d�dkr�|||d�dkr�|dt|�kr�||d|d�dkr�|d7}|dd7<n|d|||d�7<|d7}|t|�kr�|||d�dksf|t|�krވ|d�}|s�d|d<nd|d|d<|dd�}|�|�d||fS|d7}|t|�k�r	|||d�d	v�r	|d7}|t|�k�r	|||d�d	vs�|t|�k�r7|dt|�k�r1|||d�dk�r1|dd7<|d7}n|�d�nd||fS�||fS)
Nr%r�rr�r	rrCr)r'r�)r1rNr��extend)r�rHr��
real_parts)�_configlistr�rrr��sR 
���
  �


$"�(


zparselist.<locals>._parse_quotecsB|�d�}|s	gS�dgd}}}|r||||�\}}}|s|S)Ns ,rr)rO)rH�parserr�r�)r�rrr��s
�zparselist.<locals>._configlistNs ,
)rrr�)�value�resultr)r�r�r�r�	parselistks0	r�cCs tjrt�|�d��St�|�S)z8Evaluate a string containing a Python literal expressionr
)r�ispy3�ast�literal_evalrr^rrr�evalpythonliteral�s
r�)Frr)T)r)r�)rr)5�
__future__rr�r��rermr�r7�i18nr�
thirdpartyrr�rrrr��
_respecialr�regexbytesescapemaprr#r!rVr[r_rfr{r}r�r�r�r�rH�objectr�r�r�r�ror�r�r�r-r�rqr�r�r�r�r�r�r�rrrr�<module>sl	


I

=4
S
0


l�Z