1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
def _with_default_values(document):
if 'w' in document:
return document
return dict(document, w=1)
class WriteConcern:
def __init__(self, w=None, wtimeout=None, j=None, fsync=None):
self._document = {}
if w is not None:
self._document['w'] = w
if wtimeout is not None:
self._document['wtimeout'] = wtimeout
if j is not None:
self._document['j'] = j
if fsync is not None:
self._document['fsync'] = fsync
def __eq__(self, other):
try:
return _with_default_values(other.document) == _with_default_values(self.document)
except AttributeError:
return NotImplemented
def __ne__(self, other):
try:
return _with_default_values(other.document) != _with_default_values(self.document)
except AttributeError:
return NotImplemented
@property
def acknowledged(self):
return True
@property
def document(self):
return self._document.copy()
@property
def is_server_default(self):
return not self._document
|