How to use the aiocache.serializers.JsonSerializer function in aiocache

To help you get started, we’ve selected a few aiocache examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github argaen / aiocache / tests / ut / test_serializers.py View on Github external
def test_init(self):
        serializer = JsonSerializer()
        assert isinstance(serializer, BaseSerializer)
        assert serializer.DEFAULT_ENCODING == "utf-8"
        assert serializer.encoding == "utf-8"
github argaen / aiocache / tests / ut / test_serializers.py View on Github external
def test_dumps(self):
        assert (
            JsonSerializer().dumps({"hi": 1}) == '{"hi": 1}'
            or JsonSerializer().dumps({"hi": 1}) == '{"hi":1}'  # json
        )  # ujson
github argaen / aiocache / tests / ut / test_serializers.py View on Github external
def test_loads_with_none(self):
        assert JsonSerializer().loads(None) is None
github argaen / aiocache / tests / ut / test_factory.py View on Github external
def test_set_config_updates_existing_values(self):
        assert not isinstance(caches.get("default").serializer, JsonSerializer)
        caches.set_config(
            {
                "default": {
                    "cache": "aiocache.SimpleMemoryCache",
                    "serializer": {"class": "aiocache.serializers.JsonSerializer"},
                }
            }
        )
        assert isinstance(caches.get("default").serializer, JsonSerializer)
github argaen / aiocache / tests / ut / test_serializers.py View on Github external
def test_init_fails_if_msgpack_not_installed(self):
        with mock.patch("aiocache.serializers.serializers.msgpack", None):
            with pytest.raises(RuntimeError):
                MsgPackSerializer()
            assert JsonSerializer(), "Other serializers should still initialize"
github argaen / aiocache / tests / ut / test_serializers.py View on Github external
def test_dumps_with_none(self):
        assert JsonSerializer().dumps(None) == "null"
github argaen / aiocache / tests / ut / test_serializers.py View on Github external
def test_dumps_and_loads(self):
        obj = {"hi": 1}
        serializer = JsonSerializer()
        assert serializer.loads(serializer.dumps(obj)) == obj
github zibuyu1995 / ApplicationInImageProcessing / orb_image_search / app.py View on Github external
async def new_search(request):
    upload_image = request.files.get("image")
    if not upload_image:
        raise NotFound(message='not image file')
    image_types = ['image/jpeg', 'image/jpg', 'image/png']
    if upload_image.type not in image_types:
        raise NotFound(message='not image file')
    upload_image_type = upload_image.type.split('/')[-1]
    file_name = str(time.time())[:10] + '.' + upload_image_type
    file_path = upload_image_path + file_name
    with open(file_path, "wb") as f:
        f.write(request.files["image"][0].body)
    search_results = image_search(file_path)[:5]
    cache = SimpleMemoryCache(serializer=JsonSerializer())
    response_dict = {
        'site_name': site_name,
        'upload_image': file_name,
        'search_results': search_results
    }
    await cache.set("response_dict", response_dict)
    return response_dict
github argaen / aiocache / aiocache / backends / redis.py View on Github external
def __init__(self, serializer=None, **kwargs):
        super().__init__(**kwargs)
        self.serializer = serializer or JsonSerializer()
github argaen / aiocache / aiocache / backends / memcached.py View on Github external
def __init__(self, serializer=None, **kwargs):
        super().__init__(**kwargs)
        self.serializer = serializer or JsonSerializer()