Ejemplo n.º 1
0
async def parse_responses(responses):
    result = (False, "")
    for r in responses:
        try:
            if not result[0]:
                if isinstance(r, BaseException):
                    result = (False, str(r))
                elif r.status == 400:
                    error = await r.text()
                    try:
                        result = (False,
                                  errors.DuniterError(
                                      bma.parse_error(error)).message)
                    except jsonschema.ValidationError:
                        result = (False, error)
                elif r.status == 200:
                    result = (True, (await r.json()))
                elif not result[0]:
                    result = (False, (await r.text()))
            else:
                await r.release()
        except Exception as e:
            if not result[0]:
                result = (False, str(e))
    return result
Ejemplo n.º 2
0
    def test_parse_error(self):
        api = API(None, "any")
        error = parse_error("""{
"ucode": 1005,
"message": "Document has unkown fields or wrong line ending format"
}""")
        self.assertEqual(error["ucode"], 1005)
        self.assertEqual(
            error["message"],
            "Document has unkown fields or wrong line ending format")
Ejemplo n.º 3
0
Archivo: bma.py Proyecto: duniter/sakia
async def parse_responses(responses):
    result = (False, "")
    for r in responses:
        try:
            if not result[0]:
                if isinstance(r, BaseException):
                    result = (False, str(r))
                elif r.status == 400:
                    error = await r.text()
                    try:
                        result = (False, errors.DuniterError(bma.parse_error(error)).message)
                    except jsonschema.ValidationError:
                        result = (False, error)
                elif r.status == 200:
                    result = (True, (await r.json()))
                elif not result[0]:
                    result = (False, (await r.text()))
            else:
                await r.release()
        except Exception as e:
            if not result[0]:
                result = (False, str(e))
    return result