
    FCfi                    R    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e      Zy)z/Tools for representing JavaScript code in BSON.    )annotations)Mapping)Anyr   OptionalTypeUnionc                  v    e Zd ZU dZdZded<   	 d	 	 	 	 	 	 	 	 	 ddZedd       Zdd	Z	dd
Z
dZded<   ddZy)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__scopeNr   c                   t        |t              st        d      t        j                  | |      }	 |j                  |_        |Jt        |t              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 strz!scope must be an instance of dict)	
isinstancestr	TypeError__new__scoper   AttributeError_Mappingupdate)clscoder   kwargsselfs        I/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/bson/code.pyr   zCode.__new__4   s     $$=>>{{3%	 ::DL eX. CDD||'##E*$||'##F+   &#  	 DL	 s   C CCc                    | j                   S )z/Scope dictionary for this instance or ``None``.)r   r   s    r   r   z
Code.scopeT   s     ||    c                N    dt         j                  |        d| j                  dS )NzCode(z, ))r   __repr__r   r   s    r   r    zCode.__repr__Y   s&    s||D)*"T\\,<A>>r   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   __hash__c                    | |k(   S N r"   s     r   __ne__zCode.__ne__c   s    5=  r   r'   )
r   z
Type[Code]r   zUnion[str, Code]r   Optional[Mapping[str, Any]]r   r   returnr
   )r+   r*   )r+   r   )r#   r   r+   bool)__name__
__module____qualname____doc___type_marker__annotations__r   propertyr   r    r$   r%   r)   r(   r   r   r
   r
      s|    4 L++
 .2 + 	
 
@  ?
 Hc!r   r
   N)r0   
__future__r   collections.abcr   r   typingr   r   r   r   r   r
   r(   r   r   <module>r7      s$    6 " / 6 6N!3 N!r   