@@ -407,7 +407,7 @@ def validate_ok_for_update(update):
407407
408408# journal is an alias for j, 
409409# wtimeoutms is an alias for wtimeout, 
410- VALIDATORS  =  {
410+ URI_VALIDATORS  =  {
411411    'replicaset' : validate_string_or_none ,
412412    'w' : validate_int_or_basestring ,
413413    'wtimeout' : validate_integer ,
@@ -428,21 +428,27 @@ def validate_ok_for_update(update):
428428    'ssl_ca_certs' : validate_readable ,
429429    'ssl_match_hostname' : validate_boolean_or_string ,
430430    'readconcernlevel' : validate_string_or_none ,
431-     'read_preference' : validate_read_preference ,
432431    'readpreference' : validate_read_preference_mode ,
433432    'readpreferencetags' : validate_read_preference_tags ,
434433    'localthresholdms' : validate_positive_float_or_zero ,
435434    'serverselectiontimeoutms' : validate_timeout_or_zero ,
436435    'authmechanism' : validate_auth_mechanism ,
437436    'authsource' : validate_string ,
438437    'authmechanismproperties' : validate_auth_mechanism_properties ,
439-     'document_class' : validate_document_class ,
440438    'tz_aware' : validate_boolean_or_string ,
441439    'uuidrepresentation' : validate_uuid_representation ,
442440    'connect' : validate_boolean_or_string ,
441+ }
442+ 
443+ KW_VALIDATORS  =  {
444+     'document_class' : validate_document_class ,
445+     'read_preference' : validate_read_preference ,
443446    'event_listeners' : _validate_event_listeners 
444447}
445448
449+ VALIDATORS  =  URI_VALIDATORS .copy ()
450+ VALIDATORS .update (KW_VALIDATORS )
451+ 
446452
447453_AUTH_OPTIONS  =  frozenset (['authmechanismproperties' ])
448454
@@ -466,18 +472,21 @@ def validate(option, value):
466472    return  lower , value 
467473
468474
469- def  get_validated_options (options ):
475+ def  get_validated_options (options ,  warn = True ):
470476    """Validate each entry in options and raise a warning if it is not valid. 
471477    Returns a copy of options with invalid entries removed 
472478    """ 
473479    validated_options  =  {}
474480    for  opt , value  in  iteritems (options ):
475481        lower  =  opt .lower ()
476482        try :
477-             validator  =  VALIDATORS .get (lower , raise_config_error )
483+             validator  =  URI_VALIDATORS .get (lower , raise_config_error )
478484            value  =  validator (opt , value )
479485        except  (ValueError , ConfigurationError ) as  exc :
480-             warnings .warn (str (exc ))
486+             if  warn :
487+                 warnings .warn (str (exc ))
488+             else :
489+                 raise 
481490        else :
482491            validated_options [lower ] =  value 
483492    return  validated_options 
0 commit comments