U Yzf_@sJdZddlZddlmZddlmZGdddejZGdd d eZ dS) zImplementation of the DbDoc.N) STRING_TYPES)ProgrammingErrorc@seZdZdZddZdS)ExprJSONEncoderzgA :class:`json.JSONEncoder` subclass, which enables encoding of :class:`mysqlx.ExprParser` objects.cCs"t|drd|Stj||S)Nexprz{0})hasattrformatjson JSONEncoderdefault)selford/private/var/folders/n9/53xbvtmd7sjg1q1l55xmpg58n4mgng/T/pip-unpacked-wheel-47tvuv7y/mysqlx/dbdoc.pyr (s  zExprJSONEncoder.defaultN)__name__ __module__ __qualname____doc__r rrrrr%src@sReZdZdZddZddZddZdd Zd d Zdd dZ ddZ ddZ d S)DbDoczRepresents a generic document in JSON format. Args: value (object): The value can be a JSON string or a dict. Raises: ValueError: If ``value`` type is not a basestring or dict. cCs@t|tr||_n*t|tr*t||_ntdt|dS)NzUnable to handle type: {0}) isinstancedict__dict__rr loads ValueErrorrtype)r valuerrr__init__8s   zDbDoc.__init__cCs|SN)as_strr rrr__str__@sz DbDoc.__str__cCs t|jSr)reprrrrrr__repr__CszDbDoc.__repr__cCs|dkrtd||j|<dS)N_idzCannot modify _id)rr)r indexrrrr __setitem__FszDbDoc.__setitem__cCs |j|Sr)r)r r$rrr __getitem__KszDbDoc.__getitem__NcCs.|j}|r||d<nd|kr&|d=t|S)aeReturns a new copy of a :class:`mysqlx.DbDoc` object containing the `doc_id` provided. If `doc_id` is not provided, it will be removed from new :class:`mysqlx.DbDoc` object. Args: doc_id (Optional[str]): Document ID Returns: mysqlx.DbDoc: A new instance of DbDoc containing the _id provided r#)rcopyr)r Zdoc_idZnew_dictrrrr'Ns  z DbDoc.copycCs |jS)zJReturns the keys. Returns: `list`: The keys. )rkeysrrrrr(`sz DbDoc.keyscCstj|jtdS)zSerialize :class:`mysqlx.DbDoc` to a JSON formatted ``str``. Returns: str: A JSON formatted ``str`` representation of the document. .. versionadded:: 8.0.16 )cls)r dumpsrrrrrrrhsz DbDoc.as_str)N) rrrrrr r"r%r&r'r(rrrrrr/s r) rr compatrerrorsrr robjectrrrrrs