コード例 #1
0
def test_format_json():
    text = '[,,"en",,,,0.96954316,,[["en"],,[0.96954316]]]'

    result = utils.format_json(text)

    assert result == [
        None, None, 'en', None, None, None, 0.96954316, None,
        [['en'], None, [0.96954316]]
    ]
コード例 #2
0
    async def _translate(self, text, dest, src):
        token = await self.token_acquirer.do(text)
        params = utils.build_params(query=text, src=src, dest=dest,
                                    token=token)
        url = urls.TRANSLATE.format(host=self._pick_service_url())

        with aiohttp.ClientSession(headers=self.headers) as session:
            async with session.get(url + '?' + params) as resp:
                text = await resp.text()

        return utils.format_json(text)
コード例 #3
0
    async def _translate(self, text, dest, src, proxy):
        if self.session is None:
            await self._make_session()

        token = await self.loop.run_in_executor(None,
                                                self.token.calculate_token,
                                                text)

        params = utils.build_params(query=text,
                                    src=src,
                                    dest=dest,
                                    token=token)
        url = urls.TRANSLATE.format(host=self._pick_service_url())

        async with self.session.get(f'{url}?{params}', proxy=proxy) as resp:
            text = await resp.text()

        return utils.format_json(text)
コード例 #4
0
def test_format_malformed_json():
    text = '[,,"en",,,,0.96954316,,[["en"],,0.96954316]]]'

    with raises(ValueError):
        utils.format_json(text)