HEX
Server: Apache
System: Linux 185.122.168.184.host.secureserver.net 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: barbeatleanalyti (1024)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/lib/python3.9/site-packages/cockpit/__pycache__/jsonutil.cpython-39.pyc
a

�/�hJ�@s�ddlmZddlmZmZmZmZmZmZm	Z	m
Z
mZmZee
eedfZede	defZee
efZeddefZee
efZeeZed�Zed	�ZGd
d�de�Zee
eed�d
d�ZGdd�de�ZejZeeegefe
eeefeeefd�dd�Zefee
eeefeeefd�dd�Zefee
eeefeee fd�dd�Z!efee
eeefeee
fd�dd�Z"ee
ee
ee
d�dd�Z#efee
eeefeeefd�dd�Z$efee
eegefeeefeeefd�d d!�Z%efee
eeefeee	e
fd�d"d#�Z&efee
ee
eeefeee
fd$�d%d&�Z'ee
eegefeee	efd'�d(d)�Z(d*eed+�d,d-�Z)eeed.�d/d0�Z*eedd.�d1d2�Z+dS)3�)�Enum)
�Callable�	Container�Dict�List�Mapping�Optional�Sequence�Type�TypeVar�UnionN�
JsonObject�	JsonValue�JsonDict�JsonList�DT�Tcs.eZdZUeed<eed��fdd�Z�ZS)�	JsonError�value)r�msgcst��|�||_dS�N)�super�__init__r)�selfrr��	__class__��4/usr/lib/python3.9/site-packages/cockpit/jsonutil.pyr(szJsonError.__init__)�__name__�
__module__�__qualname__�object�__annotations__�strr�
__classcell__rrrrr%s
r)r�
expected_type�returncCs t||�st|d|j����|S)z>Ensure a JSON value has the expected type, returning it if so.zmust have type )�
isinstancerr)rr%rrr�typechecked-s
r(c@seZdZdZdS)�_EmptyrN)rrr �TOKENrrrrr)7sr))�obj�cast�key�defaultr&c
Cs�z|||�WStyD|tur,|YSt|d|�d��d�Yn\ty�}zDd|�d�|j||urndnd}t||�d|���|�WYd}~n
d}~00dS)Nzattribute 'z
' required�'z
 elements:�:� )�KeyError�_emptyrr)r+r,r-r.�exc�targetrrr�_get>s"r6)r+r-r.r&cCst|dd�||�S)NcSs
t|t�Sr)r(�bool��vrrr�<lambda>K�zget_bool.<locals>.<lambda>�r6�r+r-r.rrr�get_boolJsr>cCst|dd�||�S)NcSs
t|t�Sr)r(�intr8rrrr:Or;zget_int.<locals>.<lambda>r<r=rrr�get_intNsr@cCst|dd�||�S)NcSs
t|t�Sr�r(r#r8rrrr:Sr;zget_str.<locals>.<lambda>r<r=rrr�get_strRsrBcCst|dd�||�S)NcSs|durdSt|t�SrrAr8rrrr:Wr;z!get_str_or_none.<locals>.<lambda>r<r=rrr�get_str_or_noneVsrCcCst|dd�||�S)NcSs
t|t�Sr�r(�dictr8rrrr:[r;zget_dict.<locals>.<lambda>r<r=rrr�get_dictZsrF)r+r-�constructorr.r&cst|�fdd�||�S)Ncs�t|t��SrrDr8�rGrrr:dr;zget_object.<locals>.<lambda>r<)r+r-rGr.rrHr�
get_object^srIcCs"tttd�dd�}t||||�S)N�rr&cSstdd�t|t�D��S)Ncss|]}t|t�VqdSrrA��.0�itemrrr�	<genexpr>ir;z,get_strv.<locals>.as_strv.<locals>.<genexpr>��tupler(�list�rrrr�as_strvhszget_strv.<locals>.as_strv)rr	r#r6)r+r-r.rSrrr�get_strvgsrT)r+r-�choicesr.r&cs"ttd��fdd�}t||||�S)NrJcs0t|t�r|�vr|St|d|�d�����dS)Nzinvalid value "z	" not in )r'r#rrR�rUrr�	as_choicepszget_enum.<locals>.as_choice)rr#r6)r+r-rUr.rWrrVr�get_enummsrX)r+r-rGr&cs&tttd��fdd�}t|||d�S)NrJcst�fdd�t|t�D��S)Nc3s|]}�t|t��VqdSrrDrKrHrrrN{r;z,get_objv.<locals>.as_objv.<locals>.<genexpr>rOrRrHrr�as_objvzszget_objv.<locals>.as_objvr)rr	rr6)r+r-rGrYrrHr�get_objvysrZzJsonObject | None)�message�kwargsr&cCs6t|pi�}|��D]\}}|�dd�}|||<q|S)a�Constructs a JSON object based on message and kwargs.

    If only message is given, it is returned, unmodified.  If message is None,
    it is equivalent to an empty dictionary.  A copy is always made.

    If kwargs are present, then any underscore ('_') present in a key name is
    rewritten to a dash ('-').  This is intended to bridge between the required
    Python syntax when providing kwargs and idiomatic JSON (which uses '-' for
    attributes).  These values override values in message.

    The idea is that `message` should be used for passing data along, and
    kwargs used for data originating at a given call site, possibly including
    modifications to an original message.
    �_�-)rE�items�replace)r[r\�resultr-rZjson_keyrrr�
create_objects

rb)�current�patchr&cCspt|�}|��D]Z\}}t|t�rL|�|d�}t|t�s<i}t||�||<q|dur^|||<q|�|d�q|S)u�Perform a JSON merge patch (RFC 7396) using 'current' and 'patch'.
    Neither of the original dictionaries is modified — the result is returned.
    N)rEr_r'r�get�json_merge_patch�pop)rcrdrar-�patch_value�
current_valuerrrrf�s


rfcCs�t|���D]~\}}|�|d�}t|t�rbt|t�sLi||<}t||�q�t||�|s�||=q||krr||=q|dur�|||<q||=qdS)z�Perform a JSON merge patch (RFC 7396) modifying 'current' with 'patch'.
    Also modifies 'patch' to remove redundant operations.
    N)rPr_rer'rE�json_merge_and_filter_patch)rcrdr-rhrirrrrj�s



rj),�enumr�typingrrrrrrr	r
rrr#�floatr7ZJsonLiteralrr
ZJsonDocumentrrrr�	Exceptionrr(r)r*r3r6r>r?r@rBrCrFrIrTrXrZrbrfrjrrrr�<module>sJ0
0((((�

�	,�
�*