Skip to content

Commit 145a05b

Browse files
committed
Support journal and wtimeoutMS URI aliases.
This commit also cleans up some code related to URI options that were never supported in pymongo and have been removed from the URI spec.
1 parent 205279b commit 145a05b

File tree

4 files changed

+21
-14
lines changed

4 files changed

+21
-14
lines changed

pymongo/common.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,23 @@ def validate_basestring(option, value):
6060
"instance of basestring" % (option,))
6161

6262

63+
# jounal is an alias for j,
64+
# wtimeoutms is an alias for wtimeout
6365
VALIDATORS = {
6466
'replicaset': validate_basestring,
6567
'slaveok': validate_boolean,
6668
'safe': validate_boolean,
6769
'w': validate_integer,
6870
'wtimeout': validate_integer,
71+
'wtimeoutms': validate_integer,
6972
'fsync': validate_boolean,
7073
'j': validate_boolean,
74+
'journal': validate_boolean,
7175
'maxpoolsize': validate_integer,
7276
}
7377

7478

7579
UNSUPPORTED = frozenset([
76-
'connect',
77-
'minpoolsize',
78-
'waitqueuetimeoutms',
79-
'waitqueuemultiple',
8080
'connecttimeoutms',
8181
'sockettimeoutms'
8282
])
@@ -85,8 +85,10 @@ def validate_basestring(option, value):
8585
SAFE_OPTIONS = frozenset([
8686
'w',
8787
'wtimeout',
88+
'wtimeoutms',
8889
'fsync',
89-
'j'
90+
'j',
91+
'journal'
9092
])
9193

9294

@@ -124,7 +126,12 @@ def _set_options(self, **options):
124126
elif option == 'safe':
125127
self.safe = value
126128
elif option in SAFE_OPTIONS:
127-
self.__set_safe_option(option, value)
129+
if option == 'journal':
130+
self.__set_safe_option('j', value)
131+
elif option == 'wtimeoutms':
132+
self.__set_safe_option('wtimeout', value)
133+
else:
134+
self.__set_safe_option(option, value)
128135

129136
def __get_slave_okay(self):
130137
"""Is it OK to perform queries on a secondary or slave?

pymongo/connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ def __init__(self, host=None, port=None, max_pool_size=10,
218218
- `slave_okay` or `slaveok`: Is it OK to perform queries if
219219
this connection is to a secondary?
220220
- `safe`: Use getlasterror for each write operation?
221-
- `j`: Block until write operations have been commited to the
222-
journal. Ignored if the server is running without journaling.
221+
- `j` or `journal`: Block until write operations have been commited
222+
to the journal. Ignored if the server is running without journaling.
223223
Implies safe=True.
224224
- `w`: If this is a replica set the server won't return until
225225
write operations have replicated to this many set members.

test/test_common.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ def test_baseobject(self):
5959
cursor = coll.find(slave_okay=False)
6060
self.assertFalse(cursor._Cursor__slave_okay)
6161

62+
c = Connection('mongodb://localhost:27017/?'
63+
'w=2;wtimeoutMS=300;fsync=true;journal=true')
64+
self.assertTrue(c.safe)
65+
d = {'w': 2, 'wtimeout': 300, 'fsync': True, 'j': True}
66+
self.assertEqual(d, c.get_lasterror_options())
67+
6268
c = Connection('mongodb://localhost:27017/?'
6369
'slaveok=true;w=1;wtimeout=300;fsync=true;j=true')
6470
self.assertTrue(c.slave_okay)

test/test_uri_parser.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,6 @@ def test_split_hosts(self):
7373
def test_split_options(self):
7474
# This should remind us to write tests for these if
7575
# they are ever supported.
76-
self.assertRaises(UnsupportedOption, split_options,
77-
'minPoolSize=5')
78-
self.assertRaises(UnsupportedOption, split_options,
79-
'waitQueueTimeoutMS=500')
80-
self.assertRaises(UnsupportedOption, split_options,
81-
'waitQueueMultiple=5')
8276
self.assertRaises(UnsupportedOption, split_options,
8377
'connectTimeoutMS=500')
8478
self.assertRaises(UnsupportedOption, split_options,

0 commit comments

Comments
 (0)