
    Bj0                        U d dl mZ d dlmZ d dlmZ d dlZd dlZ ej                         Z	da
ded<   ddZdd	Zedd
       ZddZy)    )annotations)Iterator)contextmanagerN	base58btcstr_default_encodingc                     t         S )zEReturn the current default multibase encoding (e.g. ``'base58btc'``).)r        9/Users/sumanjeet/code/py-libp2p/libp2p/encoding_config.pyget_default_encodingr      s    r   c                    t        j                  |       s4dj                  t        j                               }t	        d| d|       t
        5  | addd       y# 1 sw Y   yxY w)u  
    Set the process-wide default multibase encoding.

    Writes are protected by an internal lock.  Reads via
    :func:`get_default_encoding` are **not** locked, so a concurrent
    reader may briefly see a stale value.

    Parameters
    ----------
    encoding : str
        A multibase encoding name recognised by *py-multibase*
        (e.g. ``'base58btc'``, ``'base32'``, ``'base64'``,
        ``'base64url'``, …).

    Raises
    ------
    ValueError
        If *encoding* is not supported by *py-multibase*.

    z, zUnsupported encoding z. Supported encodings: N)	multibaseis_encoding_supportedjoinlist_encodings
ValueError_lockr   )encoding	supporteds     r   set_default_encodingr      sg    . **84IIi6689	#H</FykR
 	
 
 %$% % %s   AA%c              #     K   t               }t        |        	 d t        5  |addd       y# 1 sw Y   yxY w# t        5  |addd       w # 1 sw Y   w xY wxY ww)ur  
    Temporarily override the default encoding within a ``with`` block.

    The previous encoding is restored when the block exits—even on exceptions.

    .. warning:: **Thread-safety caveat**

       The lock is only held for the individual *write* operations (setting
       and restoring the default), **not** for the entire duration of the
       ``with`` block.  This means that if two threads use
       ``encoding_override`` concurrently, they can interleave and one
       thread's override may be visible to the other.  For multi-threaded
       applications that require isolation, prefer passing an explicit
       *encoding* parameter to ``to_multibase()`` / ``bytes_to_multibase()``
       instead of relying on the global default.

    Parameters
    ----------
    encoding : str
        A multibase encoding name recognised by *py-multibase*.

    Raises
    ------
    ValueError
        If *encoding* is not supported.

    Example
    -------
    >>> with encoding_override("base32"):
    ...     peer_id.to_multibase()  # uses base32
    ...
    >>> peer_id.to_multibase()      # back to the previous default

    N)r   r   r   r   )r   previouss     r   encoding_overrider   3   s[     H $%H") 	) (	) 	) 	)U 	) (	) 	) 	)sC   A; A/	A8AAA	AAAAc                 <    t        t        j                               S )zGReturn a sorted list of all encoding names supported by *py-multibase*.)sortedr   r   r
   r   r   list_supported_encodingsr   a   s    )**,--r   )returnr   )r   r   r   None)r   r   r   zIterator[None])r   z	list[str])
__future__r   collections.abcr   
contextlibr   	threadingr   Lockr   r   __annotations__r   r   r   r   r
   r   r   <module>r&      sR    " $ %  	$ 3 $
%B *) *)Z.r   