def merge_setting(request_setting, session_setting, dict_class=OrderedDict):
if session_setting is None:<EOL><INDENT>return request_setting<EOL><DEDENT>if request_setting is None:<EOL><INDENT>return session_setting<EOL><DEDENT>if not (<EOL>isinstance(session_setting, Mapping) and<EOL>isinstance(request_setting, Mapping)<EOL>):<EOL><INDENT>return request_setting<EOL><DEDENT>merged_setting = dict_class(to_key_val_list(session_setting))<EOL>merged_setting.update(to_key_val_list(request_setting))<EOL>for (k, v) in request_setting.items():<EOL><INDENT>if v is None:<EOL><INDENT>del merged_setting[k]<EOL><DEDENT><DEDENT>merged_setting = dict((k, v) for (k, v) in merged_setting.items() if v is not None)<EOL>return merged_setting<EOL>
Determines appropriate setting for a given request, taking into account the
explicit setting on that request, and the setting in the session. If a
setting is a dictionary, they will be merged together using `dict_class`