3
O6b2                 @   s.   d Z G dd dZG dd deZdd ZdS )a!
  Support for MongoDB Versioned API.

.. _versioned-api-ref:

MongoDB Versioned API
=====================

Starting in MongoDB 5.0, applications can specify the server API version
to use when creating a :class:`~pymongo.mongo_client.MongoClient`. Doing so
ensures that the driver behaves in a manner compatible with that server API
version, regardless of the server's actual release version.

Declaring an API Version
````````````````````````

.. attention:: Versioned API requires MongoDB >=5.0.

To configure MongoDB Versioned API, pass the ``server_api`` keyword option to
:class:`~pymongo.mongo_client.MongoClient`::

    >>> from pymongo.mongo_client import MongoClient
    >>> from pymongo.server_api import ServerApi
    >>>
    >>> # Declare API version "1" for MongoClient "client"
    >>> server_api = ServerApi('1')
    >>> client = MongoClient(server_api=server_api)

The declared API version is applied to all commands run through ``client``,
including those sent through the generic
:meth:`~pymongo.database.Database.command` helper.

.. note:: Declaring an API version on the
   :class:`~pymongo.mongo_client.MongoClient` **and** specifying versioned
   API options in :meth:`~pymongo.database.Database.command` command document
   is not supported and will lead to undefined behaviour.

To run any command without declaring a server API version or using a different
API version, create a separate :class:`~pymongo.mongo_client.MongoClient`
instance.

Strict Mode
```````````

Configuring ``strict`` mode will cause the MongoDB server to reject all
commands that are not part of the declared :attr:`ServerApi.version`. This
includes command options and aggregation pipeline stages.

For example::

    >>> server_api = ServerApi('1', strict=True)
    >>> client = MongoClient(server_api=server_api)
    >>> client.test.command('count', 'test')
    Traceback (most recent call last):
    ...
    pymongo.errors.OperationFailure: Provided apiStrict:true, but the command count is not in API Version 1, full error: {'ok': 0.0, 'errmsg': 'Provided apiStrict:true, but the command count is not in API Version 1', 'code': 323, 'codeName': 'APIStrictError'

Detecting API Deprecations
``````````````````````````

The ``deprecationErrors`` option can be used to enable command failures
when using functionality that is deprecated from the configured
:attr:`ServerApi.version`. For example::

    >>> server_api = ServerApi('1', deprecation_errors=True)
    >>> client = MongoClient(server_api=server_api)

Note that at the time of this writing, no deprecated APIs exist.

Classes
=======
c               @   s   e Zd ZdZdZdS )ServerApiVersionz[An enum that defines values for :attr:`ServerApi.version`.

    .. versionadded:: 3.12
    1N)__name__
__module____qualname____doc__V1 r   r   Q/var/www/html/sandeepIITI/myenv/lib/python3.6/site-packages/pymongo/server_api.pyr   X   s   r   c               @   s>   e Zd ZdZdddZedd Zedd Zed	d
 ZdS )	ServerApizMongoDB Versioned API.Nc             C   sz   |t jkrtd|f |dk	r>t|t r>tdt|f |dk	rdt|t rdtdt|f || _|| _|| _	dS )a"  Options to configure MongoDB Versioned API.

        :Parameters:
          - `version`: The API version string. Must be one of the values in
            :class:`ServerApiVersion`.
          - `strict` (optional): Set to ``True`` to enable API strict mode.
            Defaults to ``None`` which means "use the server's default".
          - `deprecation_errors` (optional): Set to ``True`` to enable
            deprecation errors. Defaults to ``None`` which means "use the
            server's default".

        .. versionadded:: 3.12
        zUnknown ServerApi version: %sNzJWrong type for ServerApi strict, value must be an instance of bool, not %szVWrong type for ServerApi deprecation_errors, value must be an instance of bool, not %s)
r   r   
ValueError
isinstancebool	TypeErrortype_version_strict_deprecation_errors)selfversionstrictdeprecation_errorsr   r   r	   __init__d   s    
zServerApi.__init__c             C   s   | j S )zfThe API version setting.

        This value is sent to the server in the "apiVersion" field.
        )r   )r   r   r   r	   r      s    zServerApi.versionc             C   s   | j S )zsThe API strict mode setting.

        When set, this value is sent to the server in the "apiStrict" field.
        )r   )r   r   r   r	   r      s    zServerApi.strictc             C   s   | j S )zThe API deprecation errors setting.

        When set, this value is sent to the server in the
        "apiDeprecationErrors" field.
        )r   )r   r   r   r	   r      s    zServerApi.deprecation_errors)NN)	r   r   r   r   r   propertyr   r   r   r   r   r   r	   r
   b   s
   
r
   c             C   s>   |sdS |j | d< |jdk	r&|j| d< |jdk	r:|j| d< dS )zInternal helper which adds API versioning options to a command.

    :Parameters:
      - `cmd`: The command.
      - `server_api` (optional): A :class:`ServerApi` or ``None``.
    NZ
apiVersionZ	apiStrictZapiDeprecationErrors)r   r   r   )cmdZ
server_apir   r   r	   _add_to_command   s    



r   N)r   r   objectr
   r   r   r   r   r	   <module>U   s   
9