o
    ?8¾\   ã                   @   s0   d Z ddlmZmZmZmZ G dd„ deƒZdS )z0Tools for representing JavaScript code in BSON.
é    )ÚabcÚstring_typeÚPY3Ú	text_typec                   @   sF   e Zd ZdZdZddd„Zedd„ ƒZdd	„ Zd
d„ Z	dZ
dd„ ZdS )ÚCodea�  BSON's JavaScript code type.

    Raises :class:`TypeError` if `code` is not an instance of
    :class:`basestring` (:class:`str` in python 3) 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.

    :Parameters:
      - `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`.
      - `scope` (optional): 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.
      - `**kwargs` (optional): 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 ``{}``.

    é   Nc                 K   sÎ   t |tƒstdtj ƒ‚tst |tƒrt | | d¡¡}nt | |¡}z|j	|_
W n ty5   d |_
Y nw |d urSt |tjƒsDtdƒ‚|j
d urP|j
 |¡ n||_
|re|j
d urb|j
 |¡ |S ||_
|S )Nzcode must be an instance of %sÚutf8z!scope must be an instance of dict)Ú
isinstancer   Ú	TypeErrorÚ__name__r   r   ÚstrÚ__new__ÚencodeÚscopeÚ_Code__scopeÚAttributeErrorr   ÚMappingÚupdate)ÚclsÚcoder   ÚkwargsÚself© r   ú;/var/www/html/env/lib/python3.10/site-packages/bson/code.pyr   3   s0   
ÿ
ÿ

þzCode.__new__c                 C   s   | j S )z8Scope dictionary for this instance or ``None``.
        )r   ©r   r   r   r   r   R   s   z
Code.scopec                 C   s   dt  | ¡| jf S )NzCode(%s, %r))r   Ú__repr__r   r   r   r   r   r   X   s   zCode.__repr__c                 C   s*   t |tƒr| jt| ƒf|jt|ƒfkS dS )NF)r	   r   r   r   ©r   Úotherr   r   r   Ú__eq__[   s   
zCode.__eq__c                 C   s
   | |k S ©Nr   r   r   r   r   Ú__ne__b   s   
zCode.__ne__r   )r   Ú
__module__Ú__qualname__Ú__doc__Ú_type_markerr   Úpropertyr   r   r   Ú__hash__r    r   r   r   r   r      s    

r   N)r#   Úbson.py3compatr   r   r   r   r   r   r   r   r   r   Ú<module>   s   