o Sb @s@dZddlmZddlmZmZmZmZmZGddde Z dS)z0Tools for representing JavaScript code in BSON. )Mapping)AnyrOptionalTypeUnionc @seZdZUdZdZeeeefdfe d< dde ddeedfde eeefded df d d Z e d e eeeffd d ZddZded efddZdZee d<ded efddZdS)CodeaBSON'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 ``{}``. N _Code__scopeclscodescopekwargsreturncKst|ts tdt||}z|j|_Wn ty!d|_Ynw|dur>t|ts/td|jdur;|j|n||_|rP|jdurM|j||S||_|S)Nzcode must be an instance of strz!scope must be an instance of dict) isinstancestr TypeError__new__r r AttributeError_Mappingupdate)r r r r selfr0/tmp/pip-target-onvjaxws/lib/python/bson/code.pyr5s(         z Code.__new__cCs|jS)z/Scope dictionary for this instance or ``None``.)r rrrrr Usz Code.scopecCsdt||jfS)Nz Code(%s, %r))r__repr__r rrrrrZsz Code.__repr__othercCs*t|tr|jt|f|jt|fkSdS)NF)rrr rrrrrr__eq__]s z Code.__eq____hash__cCs ||k SNrrrrr__ne__ds z Code.__ne__r)__name__ __module__ __qualname____doc__Z _type_markerrrrr__annotations__rrrpropertyr rboolrrr rrrrrs,     rN) r$collections.abcrrtypingrrrrrrrrrrs