implemented global IS_PYMONGO_3
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
import pymongo
|
||||
from pymongo import MongoClient, ReadPreference, uri_parser
|
||||
|
||||
from mongoengine.python_support import IS_PYMONGO_3
|
||||
|
||||
__all__ = ['ConnectionError', 'connect', 'register_connection',
|
||||
'DEFAULT_CONNECTION_NAME']
|
||||
|
||||
|
||||
DEFAULT_CONNECTION_NAME = 'default'
|
||||
if pymongo.version_tuple[0] >= 3:
|
||||
if IS_PYMONGO_3:
|
||||
READ_PREFERENCE = ReadPreference.PRIMARY
|
||||
else:
|
||||
from pymongo import MongoReplicaSetClient
|
||||
@@ -115,7 +114,7 @@ def get_connection(alias=DEFAULT_CONNECTION_NAME, reconnect=False):
|
||||
# Discard replicaSet if not base string
|
||||
if not isinstance(conn_settings['replicaSet'], basestring):
|
||||
conn_settings.pop('replicaSet', None)
|
||||
if pymongo.version_tuple[0] < 3:
|
||||
if not IS_PYMONGO_3:
|
||||
connection_class = MongoReplicaSetClient
|
||||
|
||||
try:
|
||||
|
||||
@@ -295,7 +295,7 @@ class Document(BaseDocument):
|
||||
|
||||
# I think the self._created flag is not necessarily required in PyMongo3
|
||||
# but may cause test test_collection_name_and_primary to fail
|
||||
# if pymongo.version_tuple[0] < 3:
|
||||
# if not IS_PYMONGO_3:
|
||||
created = ('_id' not in doc or self._created or force_insert)
|
||||
# else:
|
||||
# created = ('_id' not in doc or force_insert)
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
"""Helper functions and types to aid with Python 2.5 - 3 support."""
|
||||
|
||||
import sys
|
||||
import pymongo
|
||||
|
||||
|
||||
if pymongo.version_tuple[0] < 3:
|
||||
IS_PYMONGO_3 = False
|
||||
else:
|
||||
IS_PYMONGO_3 = True
|
||||
|
||||
PY3 = sys.version_info[0] == 3
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ from mongoengine.common import _import_class
|
||||
from mongoengine.base.common import get_document
|
||||
from mongoengine.errors import (OperationError, NotUniqueError,
|
||||
InvalidQueryError, LookUpError)
|
||||
from mongoengine.python_support import IS_PYMONGO_3
|
||||
from mongoengine.queryset import transform
|
||||
from mongoengine.queryset.field_list import QueryFieldList
|
||||
from mongoengine.queryset.visitor import Q, QNode
|
||||
@@ -1385,7 +1386,7 @@ class BaseQuerySet(object):
|
||||
|
||||
@property
|
||||
def _cursor_args(self):
|
||||
if pymongo.version_tuple[0] < 3:
|
||||
if not IS_PYMONGO_3:
|
||||
fields_name = 'fields'
|
||||
cursor_args = {
|
||||
'timeout': self._timeout,
|
||||
|
||||
Reference in New Issue
Block a user