PYTHON-826 Move codec_options submodule from pymongo to bson.
This commit is contained in:
parent
1ec4ab3260
commit
a2c13090d8
@ -75,3 +75,11 @@ class CodecOptions(object):
|
||||
|
||||
def __ne__(self, other):
|
||||
return self != other
|
||||
|
||||
|
||||
def _parse_codec_options(options):
|
||||
"""Parse BSON codec options."""
|
||||
as_class = options.get('document_class', dict)
|
||||
tz_aware = options.get('tz_aware', False)
|
||||
uuid_rep = options.get('uuidrepresentation', PYTHON_LEGACY)
|
||||
return CodecOptions(as_class, tz_aware, uuid_rep)
|
||||
@ -1,6 +1,6 @@
|
||||
:mod:`codec_options` -- Tools for specifying BSON codec options
|
||||
===============================================================
|
||||
|
||||
.. automodule:: pymongo.codec_options
|
||||
.. automodule:: bson.codec_options
|
||||
:synopsis: Tools for specifying BSON codec options.
|
||||
:members:
|
||||
@ -13,6 +13,7 @@ Sub-modules:
|
||||
binary
|
||||
regex
|
||||
code
|
||||
codec_options
|
||||
dbref
|
||||
errors
|
||||
json_util
|
||||
|
||||
@ -33,7 +33,6 @@ Sub-modules:
|
||||
|
||||
database
|
||||
collection
|
||||
codec_options
|
||||
command_cursor
|
||||
cursor
|
||||
bulk
|
||||
|
||||
@ -14,10 +14,9 @@
|
||||
|
||||
"""Tools to parse mongo client options."""
|
||||
|
||||
from bson.binary import PYTHON_LEGACY
|
||||
from bson.codec_options import _parse_codec_options
|
||||
from bson.py3compat import iteritems
|
||||
from pymongo.auth import _build_credentials_tuple
|
||||
from pymongo.codec_options import CodecOptions
|
||||
from pymongo.common import validate
|
||||
from pymongo.errors import ConfigurationError
|
||||
from pymongo.pool import PoolOptions
|
||||
@ -36,14 +35,6 @@ def _parse_credentials(username, password, database, options):
|
||||
mechanism, source, username, password, options)
|
||||
|
||||
|
||||
def _parse_codec_options(options):
|
||||
"""Parse BSON codec options."""
|
||||
as_class = options.get('document_class', dict)
|
||||
tz_aware = options.get('tz_aware', False)
|
||||
uuid_rep = options.get('uuidrepresentation', PYTHON_LEGACY)
|
||||
return CodecOptions(as_class, tz_aware, uuid_rep)
|
||||
|
||||
|
||||
def _parse_read_preference(options):
|
||||
"""Parse read preference options."""
|
||||
if 'read_preference' in options:
|
||||
@ -130,7 +121,7 @@ class ClientOptions(object):
|
||||
|
||||
@property
|
||||
def codec_options(self):
|
||||
"""A :class:`~pymongo.codec_options.CodecOptions` instance."""
|
||||
"""A :class:`~bson.codec_options.CodecOptions` instance."""
|
||||
return self.__codec_options
|
||||
|
||||
@property
|
||||
|
||||
@ -24,12 +24,12 @@ from bson.objectid import ObjectId
|
||||
from bson.py3compat import (_unicode,
|
||||
integer_types,
|
||||
string_type)
|
||||
from bson.codec_options import CodecOptions
|
||||
from bson.son import SON
|
||||
from pymongo import (bulk,
|
||||
common,
|
||||
helpers,
|
||||
message)
|
||||
from pymongo.codec_options import CodecOptions
|
||||
from pymongo.command_cursor import CommandCursor
|
||||
from pymongo.cursor import Cursor
|
||||
from pymongo.errors import ConfigurationError, InvalidName, OperationFailure
|
||||
@ -78,7 +78,7 @@ class Collection(common.BaseObject):
|
||||
- `create` (optional): if ``True``, force collection
|
||||
creation even without options being set
|
||||
- `codec_options` (optional): An instance of
|
||||
:class:`~pymongo.codec_options.CodecOptions`. If ``None`` (the
|
||||
:class:`~bson.codec_options.CodecOptions`. If ``None`` (the
|
||||
default) database.codec_options is used.
|
||||
- `read_preference` (optional): The read preference to use. If
|
||||
``None`` (the default) database.read_preference is used.
|
||||
@ -147,7 +147,7 @@ class Collection(common.BaseObject):
|
||||
- `read_preference` (optional) - An subclass of
|
||||
:class:`~pymongo.read_preferences.ServerMode`.
|
||||
- `codec_options` (optional) - An instance of
|
||||
:class:`~pymongo.codec_options.CodecOptions`.
|
||||
:class:`~bson.codec_options.CodecOptions`.
|
||||
- `**kwargs` - any optional keyword arguments accepted by
|
||||
:func:`~pymongo.helpers._command`.
|
||||
|
||||
@ -229,7 +229,7 @@ class Collection(common.BaseObject):
|
||||
|
||||
:Parameters:
|
||||
- `codec_options` (optional): An instance of
|
||||
:class:`~pymongo.codec_options.CodecOptions`. If ``None`` (the
|
||||
:class:`~bson.codec_options.CodecOptions`. If ``None`` (the
|
||||
default) the :attr:`codec_options` of this :class:`Collection`
|
||||
is used.
|
||||
- `read_preference` (optional): The read preference to use. If
|
||||
|
||||
@ -17,8 +17,8 @@
|
||||
|
||||
import collections
|
||||
|
||||
from bson.codec_options import CodecOptions
|
||||
from pymongo.auth import MECHANISMS
|
||||
from pymongo.codec_options import CodecOptions
|
||||
from pymongo.errors import ConfigurationError
|
||||
from pymongo.read_preferences import (read_pref_mode_from_name,
|
||||
ServerMode)
|
||||
@ -381,7 +381,7 @@ class BaseObject(object):
|
||||
|
||||
if not isinstance(codec_options, CodecOptions):
|
||||
raise TypeError("codec_options must be an instance of "
|
||||
"pymongo.codec_options.CodecOptions")
|
||||
"bson.codec_options.CodecOptions")
|
||||
self.__codec_options = codec_options
|
||||
|
||||
# TODO: Better error reporting for read preference.
|
||||
@ -396,7 +396,7 @@ class BaseObject(object):
|
||||
|
||||
@property
|
||||
def codec_options(self):
|
||||
"""An instance of :class:`~pymongo.codec_options.CodecOptions`."""
|
||||
"""An instance of :class:`~bson.codec_options.CodecOptions`."""
|
||||
return self.__codec_options
|
||||
|
||||
@property
|
||||
|
||||
@ -17,11 +17,11 @@
|
||||
import warnings
|
||||
|
||||
from bson.code import Code
|
||||
from bson.codec_options import CodecOptions
|
||||
from bson.dbref import DBRef
|
||||
from bson.py3compat import iteritems, string_type, _unicode
|
||||
from bson.son import SON
|
||||
from pymongo import auth, common, helpers
|
||||
from pymongo.codec_options import CodecOptions
|
||||
from pymongo.collection import Collection
|
||||
from pymongo.command_cursor import CommandCursor
|
||||
from pymongo.errors import (CollectionInvalid,
|
||||
@ -61,7 +61,7 @@ class Database(common.BaseObject):
|
||||
- `connection`: A client instance.
|
||||
- `name`: The database name.
|
||||
- `codec_options` (optional): An instance of
|
||||
:class:`~pymongo.codec_options.CodecOptions`. If ``None`` (the
|
||||
:class:`~bson.codec_options.CodecOptions`. If ``None`` (the
|
||||
default) connection.codec_options is used.
|
||||
- `read_preference` (optional): The read preference to use. If
|
||||
``None`` (the default) connection.read_preference is used.
|
||||
@ -229,7 +229,7 @@ class Database(common.BaseObject):
|
||||
:Parameters:
|
||||
- `name`: The name of the collection - a string.
|
||||
- `codec_options` (optional): An instance of
|
||||
:class:`~pymongo.codec_options.CodecOptions`. If ``None`` (the
|
||||
:class:`~bson.codec_options.CodecOptions`. If ``None`` (the
|
||||
default) the :attr:`codec_options` of this :class:`Database` is
|
||||
used.
|
||||
- `read_preference` (optional): The read preference to use. If
|
||||
@ -268,7 +268,7 @@ class Database(common.BaseObject):
|
||||
:Parameters:
|
||||
- `name`: the name of the collection to create
|
||||
- `codec_options` (optional): An instance of
|
||||
:class:`~pymongo.codec_options.CodecOptions`. If ``None`` (the
|
||||
:class:`~bson.codec_options.CodecOptions`. If ``None`` (the
|
||||
default) the :attr:`codec_options` of this :class:`Database` is
|
||||
used.
|
||||
- `read_preference` (optional): The read preference to use. If
|
||||
@ -389,7 +389,7 @@ class Database(common.BaseObject):
|
||||
- `allowable_errors`: if `check` is ``True``, error messages
|
||||
in this list will be ignored by error-checking
|
||||
- `read_preference`: The read preference for this operation.
|
||||
- `codec_options`: A :class:`~pymongo.codec_options.CodecOptions`
|
||||
- `codec_options`: A :class:`~bson.codec_options.CodecOptions`
|
||||
instance.
|
||||
- `**kwargs` (optional): additional keyword arguments will
|
||||
be added to the command document before it is sent
|
||||
|
||||
@ -19,10 +19,9 @@ import struct
|
||||
|
||||
import bson
|
||||
import pymongo
|
||||
|
||||
from bson.codec_options import CodecOptions
|
||||
from bson.py3compat import itervalues, string_type, iteritems
|
||||
from bson.son import SON
|
||||
from pymongo.codec_options import CodecOptions
|
||||
from pymongo.errors import (CursorNotFound,
|
||||
DuplicateKeyError,
|
||||
OperationFailure,
|
||||
@ -90,7 +89,7 @@ def _unpack_response(response, cursor_id=None, codec_options=CodecOptions()):
|
||||
used for raising an informative exception when we get cursor id not
|
||||
valid at server response
|
||||
- `codec_options` (optional): an instance of
|
||||
:class:`~pymongo.codec_options.CodecOptions`
|
||||
:class:`~bson.codec_options.CodecOptions`
|
||||
"""
|
||||
response_flag = struct.unpack("<i", response[:4])[0]
|
||||
if response_flag & 1:
|
||||
|
||||
@ -1056,7 +1056,7 @@ class MongoClient(common.BaseObject):
|
||||
:Parameters:
|
||||
- `name`: The name of the database - a string.
|
||||
- `codec_options` (optional): An instance of
|
||||
:class:`~pymongo.codec_options.CodecOptions`. If ``None`` (the
|
||||
:class:`~bson.codec_options.CodecOptions`. If ``None`` (the
|
||||
default) the :attr:`codec_options` of this :class:`MongoClient` is
|
||||
used.
|
||||
- `read_preference` (optional): The read preference to use. If
|
||||
|
||||
@ -25,10 +25,10 @@ sys.path[0:0] = [""]
|
||||
import bson
|
||||
|
||||
from bson.binary import *
|
||||
from bson.codec_options import CodecOptions
|
||||
from bson.py3compat import u
|
||||
from bson.son import SON
|
||||
from test import client_context, unittest
|
||||
from pymongo.codec_options import CodecOptions
|
||||
from pymongo.mongo_client import MongoClient
|
||||
|
||||
|
||||
|
||||
@ -28,13 +28,13 @@ import warnings
|
||||
sys.path[0:0] = [""]
|
||||
|
||||
from bson import BSON
|
||||
from bson.codec_options import CodecOptions
|
||||
from bson.py3compat import thread, u
|
||||
from bson.son import SON
|
||||
from bson.tz_util import utc
|
||||
from pymongo import auth, message
|
||||
from pymongo.cursor import EXHAUST
|
||||
from pymongo.database import Database
|
||||
from pymongo.codec_options import CodecOptions
|
||||
from pymongo.errors import (AutoReconnect,
|
||||
ConfigurationError,
|
||||
ConnectionFailure,
|
||||
|
||||
@ -27,6 +27,7 @@ sys.path[0:0] = [""]
|
||||
|
||||
from bson.regex import Regex
|
||||
from bson.code import Code
|
||||
from bson.codec_options import CodecOptions
|
||||
from bson.dbref import DBRef
|
||||
from bson.objectid import ObjectId
|
||||
from bson.py3compat import u, itervalues
|
||||
@ -34,7 +35,6 @@ from bson.son import SON
|
||||
from pymongo import (ASCENDING, DESCENDING, GEO2D,
|
||||
GEOHAYSTACK, GEOSPHERE, HASHED, TEXT)
|
||||
from pymongo import MongoClient
|
||||
from pymongo.codec_options import CodecOptions
|
||||
from pymongo.collection import Collection
|
||||
from pymongo.command_cursor import CommandCursor
|
||||
from pymongo.cursor import EXHAUST
|
||||
|
||||
@ -21,11 +21,10 @@ sys.path[0:0] = [""]
|
||||
|
||||
from bson.binary import UUIDLegacy, PYTHON_LEGACY, STANDARD
|
||||
from bson.code import Code
|
||||
from bson.codec_options import CodecOptions
|
||||
from bson.objectid import ObjectId
|
||||
from bson.son import SON
|
||||
from pymongo.codec_options import CodecOptions
|
||||
from pymongo.mongo_client import MongoClient
|
||||
from pymongo.errors import ConfigurationError, OperationFailure
|
||||
from pymongo.errors import OperationFailure
|
||||
from pymongo.write_concern import WriteConcern
|
||||
from test import client_context, pair, unittest, IntegrationTest
|
||||
from test.utils import connected, rs_or_single_client, single_client
|
||||
|
||||
@ -22,6 +22,7 @@ import warnings
|
||||
sys.path[0:0] = [""]
|
||||
|
||||
from bson.code import Code
|
||||
from bson.codec_options import CodecOptions
|
||||
from bson.int64 import Int64
|
||||
from bson.regex import Regex
|
||||
from bson.dbref import DBRef
|
||||
@ -33,9 +34,7 @@ from pymongo import (MongoClient,
|
||||
auth,
|
||||
OFF,
|
||||
SLOW_ONLY,
|
||||
helpers,
|
||||
ReadPreference)
|
||||
from pymongo.codec_options import CodecOptions
|
||||
helpers)
|
||||
from pymongo.collection import Collection
|
||||
from pymongo.database import Database
|
||||
from pymongo.errors import (CollectionInvalid,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user