mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-12-11 14:44:18 -05:00
Simplify intern_dict
This commit is contained in:
parent
2f0180b09e
commit
8122ad7bab
@ -65,27 +65,20 @@ def intern_string(string):
|
|||||||
def intern_dict(dictionary):
|
def intern_dict(dictionary):
|
||||||
"""Takes a dictionary and interns well known keys and their values
|
"""Takes a dictionary and interns well known keys and their values
|
||||||
"""
|
"""
|
||||||
return _intern_known_values({
|
return {
|
||||||
_intern_key(key): value for key, value in dictionary.items()
|
KNOWN_KEYS.get(key, key): _intern_known_values(key, value)
|
||||||
})
|
for key, value in dictionary.items()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def _intern_known_values(dictionary):
|
def _intern_known_values(key, value):
|
||||||
intern_str_keys = ("event_id", "room_id")
|
intern_str_keys = ("event_id", "room_id")
|
||||||
intern_unicode_keys = ("sender", "user_id", "type", "state_key")
|
intern_unicode_keys = ("sender", "user_id", "type", "state_key")
|
||||||
|
|
||||||
for key in intern_str_keys:
|
if key in intern_str_keys:
|
||||||
val = dictionary.get(key, None)
|
return intern(value.encode('ascii'))
|
||||||
if val is not None:
|
|
||||||
dictionary[key] = intern(val.encode('ascii'))
|
|
||||||
|
|
||||||
for key in intern_unicode_keys:
|
if key in intern_unicode_keys:
|
||||||
val = dictionary.get(key, None)
|
return intern_string(value)
|
||||||
if val is not None:
|
|
||||||
dictionary[key] = intern_string(val)
|
|
||||||
|
|
||||||
return dictionary
|
return value
|
||||||
|
|
||||||
|
|
||||||
def _intern_key(key):
|
|
||||||
return KNOWN_KEYS.get(key, key)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user