mirror of
https://mau.dev/maunium/synapse.git
synced 2024-12-16 16:03:50 +01:00
Merge pull request #3281 from NotAFile/py3-six-isinstance
remaining isintance fixes
This commit is contained in:
commit
debff7ae09
3 changed files with 18 additions and 13 deletions
|
@ -18,13 +18,14 @@ import logging
|
||||||
import re
|
import re
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
|
|
||||||
|
from six import string_types
|
||||||
|
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
|
|
||||||
from .background_updates import BackgroundUpdateStore
|
from .background_updates import BackgroundUpdateStore
|
||||||
from synapse.api.errors import SynapseError
|
from synapse.api.errors import SynapseError
|
||||||
from synapse.storage.engines import PostgresEngine, Sqlite3Engine
|
from synapse.storage.engines import PostgresEngine, Sqlite3Engine
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
SearchEntry = namedtuple('SearchEntry', [
|
SearchEntry = namedtuple('SearchEntry', [
|
||||||
|
@ -126,7 +127,7 @@ class SearchStore(BackgroundUpdateStore):
|
||||||
# skip over it.
|
# skip over it.
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if not isinstance(value, basestring):
|
if not isinstance(value, string_types):
|
||||||
# If the event body, name or topic isn't a string
|
# If the event body, name or topic isn't a string
|
||||||
# then skip over it
|
# then skip over it
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -31,6 +31,9 @@ import functools
|
||||||
import inspect
|
import inspect
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
|
from six import string_types, itervalues
|
||||||
|
import six
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -205,7 +208,7 @@ class Cache(object):
|
||||||
def invalidate_all(self):
|
def invalidate_all(self):
|
||||||
self.check_thread()
|
self.check_thread()
|
||||||
self.cache.clear()
|
self.cache.clear()
|
||||||
for entry in self._pending_deferred_cache.itervalues():
|
for entry in itervalues(self._pending_deferred_cache):
|
||||||
entry.invalidate()
|
entry.invalidate()
|
||||||
self._pending_deferred_cache.clear()
|
self._pending_deferred_cache.clear()
|
||||||
|
|
||||||
|
@ -392,9 +395,10 @@ class CacheDescriptor(_CacheDescriptorBase):
|
||||||
|
|
||||||
ret.addErrback(onErr)
|
ret.addErrback(onErr)
|
||||||
|
|
||||||
# If our cache_key is a string, try to convert to ascii to save
|
# If our cache_key is a string on py2, try to convert to ascii
|
||||||
# a bit of space in large caches
|
# to save a bit of space in large caches. Py3 does this
|
||||||
if isinstance(cache_key, basestring):
|
# internally automatically.
|
||||||
|
if six.PY2 and isinstance(cache_key, string_types):
|
||||||
cache_key = to_ascii(cache_key)
|
cache_key = to_ascii(cache_key)
|
||||||
|
|
||||||
result_d = ObservableDeferred(ret, consumeErrors=True)
|
result_d = ObservableDeferred(ret, consumeErrors=True)
|
||||||
|
|
|
@ -16,16 +16,17 @@
|
||||||
from frozendict import frozendict
|
from frozendict import frozendict
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
|
|
||||||
|
from six import string_types
|
||||||
|
|
||||||
|
|
||||||
def freeze(o):
|
def freeze(o):
|
||||||
t = type(o)
|
if isinstance(o, dict):
|
||||||
if t is dict:
|
|
||||||
return frozendict({k: freeze(v) for k, v in o.items()})
|
return frozendict({k: freeze(v) for k, v in o.items()})
|
||||||
|
|
||||||
if t is frozendict:
|
if isinstance(o, frozendict):
|
||||||
return o
|
return o
|
||||||
|
|
||||||
if t is str or t is unicode:
|
if isinstance(o, string_types):
|
||||||
return o
|
return o
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -37,11 +38,10 @@ def freeze(o):
|
||||||
|
|
||||||
|
|
||||||
def unfreeze(o):
|
def unfreeze(o):
|
||||||
t = type(o)
|
if isinstance(o, (dict, frozendict)):
|
||||||
if t is dict or t is frozendict:
|
|
||||||
return dict({k: unfreeze(v) for k, v in o.items()})
|
return dict({k: unfreeze(v) for k, v in o.items()})
|
||||||
|
|
||||||
if t is str or t is unicode:
|
if isinstance(o, string_types):
|
||||||
return o
|
return o
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue