o
    –¨Êhø  ã                   @   sJ   d Z ddlZddlmZ ddlmZ G dd„ dejƒZG dd	„ d	eƒZ	dS )
zImplementation of the DbDoc.é    Né   )ÚSTRING_TYPES)ÚProgrammingErrorc                   @   s   e Zd ZdZdd„ ZdS )ÚExprJSONEncoderzgA :class:`json.JSONEncoder` subclass, which enables encoding of
    :class:`mysqlx.ExprParser` objects.c                 C   s"   t |dƒr
d |¡S tj | |¡S )NÚexprz{0})ÚhasattrÚformatÚjsonÚJSONEncoderÚdefault)ÚselfÚo© r   ú>/var/www/html/env/lib/python3.10/site-packages/mysqlx/dbdoc.pyr   (   s   

zExprJSONEncoder.defaultN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   %   s    r   c                   @   sJ   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zddd„Z	dd„ Z
dS )ÚDbDoczÏRepresents a generic document in JSON format.

    Args:
        value (object): The value can be a JSON string or a dict.

    Raises:
        ValueError: If ``value`` type is not a basestring or dict.
    c                 C   s@   t |tƒr
|| _d S t |tƒrt |¡| _d S td t|ƒ¡ƒ‚)NzUnable to handle type: {0})	Ú
isinstanceÚdictÚ__dict__r   r	   ÚloadsÚ
ValueErrorr   Útype)r   Úvaluer   r   r   Ú__init__8   s
   


zDbDoc.__init__c                 C   s   t j| jtd�S )N)Úcls)r	   Údumpsr   r   ©r   r   r   r   Ú__str__@   s   zDbDoc.__str__c                 C   s
   t | jƒS ©N)Úreprr   r   r   r   r   Ú__repr__C   ó   
zDbDoc.__repr__c                 C   s   |dkrt dƒ‚|| j|< d S )NÚ_idzCannot modify _id)r   r   )r   Úindexr   r   r   r   Ú__setitem__F   s   zDbDoc.__setitem__c                 C   s
   | j | S r!   )r   )r   r&   r   r   r   Ú__getitem__K   r$   zDbDoc.__getitem__Nc                 C   s4   | j  ¡ }|r||d< t|ƒS d|v r|d= t|ƒS )ae  Returns a new copy of a :class:`mysqlx.DbDoc` object containing the
        `doc_id` provided. If `doc_id` is not provided, it will be removed from
        new :class:`mysqlx.DbDoc` object.

        Args:
            doc_id (Optional[str]): Document ID

        Returns:
            mysqlx.DbDoc: A new instance of DbDoc containing the _id provided
        r%   )r   Úcopyr   )r   Údoc_idÚnew_dictr   r   r   r)   N   s   
þz
DbDoc.copyc                 C   s
   | j  ¡ S )zJReturns the keys.

        Returns:
            `list`: The keys.
        )r   Úkeysr   r   r   r   r,   `   s   
z
DbDoc.keysr!   )r   r   r   r   r   r    r#   r'   r(   r)   r,   r   r   r   r   r   /   s    
r   )
r   r	   Úcompatr   Úerrorsr   r
   r   Úobjectr   r   r   r   r   Ú<module>   s   
