o Sbv@sBdZddlmZmZmZmZddlmZGdddeZ e Z dS)z&Tools for working with write concerns.)AnyDictOptionalUnion)ConfigurationErrorc @seZdZdZdZ    ddeeeefdeedee dee ddf d d Z e de fd d Z e de eeffd dZe de fddZddZdede fddZdede fddZdS) WriteConcernaWriteConcern :Parameters: - `w`: (integer or string) Used with replication, write operations will block until they have been replicated to the specified number or tagged set of servers. `w=` always includes the replica set primary (e.g. w=3 means write to the primary and wait until replicated to **two** secondaries). **w=0 disables acknowledgement of write operations and can not be used with other write concern options.** - `wtimeout`: (integer) Used in conjunction with `w`. Specify a value in milliseconds to control how long to wait for write propagation to complete. If replication does not complete in the given timeframe, a timeout exception is raised. - `j`: If ``True`` block until write operations have been committed to the journal. Cannot be used in combination with `fsync`. Write operations will fail with an exception if this option is used when the server is running without journaling. - `fsync`: If ``True`` and the server is running without journaling, blocks until the server has synced all data files to disk. If the server is running with journaling, this acts the same as the `j` option, blocking until write operations have been committed to the journal. Cannot be used in combination with `j`. )Z __documentZ__acknowledgedZ__server_defaultNwwtimeoutjfsyncreturncCsi|_d|_|dur t|tstd|dkrtd||jd<|dur2t|ts-td||jd<|durLt|ts?td|rG|rGtd ||jd <|dkrX|durXtd |dur}t|tro|dkritd |dk|_n t|tsxtd ||jd<|j |_ dS)NTzwtimeout must be an integerrzwtimeout cannot be less than 0r zj must be True or Falser zfsync must be True or Falsez+Can't set both j and fsync at the same timer zCannot set w to 0 and j to Truezw cannot be less than 0zw must be an integer or stringr) _WriteConcern__document_WriteConcern__acknowledged isinstanceint TypeError ValueErrorboolrstr_WriteConcern__server_default)selfrr r r rtsz(WriteConcern.__repr__..)joinr itemsrrrr__repr__ss zWriteConcern.__repr__othercCst|tr |j|jkStSNrrr rNotImplementedrr%rrr__eq__v  zWriteConcern.__eq__cCst|tr |j|jkStSr&r'r)rrr__ne__{r+zWriteConcern.__ne__)NNNN)__name__ __module__ __qualname____doc__ __slots__rrrrrrpropertyrrrrrr$r*r,rrrrrs6 + rN) r0typingrrrrZpymongo.errorsrobjectrZDEFAULT_WRITE_CONCERNrrrrs   k