diff options
author | David Robertson <davidr@element.io> | 2022-05-17 13:47:51 +0100 |
---|---|---|
committer | David Robertson <davidr@element.io> | 2022-05-17 13:55:58 +0100 |
commit | 79f1cef5e42f2fa807b44c7670868714ce28cc0a (patch) | |
tree | 04e9e111ae53bb40bc6a7e1eae8dbb5b3789cc18 | |
parent | Reproduce #12755 (diff) | |
download | synapse-79f1cef5e42f2fa807b44c7670868714ce28cc0a.tar.xz |
Move non_null_str_or_none to s.utils.stringutils
-rw-r--r-- | synapse/storage/databases/main/events.py | 4 | ||||
-rw-r--r-- | synapse/util/stringutils.py | 6 |
2 files changed, 6 insertions, 4 deletions
diff --git a/synapse/storage/databases/main/events.py b/synapse/storage/databases/main/events.py index 42d484dc98..0df8ff5395 100644 --- a/synapse/storage/databases/main/events.py +++ b/synapse/storage/databases/main/events.py @@ -52,6 +52,7 @@ from synapse.storage.util.sequence import SequenceGenerator from synapse.types import JsonDict, StateMap, get_domain_from_id from synapse.util import json_encoder from synapse.util.iterutils import batch_iter, sorted_topologically +from synapse.util.stringutils import non_null_str_or_none if TYPE_CHECKING: from synapse.server import HomeServer @@ -1728,9 +1729,6 @@ class PersistEventsStore: not affect the current local state. """ - def non_null_str_or_none(val: Any) -> Optional[str]: - return val if isinstance(val, str) and "\u0000" not in val else None - self.db_pool.simple_insert_many_txn( txn, table="room_memberships", diff --git a/synapse/util/stringutils.py b/synapse/util/stringutils.py index b26546aecd..11246d95e9 100644 --- a/synapse/util/stringutils.py +++ b/synapse/util/stringutils.py @@ -16,7 +16,7 @@ import itertools import re import secrets import string -from typing import Iterable, Optional, Tuple +from typing import Any, Iterable, Optional, Tuple from netaddr import valid_ipv6 @@ -247,3 +247,7 @@ def base62_encode(num: int, minwidth: int = 1) -> str: # pad to minimum width pad = "0" * (minwidth - len(res)) return pad + res + + +def non_null_str_or_none(val: Any) -> Optional[str]: + return val if isinstance(val, str) and "\u0000" not in val else None |