o
    C©Ìh�  ã                   @  sL   d Z ddlmZ ddlmZ ddlmZmZmZm	Z	m
Z
 G dd„ deƒZdS )z/Tools for representing JavaScript code in BSON.é    )Úannotations)ÚMapping)ÚAnyr   ÚOptionalÚTypeÚUnionc                   @  sd   e Zd ZU dZdZded< 	dddd„Zeddd„ƒZd dd„Z	d!dd„Z
dZded< d!dd„ZdS )"ÚCodeaG  BSON's JavaScript code type.

    Raises :class:`TypeError` if `code` is not an instance of
    :class:`str` or `scope` is not ``None`` or an instance
    of :class:`dict`.

    Scope variables can be set by passing a dictionary as the `scope`
    argument or by using keyword arguments. If a variable is set as a
    keyword argument it will override any setting for that variable in
    the `scope` dictionary.

    :param code: A string containing JavaScript code to be evaluated or another
        instance of Code. In the latter case, the scope of `code` becomes this
        Code's :attr:`scope`.
    :param scope: dictionary representing the scope in which
        `code` should be evaluated - a mapping from identifiers (as
        strings) to values. Defaults to ``None``. This is applied after any
        scope associated with a given `code` above.
    :param kwargs: scope variables can also be passed as
        keyword arguments. These are applied after `scope` and `code`.

    .. versionchanged:: 3.4
      The default value for :attr:`scope` is ``None`` instead of ``{}``.

    é   zUnion[Mapping[str, Any], None]Ú_Code__scopeNÚclsú
Type[Code]ÚcodeúUnion[str, Code]ÚscopeúOptional[Mapping[str, Any]]Úkwargsr   Úreturnc                 K  s¸   t |tƒstdt|ƒ› �ƒ‚t | |¡}z|j|_W n ty&   d |_Y nw |d urHt |tƒs9tdt|ƒ› �ƒ‚|jd urE|j 	|¡ n||_|rZ|jd urW|j 	|¡ |S ||_|S )Nz%code must be an instance of str, not z'scope must be an instance of dict, not )
Ú
isinstanceÚstrÚ	TypeErrorÚtypeÚ__new__r   r
   ÚAttributeErrorÚ_MappingÚupdate)r   r   r   r   Úself© r   úX/var/www/html/Moveonwheels/move_on_wheels/venv/lib/python3.10/site-packages/bson/code.pyr   4   s(   

ÿ


þzCode.__new__c                 C  s   | j S )z/Scope dictionary for this instance or ``None``.)r
   ©r   r   r   r   r   T   s   z
Code.scoper   c                 C  s   dt  | ¡› d| j›d�S )NzCode(z, ú))r   Ú__repr__r
   r   r   r   r   r    Y   s   zCode.__repr__ÚotherÚboolc                 C  s*   t |tƒr| jt| ƒf|jt|ƒfkS dS )NF)r   r   r
   r   ©r   r!   r   r   r   Ú__eq__\   s   
zCode.__eq__Ú__hash__c                 C  s
   | |k S ©Nr   r#   r   r   r   Ú__ne__c   s   
zCode.__ne__r&   )
r   r   r   r   r   r   r   r   r   r   )r   r   )r   r   )r!   r   r   r"   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú_type_markerÚ__annotations__r   Úpropertyr   r    r$   r%   r'   r   r   r   r   r      s   
 ý 

r   N)r+   Ú
__future__r   Úcollections.abcr   r   Útypingr   r   r   r   r   r   r   r   r   r   Ú<module>   s
   