HEX
Server: Apache
System: Linux a16-asgard6.hospedagemuolhost.com.br 5.14.0-570.52.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Oct 15 06:39:08 EDT 2025 x86_64
User: maoristu4c3dbd03 (1436)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/lib64/python3.9/site-packages/rhsm/__pycache__/utils.cpython-39.opt-1.pyc
a

X�ZhBI�
@s$UddlZddlZddlZddlZddlZddlZddlZddlmZm	Z	m
Z
mZmZm
Z
mZddlZddlZddlmZdZeed<Gdd�dej�Zeeed�d	d
�Zeed�dd
�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�Z Gdd�de�Z!Gdd�de�Z"Gdd�de�Z#Gdd�de�Z$eed�dd �Z%eed�d!d"�Z&d?eeeeeeeeeeeefd#�d$d%�Z'e(d&�d'd(�Z)e	eed)�d*d+�Z*dd&�d,d-�Z+eed.�d/d0�Z,e-e-d1�d2d3�Z.eed4�d5d6�Z/e-e-d1�d7d8�Z0Gd9d:�d:�Z1Gd;d<�d<�Z2Gd=d>�d>e1�Z3dS)@�N)�Callable�List�Optional�TextIO�Tuple�Union�	Generator)�DEFAULT_PROXY_PORTT�PROGRESS_MESSAGESc@s$eZdZdZdZdZdZdZdZdS)�COLORzzzzz�N)	�__name__�
__module__�__qualname__ZREDZYELLOWZGREENZMAGENTAZBLUE�RESET�rr�0/usr/lib64/python3.9/site-packages/rhsm/utils.pyr&sr)�text�color�returncCs|j|tjjS�N)�valuerr)rrrrr�colorize/sr)�urircCst�dd|�S)z'Remove the scheme component from a URI.z^[A-Za-z][A-Za-z0-9+-.]*://�)�re�sub)rrrr�
remove_scheme3src@seZdZdeed�dd�ZdS)�ServerUrlParseErrorN��	serverurl�msgcCs||_||_dSrr)�selfr r!rrr�__init__9szServerUrlParseError.__init__)N)r
rr�strr#rrrrr8src@seZdZdS)�ServerUrlParseErrorEmptyN�r
rrrrrrr%>sr%c@seZdZdS)�ServerUrlParseErrorNoneNr&rrrrr'Bsr'c@seZdZdS)�ServerUrlParseErrorPortNr&rrrrr(Fsr(c@seZdZdS)�ServerUrlParseErrorPathNr&rrrrr)Jsr)c@seZdZdS)�ServerUrlParseErrorSchemeNr&rrrrr*Nsr*c@seZdZdS)�ServerUrlParseErrorJustSchemeNr&rrrrr+Rsr+c@seZdZdZdS)�UnsupportedOperationExceptionz�Thrown when a call is made that is unsupported in the current
    state.  For example, if a call is made to a deprecated API when
    a newer API is available.
    N)r
rr�__doc__rrrrr,Vsr,)�urlrcCs,d}d}t�||�rdSt�||�r(dSdS)z�Check a url for an invalid or unuseful schema.

    Don't allow urls to start with :/ http/ https/ non http/httpsm or http(s) with single /

    :params url: URL string to check
    :returns: True if the url scheme is "bad"
    z(https?[:/])|(:/)|(\S+://)z	https?://FT)r�match)r.Z	match_badZ
match_goodrrr�has_bad_scheme_sr0cCs*t�d|�}|sdS|�d�s&t|��dS)Nzhttps?://(\S+)?F�T)rr/�groupr+)r.r/rrr�has_good_schemeqs
r3)�local_server_entry�default_hostname�default_port�default_prefix�default_username�default_passwordrc
Cs�|dkrt|d��|dur$t|d��d}t|�r8t|��t|�rD|}|sPd|}tj�|�}|j}|dusr|dkrv|}|j	}	|	dur�|}	|j
}
|
dur�|}
z
|j}Wnty�t
|��Yn0|dur�|}nt|�}|j}|dus�|dkr�|}||	|
||fS)a
    Parse hostname, port, and webapp prefix from the string a user entered.
    Expected format: username:password@hostname:port/prefix
    :param local_server_entry: URL of a candlepin server
    :param default_hostname: default hostname
    :param default_port: default port
    :param default_prefix: default prefix (e.g. /candlepin)
    :param default_username: not encrypted default username
    :param default_password: not encrypted dfault password
    :return: a tuple of (username, password, hostname, port, path)
    rzServer entry is emptyNzNo server entry providedz
