diff --git a/pymongo/cluster_description.py b/pymongo/cluster_description.py index 94ce3ff8d..d7a65ef14 100644 --- a/pymongo/cluster_description.py +++ b/pymongo/cluster_description.py @@ -17,8 +17,9 @@ from collections import namedtuple from pymongo import common +from pymongo.server_type import SERVER_TYPE from pymongo.errors import ConfigurationError -from pymongo.server_description import ServerDescription, SERVER_TYPE +from pymongo.server_description import ServerDescription CLUSTER_TYPE = namedtuple('ClusterType', ['Single', 'ReplicaSetNoPrimary', diff --git a/pymongo/ismaster.py b/pymongo/ismaster.py index db67ed6c8..07e2a4084 100644 --- a/pymongo/ismaster.py +++ b/pymongo/ismaster.py @@ -15,16 +15,10 @@ """Parse a response to the 'ismaster' command.""" import itertools -from collections import namedtuple from bson.py3compat import imap from pymongo import common - - -SERVER_TYPE = namedtuple('ServerType', - ['Unknown', 'Mongos', 'RSPrimary', 'RSSecondary', - 'RSArbiter', 'RSOther', 'RSGhost', - 'Standalone'])(*range(8)) +from pymongo.server_type import SERVER_TYPE def _get_server_type(doc): diff --git a/pymongo/monitor.py b/pymongo/monitor.py index daf95a2cf..8e6081723 100644 --- a/pymongo/monitor.py +++ b/pymongo/monitor.py @@ -21,7 +21,8 @@ import time import weakref from pymongo import common, helpers, message, thread_util -from pymongo.ismaster import IsMaster, SERVER_TYPE +from pymongo.server_type import SERVER_TYPE +from pymongo.ismaster import IsMaster from pymongo.read_preferences import MovingAverage from pymongo.server_description import ServerDescription diff --git a/pymongo/server.py b/pymongo/server.py index b70849859..b238875a5 100644 --- a/pymongo/server.py +++ b/pymongo/server.py @@ -14,7 +14,7 @@ """Communicate with one MongoDB server in a cluster.""" -from pymongo.ismaster import SERVER_TYPE +from pymongo.server_type import SERVER_TYPE from pymongo.response import Response, ExhaustResponse diff --git a/pymongo/server_description.py b/pymongo/server_description.py index b24126e5c..6531c5d04 100644 --- a/pymongo/server_description.py +++ b/pymongo/server_description.py @@ -14,7 +14,8 @@ """Represent one server in the cluster.""" -from pymongo.ismaster import IsMaster, SERVER_TYPE +from pymongo.server_type import SERVER_TYPE +from pymongo.ismaster import IsMaster class ServerDescription(object): diff --git a/pymongo/server_selectors.py b/pymongo/server_selectors.py index b3d7ee5e8..edf4f89eb 100644 --- a/pymongo/server_selectors.py +++ b/pymongo/server_selectors.py @@ -14,7 +14,7 @@ """Criteria to select some ServerDescriptions out of a list.""" -from pymongo.ismaster import SERVER_TYPE +from pymongo.server_type import SERVER_TYPE def any_server_selector(server_descriptions): diff --git a/pymongo/server_type.py b/pymongo/server_type.py new file mode 100644 index 000000000..13b2f2da6 --- /dev/null +++ b/pymongo/server_type.py @@ -0,0 +1,23 @@ +# Copyright 2014 MongoDB, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Type codes for MongoDB servers.""" + +from collections import namedtuple + + +SERVER_TYPE = namedtuple('ServerType', + ['Unknown', 'Mongos', 'RSPrimary', 'RSSecondary', + 'RSArbiter', 'RSOther', 'RSGhost', + 'Standalone'])(*range(8)) diff --git a/test/test_cluster.py b/test/test_cluster.py index e29f236ec..6b933cd40 100644 --- a/test/test_cluster.py +++ b/test/test_cluster.py @@ -23,6 +23,7 @@ import threading from bson.py3compat import imap from pymongo import common +from pymongo.server_type import SERVER_TYPE from pymongo.cluster import Cluster from pymongo.cluster_description import CLUSTER_TYPE from pymongo.errors import (ConfigurationError, @@ -31,7 +32,7 @@ from pymongo.errors import (ConfigurationError, from pymongo.ismaster import IsMaster from pymongo.monitor import Monitor from pymongo.read_preferences import MovingAverage -from pymongo.server_description import ServerDescription, SERVER_TYPE +from pymongo.server_description import ServerDescription from pymongo.server_selectors import (any_server_selector, writable_server_selector) from pymongo.settings import ClusterSettings diff --git a/test/test_server_description.py b/test/test_server_description.py index 1253a5af4..fdc66bb5c 100644 --- a/test/test_server_description.py +++ b/test/test_server_description.py @@ -18,9 +18,10 @@ import sys sys.path[0:0] = [""] +from pymongo.server_type import SERVER_TYPE from pymongo.ismaster import IsMaster from pymongo.read_preferences import MovingAverage -from pymongo.server_description import ServerDescription, SERVER_TYPE +from pymongo.server_description import ServerDescription from test import unittest address = ('localhost', 27017)