@@ -407,7 +407,7 @@ def validate_ok_for_update(update):
407
407
408
408
# journal is an alias for j,
409
409
# wtimeoutms is an alias for wtimeout,
410
- VALIDATORS = {
410
+ URI_VALIDATORS = {
411
411
'replicaset' : validate_string_or_none ,
412
412
'w' : validate_int_or_basestring ,
413
413
'wtimeout' : validate_integer ,
@@ -428,21 +428,27 @@ def validate_ok_for_update(update):
428
428
'ssl_ca_certs' : validate_readable ,
429
429
'ssl_match_hostname' : validate_boolean_or_string ,
430
430
'readconcernlevel' : validate_string_or_none ,
431
- 'read_preference' : validate_read_preference ,
432
431
'readpreference' : validate_read_preference_mode ,
433
432
'readpreferencetags' : validate_read_preference_tags ,
434
433
'localthresholdms' : validate_positive_float_or_zero ,
435
434
'serverselectiontimeoutms' : validate_timeout_or_zero ,
436
435
'authmechanism' : validate_auth_mechanism ,
437
436
'authsource' : validate_string ,
438
437
'authmechanismproperties' : validate_auth_mechanism_properties ,
439
- 'document_class' : validate_document_class ,
440
438
'tz_aware' : validate_boolean_or_string ,
441
439
'uuidrepresentation' : validate_uuid_representation ,
442
440
'connect' : validate_boolean_or_string ,
441
+ }
442
+
443
+ KW_VALIDATORS = {
444
+ 'document_class' : validate_document_class ,
445
+ 'read_preference' : validate_read_preference ,
443
446
'event_listeners' : _validate_event_listeners
444
447
}
445
448
449
+ VALIDATORS = URI_VALIDATORS .copy ()
450
+ VALIDATORS .update (KW_VALIDATORS )
451
+
446
452
447
453
_AUTH_OPTIONS = frozenset (['authmechanismproperties' ])
448
454
@@ -466,18 +472,21 @@ def validate(option, value):
466
472
return lower , value
467
473
468
474
469
- def get_validated_options (options ):
475
+ def get_validated_options (options , warn = True ):
470
476
"""Validate each entry in options and raise a warning if it is not valid.
471
477
Returns a copy of options with invalid entries removed
472
478
"""
473
479
validated_options = {}
474
480
for opt , value in iteritems (options ):
475
481
lower = opt .lower ()
476
482
try :
477
- validator = VALIDATORS .get (lower , raise_config_error )
483
+ validator = URI_VALIDATORS .get (lower , raise_config_error )
478
484
value = validator (opt , value )
479
485
except (ValueError , ConfigurationError ) as exc :
480
- warnings .warn (str (exc ))
486
+ if warn :
487
+ warnings .warn (str (exc ))
488
+ else :
489
+ raise
481
490
else :
482
491
validated_options [lower ] = value
483
492
return validated_options
0 commit comments