Skip to content

Commit

Permalink
Support journal and wtimeoutMS URI aliases.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
behackett committed Aug 1, 2011
1 parent 205279b commit 145a05b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
19 changes: 13 additions & 6 deletions pymongo/common.py
Expand Up @@ -60,23 +60,23 @@ def validate_basestring(option, value):
"instance of basestring" % (option,))


# jounal is an alias for j,
# wtimeoutms is an alias for wtimeout
VALIDATORS = {
'replicaset': validate_basestring,
'slaveok': validate_boolean,
'safe': validate_boolean,
'w': validate_integer,
'wtimeout': validate_integer,
'wtimeoutms': validate_integer,
'fsync': validate_boolean,
'j': validate_boolean,
'journal': validate_boolean,
'maxpoolsize': validate_integer,
}


UNSUPPORTED = frozenset([
'connect',
'minpoolsize',
'waitqueuetimeoutms',
'waitqueuemultiple',
'connecttimeoutms',
'sockettimeoutms'
])
Expand All @@ -85,8 +85,10 @@ def validate_basestring(option, value):
SAFE_OPTIONS = frozenset([
'w',
'wtimeout',
'wtimeoutms',
'fsync',
'j'
'j',
'journal'
])


Expand Down Expand Up @@ -124,7 +126,12 @@ def _set_options(self, **options):
elif option == 'safe':
self.safe = value
elif option in SAFE_OPTIONS:
self.__set_safe_option(option, value)
if option == 'journal':
self.__set_safe_option('j', value)
elif option == 'wtimeoutms':
self.__set_safe_option('wtimeout', value)
else:
self.__set_safe_option(option, value)

def __get_slave_okay(self):
"""Is it OK to perform queries on a secondary or slave?
Expand Down
4 changes: 2 additions & 2 deletions pymongo/connection.py
Expand Up @@ -218,8 +218,8 @@ def __init__(self, host=None, port=None, max_pool_size=10,
- `slave_okay` or `slaveok`: Is it OK to perform queries if
this connection is to a secondary?
- `safe`: Use getlasterror for each write operation?
- `j`: Block until write operations have been commited to the
journal. Ignored if the server is running without journaling.
- `j` or `journal`: Block until write operations have been commited
to the journal. Ignored if the server is running without journaling.
Implies safe=True.
- `w`: If this is a replica set the server won't return until
write operations have replicated to this many set members.
Expand Down
6 changes: 6 additions & 0 deletions test/test_common.py
Expand Up @@ -59,6 +59,12 @@ def test_baseobject(self):
cursor = coll.find(slave_okay=False)
self.assertFalse(cursor._Cursor__slave_okay)

c = Connection('mongodb://localhost:27017/?'
'w=2;wtimeoutMS=300;fsync=true;journal=true')
self.assertTrue(c.safe)
d = {'w': 2, 'wtimeout': 300, 'fsync': True, 'j': True}
self.assertEqual(d, c.get_lasterror_options())

c = Connection('mongodb://localhost:27017/?'
'slaveok=true;w=1;wtimeout=300;fsync=true;j=true')
self.assertTrue(c.slave_okay)
Expand Down
6 changes: 0 additions & 6 deletions test/test_uri_parser.py
Expand Up @@ -73,12 +73,6 @@ def test_split_hosts(self):
def test_split_options(self):
# This should remind us to write tests for these if
# they are ever supported.
self.assertRaises(UnsupportedOption, split_options,
'minPoolSize=5')
self.assertRaises(UnsupportedOption, split_options,
'waitQueueTimeoutMS=500')
self.assertRaises(UnsupportedOption, split_options,
'waitQueueMultiple=5')
self.assertRaises(UnsupportedOption, split_options,
'connectTimeoutMS=500')
self.assertRaises(UnsupportedOption, split_options,
Expand Down

0 comments on commit 145a05b

Please sign in to comment.