Simplify _graphql.py imports

This commit is contained in:
Mads Marquart
2019-03-10 19:54:36 +01:00
parent f20a04b2a0
commit 28c867a115

View File

@@ -1,11 +1,10 @@
# -*- coding: UTF-8 -*- # -*- coding: UTF-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
import json import json
import re import re
from . import _file, _message, _quick_reply from . import _util
from .models import * from ._exception import FBchatException, FBchatUserError
from ._util import *
# Shameless copy from https://stackoverflow.com/a/8730674 # Shameless copy from https://stackoverflow.com/a/8730674
FLAGS = re.VERBOSE | re.MULTILINE | re.DOTALL FLAGS = re.VERBOSE | re.MULTILINE | re.DOTALL
@@ -39,7 +38,7 @@ def graphql_queries_to_json(*queries):
def graphql_response_to_json(content): def graphql_response_to_json(content):
content = strip_to_json(content) # Usually only needed in some error cases content = _util.strip_to_json(content) # Usually only needed in some error cases
try: try:
j = json.loads(content, cls=ConcatJSONDecoder) j = json.loads(content, cls=ConcatJSONDecoder)
except Exception: except Exception:
@@ -50,15 +49,15 @@ def graphql_response_to_json(content):
if "error_results" in x: if "error_results" in x:
del rtn[-1] del rtn[-1]
continue continue
check_json(x) _util.check_json(x)
[(key, value)] = x.items() [(key, value)] = x.items()
check_json(value) _util.check_json(value)
if "response" in value: if "response" in value:
rtn[int(key[1:])] = value["response"] rtn[int(key[1:])] = value["response"]
else: else:
rtn[int(key[1:])] = value["data"] rtn[int(key[1:])] = value["data"]
log.debug(rtn) _util.log.debug(rtn)
return rtn return rtn