https://%s)r%r'r0r*r3�urllib�parse�urlparse�username�password�hostname�port�
ValueErrorr(r$�path)
r4r5r6r7r8r9Zgood_url�resultr=r>r?r@�prefixrrr�	parse_url{s@


rE�rcCs�ddddd�}d}gd�}|D]"}t�|�}|rt|td�}qBq|r�|d|d<|d|d	<|d
|d<|ddus�|ddkr�d|d
<nt|d�|d
<|S)Nr)�proxy_username�proxy_hostname�
proxy_port�proxy_passwordr)ZHTTPS_PROXYZhttps_proxyZ
HTTP_PROXYZ
http_proxy)r6rrGr1rJ�rH�rI)�os�getenvrEr	�int)Z	the_proxy�infoZenv_varsZevZ
proxy_inforrr�get_env_proxy_info�s(�

rQ)�argvrcCstj�|d�}|S)z�Attempt to get a meaningful command name from argv.

    This handles cases where argv[0] isn't helpful (for
    example, '/usr/bin/python' or '__main__.py'.
    r)rMrB�basename)rRZcmd_name_stringrrr�cmd_name�srTcCsZtj�d�ptj�d�}|durV|dkrVd�dd�|�d�D��}|tjd<|tjd<dS)z�
    This fixes no_proxy/NO_PROXY environment to not include leading
    asterisk, because there is some imperfection in proxy_bypass_environment.
    �no_proxyZNO_PROXYN�*�,cSsg|]}|�d��qS)z *)�lstrip)�.0�itemrrr�
<listcomp>�z fix_no_proxy.<locals>.<listcomp>)rM�environ�get�join�split)rUrrr�fix_no_proxy�s	
ra)�funcrcs�fdd�}|S)Ncs�d}d}d}z�ttjd�}tj}tj}|t_|t_�|i|��W|durN|t_|dur\|t_|durl|��S|dur||t_|dur�|��n.|dur�|t_|dur�|t_|dur�|��0dS)N�w)�openrM�devnull�sys�stdout�stderr�close)�args�kwargsrergrh�rbrr�wrappers:�
�z suppress_output.<locals>.wrapperr)rbrmrrlr�suppress_output
srn)�clsrcs"|j�d|_�fdd�}||_|S)z�Decorate a class to make it singleton.

    This decorator is inherited: subclasses will be singletons as well,
    but they won't be the same singleton as their parent.
    Ncs@t|j|�s:�tjur"�|�|_n�|g|�Ri|��|_|jSr)�
isinstance�	_instance�object�__new__)Zklsrjrk�Z__orig_new__rrrs+s

zsingleton.<locals>.__new__)rsrq)rorsrrtr�	singleton!s
	ru)�fnrcs<t���_d�_t����fdd��}�fdd�}||_|S)zrDecorate a function to make it callable just once.

    All further calls do not do anything and return None.
    Fcsr�jjddd�}|s&td�j�d���z:�jr>W�j��dSd�_�|i|��}|W�j��S�j��0dS)NT��?��blocking�timeout�.Could not acquire call_once lock for function �.��_call_once_lock�acquire�RuntimeErrorr
