示例#1
0
    def test_set_json(self) -> None:
        """Ensure that changing the underlying JSON implementation works."""
        mock_json = mock.Mock(spec=["JSONEncoder"])
        mock_json.JSONEncoder.return_value.encode.return_value = "sentinel"
        try:
            set_json_library(mock_json)
            self.assertEqual(encode_canonical_json({}), b"sentinel")
        finally:
            # Reset the JSON library to whatever was originally set.
            from canonicaljson import json  # type: ignore[attr-defined]

            set_json_library(json)
示例#2
0
# Twisted and canonicaljson will fail to import when this file is executed to
# get the __version__ during a fresh install. That's OK and subsequent calls to
# actually start Synapse will import these libraries fine.
try:
    from twisted.internet import protocol
    from twisted.internet.protocol import Factory
    from twisted.names.dns import DNSDatagramProtocol

    protocol.Factory.noisy = False
    Factory.noisy = False
    DNSDatagramProtocol.noisy = False
except ImportError:
    pass

# Use the standard library json implementation instead of simplejson.
try:
    from canonicaljson import set_json_library

    set_json_library(json)
except ImportError:
    pass

__version__ = get_distribution_version_string("matrix-synapse")

if bool(os.environ.get("SYNAPSE_TEST_PATCH_LOG_CONTEXTS", False)):
    # We import here so that we don't have to install a bunch of deps when
    # running the packaging tox test.
    from synapse.util.patch_inline_callbacks import do_patch

    do_patch()
示例#3
0
import aiosqlite
import attr
import canonicaljson
import cattr
from aiosqlite import Connection

from scone.head.dag import Resource
from scone.head.recipe import recipe_name_getter
from scone.head.variables import Variables

if TYPE_CHECKING:
    from scone.head.dag import RecipeDag
    from scone.head.recipe import Recipe

canonicaljson.set_json_library(json)
logger = logging.getLogger(__name__)

# TODO(security, low): how to prevent passwords being recovered from the
#  paramhashes in a dependency store?


def _canonicalise_dict(input: Dict[str, Any]) -> Dict[str, Any]:
    output: Dict[str, Any] = {}
    for key, value in input.items():
        if isinstance(value, dict):
            output[key] = _canonicalise_dict(value)
        elif isinstance(value, set):
            new_list = list(value)
            new_list.sort()
            output[key] = new_list