Skip to content
Myr

use dict instead of if/else logic (#2093)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Raphael Deem · committed by Markus Unterwaditzer · parent 7f28837 · Browse files · 1 file+14 added−10 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+14 added−10 removed

  • other:+14 added−10 removed

1 file+14 added−10 removed

modified:flask/sessions.py+14 added-10 removed
82 unmodified lines
8384 def dumps(self, value):85 return json.dumps(_tag(value), separators=(',', ':'))8687 LOADS_MAP = {88 ' t': tuple,89 ' u': uuid.UUID,90 ' b': b64decode,91 ' m': Markup,92 ' d': parse_date,93 }9495 def loads(self, value):96 def object_hook(obj):97 if len(obj) != 1:98 return obj99 the_key, the_value = next(iteritems(obj))92 if the_key == ' t':93 return tuple(the_value)94 elif the_key == ' u':95 return uuid.UUID(the_value)96 elif the_key == ' b':97 return b64decode(the_value)98 elif the_key == ' m':99 return Markup(the_value)100 elif the_key == ' d':101 return parse_date(the_value)100 # Check the key for a corresponding function101 return_function = self.LOADS_MAP.get(the_key)102 if return_function:103 # Pass the value to the function104 return return_function(the_value)105 # Didn't find a function for this object106 return obj107 return json.loads(value, object_hook=object_hook)108109
257 unmodified lines