
    h                      6    d Z ddlmZmZmZmZ  G d de      Zy)z0Tools for representing JavaScript code in BSON.
    )abcstring_typePY3	text_typec                   B    e Zd ZdZdZd	dZed        Zd Zd Z	dZ
d Zy)
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                 b   t        |t              st        dt        j                  z        t        s6t        |t
              r&t        j                  | |j                  d            }nt        j                  | |      }	 |j                  |_
        |Tt        |t        j                        st        d      |j                  |j                  j                  |       n||_
        |r0|j                  |j                  j                  |       |S ||_
        |S # t        $ r
 d |_
        Y w xY w)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selfs        L/var/www/html/ranktracker/api/venv/lib/python3.12/site-packages/bson/code.pyr   zCode.__new__3   s   $, -0;0D0DF G G z$	2;;sDKK$78D;;sD)D	 ::DL eS[[1 CDD||'##E*$||'##F+   &#  	 DL	 s    D D.-D.c                     | j                   S )z8Scope dictionary for this instance or ``None``.
        )r   r   s    r   r   z
Code.scopeR   s     ||    c                 N    dt         j                  |       d| j                  dS )NzCode(z, ))r   __repr__r   r   s    r   r!   zCode.__repr__X   s    !$d!3T\\BBr   c                     t        |t              r/| j                  t        |       f|j                  t        |      fk(  S y)NF)r   r   r   r   r   others     r   __eq__zCode.__eq__[   s4    eT"LL#d),E
0KKKr   c                     | |k(   S N r#   s     r   __ne__zCode.__ne__b   s    5=  r   r'   )r   
__module____qualname____doc___type_markerr   propertyr   r!   r%   __hash__r)   r(   r   r   r   r      s>    6 L>  
C
 H!r   r   N)r,   bson.py3compatr   r   r   r   r   r   r(   r   r   <module>r1      s     < ;N!3 N!r   