�_called�release)rjrk�lockedZ	fn_result�rvrrrm@s
�
�zcall_once.<locals>.wrappercsL�jjddd�}|s&td�j�d���zd�_W�j��n�j��0dS)z�Reset function state to allow another call to it.

        This is used for testing purposes, there is no need to call this in
        production code itself.
        Trwrxr{r|FNr})r�r�rr�_resetPszcall_once.<locals>._reset)�	threading�RLockr~r��	functools�wrapsr�)rvrmr�rr�r�	call_once8s
r�cCstt��|_d|_tdd�d�|_dd�dd�}dd�d	d
�}|d�dd�}dd�d
d�}||_||_||_||_	|S)z�Decorate a class to make it thread-safe lock.

    It will provide read-only 'locked' attribute, functions lock() and unlock()
    and __enter__/__exit__ methods for context manager functionality.
    FcSs|jSr)�_locked�r"rrr�<lambda>rr\zlock.<locals>.<lambda>)�fgetNrFcSs|j��d|_dS)z�Lock using RLock.

        One thread can acquire the lock multiple times, but other threads cannot
        until the lock is completely unlocked.
        TN)�_lockrr�r�rrr�lockts
zlock.<locals>.lockcSs:z,z|j��Wnty"Yn0Wd|_nd|_0dS)zUnlock the lock.FN)r�r�r�r�r�rrr�unlock}s
zlock.<locals>.unlockcSs|��|Sr)r�r�rrr�	__enter__�szlock.<locals>.__enter__cSs|��dSr)r�)r"�exc_typeZexc_valZexc_tbrrr�__exit__�szlock.<locals>.__exit__)
r�r�r�r��propertyr�r�r�r�r�)ror�r�r�r�rrrr�ds
	
r�c@sZeZdZdZeed�dd�Zdd�dd�Zdd�d	d
�Zdd�dd�Z	dd�d
d�Z
dS)�
StatusMessageaClass for temporary reporting.

    While you can call 'print()' and 'clean()' methods directly, the easier
    way is to use context manager: 'with StatusMessage("Fetching data"):'.

    This object will print the description to stdout when called. When the
    context manager exists (either because the code finished or because an
    error got raised inside), printed output will be cleared before the
    program continues with its execution. This ensures that the message will
    disappear after it's no longer valid.
    )�descriptioncCs�|durd}||_d}d}|�|j�|��|_d|_tj��}|�dd�dkrTd|_ts^d|_tj	�
�snd|_tj�d	d
�r�d|_dS)NzTransmitting datazrF�rhsmZprogress_messages�0TZSUBMAN_DEBUG_PRINT_REQUESTr)
�raw_textr�quietr��configZget_config_parserr^r
rfrg�isattyrMr])r"r�ZCURSIVErr�rrrr#�s 

zStatusMessage.__init__NrFcCs|jr
dSt|jdd�dS)N�
��end)r��printrr�rrrr��szStatusMessage.printcCs|jr
dStddd�dS�Nzr�r��r�r�r�rrr�clean�szStatusMessage.cleancCs|��dSr)r�r�rrrr��szStatusMessage.__enter__cCs|��|r�dSr)r��r"Z
error_typeZerror_value�	tracebackrrrr��szStatusMessage.__exit__)r
rrr-rr$r#r�r�r�r�rrrrr��sr�c@sveZdZUdZdZeeed<dZeeed<dZ	eeed<dZ
eeed	<d
Zeeed<e
eZeeed<d
S)�StatusSpinnerStyleagClass for spinner animations.

    While subscription-manager may not be using all spinners used below,
    they have been defined here, so they can be easily used in the future.

    The default spinner, LINE, has been chosen for several reasons:
    - it is small (only one character wide),
    - it has small loop cycle (so quickly switching several status messages
      looks like it is one spinner with several messages, even though every
      message has its own spinner),
    - it is only made of ASCII characters (which makes it renderable on
      all TTYs, not just rich terminal emulators in GUI).
    )�|�/�-�\�LINE)u⠋u⠙u⠸u⠴u⠦u⠇�BRAILLE)
