o
    Niw                     @  sl   d Z ddlmZ ddlZddlZddlZddlmZ er"ddlmZ dd
dZ	dddddZ
dddZdS )z-Serialise objects to a stable representation.    )annotationsN)TYPE_CHECKING)Anyobjr   returnstrc                 C  s~   t | trttt|  } t | ttB tB t	B r!ttt| } nt | t
tjB r2| j d| j } tjt|  dd S )zReturn a stable hash for a Python data structure.

    We can't just use the md5 of str(obj) as the order of collections
    may be random.
    .F)usedforsecurity)
isinstancedictsortedmapstable_hashitemslisttupleset	frozensettypetypesFunctionType
__module____qualname__hashlibmd5r   encode	hexdigestr    r   J/home/ubuntu/.local/lib/python3.10/site-packages/sphinx/util/_serialise.pyr      s   
r   indentr!   
int | Nonec                C  s   t jt| |dS )zReturn a stable string representation of a Python data structure.

    We can't just use ``str(obj)`` as the order of collections may be random.
    r    )jsondumps_stable_str_prep)r   r!   r   r   r   
stable_str   s   r&    dict[str, Any] | list[Any] | strc                 C  s~   t | trdd |  D } |   t| S t | ttB tB tB r*tt	t
| tdS t | ttjB r;| j d| j S t| S )Nc                 S  s    g | ]\}}t |t |fqS r   )r%   ).0kvr   r   r   
<listcomp>*   s     z$_stable_str_prep.<locals>.<listcomp>)keyr   )r
   r   r   sortr   r   r   r   r   r   r%   r   r   r   r   r   r   r   r   r   r   r%   '   s   
r%   )r   r   r   r   )r   r   r!   r"   r   r   )r   r   r   r'   )__doc__
__future__r   r   r#   r   typingr   r   r   r&   r%   r   r   r   r   <module>   s    