u⠧ u⠏ u⠋⠁u⠉⠉u⠈⠙u ⠹u ⠼u⠠⠴u⠤⠤u⠦⠄�WIDE_BRAILLE)�[    ]�[=   ]�[==  ]�[=== ]�[====]�[ ===]�[  ==]�[   =]�BAR_FORWARD)r�r�r�r�r�r�r�r��BAR_BACKWARD�
BAR_BOUNCEN)
r
rrr-r�rr$�__annotations__r�r�r�r�r�rrrrr��s

r�cs�eZdZdZejddd�eeeeee	dd��fdd�Z
eeeddfd	�d
d��Z
eed	�dd
��Zejedd�dd
��Zdd	�dd�Zdd	�dd�Zdd	�dd�Zdd	�dd�Zdd	�dd�Z�ZS)�LiveStatusMessagea�Class for temporary reporting, with activity spinner.

    While you can call 'print()' and 'clean()' methods directly, the easier
    way is to use context manager: 'with LiveStatusMessage("Fetching data"):'.

    This object will print the description to stdout when called. When the
    context manager exists (either because the code finished or because an
    error got raised inside), printed output will be cleared before the
    program continues with its execution. This ensures that the message will
    disappear after it's no longer valid.

    You can set several loading styles (via class StatusSpinnerStyle) or choose
    the speed in which the animation is played (per frame, in seconds).
    �BEFOREg333333�?)�style�	placement�speedN)r�r�r�r�rcsZt��|�|j|_d|_d|_d|_d|_||_||_	|dvrPt
d|�d���||_dS)NFrT)r�ZAFTERzString z  is not valid spinner placement.)�superr#r�r�busy�_loops�_thread�_cursor�frames�delayrAr�)r"r�r�r�r���	__class__rrr#�szLiveStatusMessage.__init__rFccs|j|jt|j�VqdS)z(Get next frame of the spinner animation.N)r�r��lenr�rrr�
spinner_frameszLiveStatusMessage.spinner_framecCs|jS)zGet cursor visibility state.)r�r�rrr�cursorszLiveStatusMessage.cursor)�enablercCsLt|�turtdt|�����|r6tddd�d|_ntddd�d|_dS)	z�Enable or disable cursor.

        For more information on these rarely used shell escape codes, see
        https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_(Control_Sequence_Introducer)_sequences
        zExpected bool, got z[?25hrr�Tz[?25lFN)�type�boolrAr�r�)r"r�rrrr�"scCs4d|_|jrdSd|_tj|jd�|_|j��dS)NTF)�target)r�r�r�r��Thread�loopr��startr�rrrr�2szLiveStatusMessage.__enter__cCs6d|_|jr|r�dSd|_|jj|jd�|r2�dS)NFT)rz)r�r�r�r�r_r�r�rrrr�:szLiveStatusMessage.__exit__cCsL|jr
dSt|j�}|jdkr.|d|j}n|jd|}t|dd�dS)Nr�� r�r�)r��nextr�r�rr�)r"�frame�linerrrr�Es

zLiveStatusMessage.printcCs|jr
dStddd�dSr�r�r�rrrr�PszLiveStatusMessage.cleancCs6|jr2|��|jd7_t�|j�|��qdS)z*Show pretty animation while we fetch data.r1N)r�r�r��time�sleepr�r�r�rrrr�Us
zLiveStatusMessage.loop)r
rrr-r�r�rr$r�floatr#r�rr�r�r��setterr�r�r�r�r��
__classcell__rrr�rr��s,��r�)NNNNN)4�enumr�rMrrfr�r��typingrrrrrrr�urllib.parser:Zrhsm.configr�r	r
r�r��Enumrr$rr�	Exceptionrr%r'r(r)r*r+r,r0r3rE�dictrQrTrarnr�rur�r�r�r�r�rrrr�<module>s`
$			��N#
,25