コード例 #1
0
ファイル: restful.py プロジェクト: alenstar/hikyuu
def session_post(session: SessionModel,
                 service,
                 api,
                 data=None,
                 json=None,
                 **kwargs):
    def inner_func(session: SessionModel,
                   service,
                   api,
                   data=None,
                   json=None,
                   **kwargs):
        url = getserviceUrl(session.host, session.port, service, api)
        headers = defaultRequestHeader()
        headers["hku_token"] = session.token
        r = post(url, data, json, headers=headers, **kwargs)
        if "update_token" in r:
            session.token = r["update_token"]
        return r

    session.running = False
    if not session.token:
        session = login(session)
    res = inner_func(session, service, api, data, json, **kwargs)
    if not res["result"] and (res['errcode'] == RestErrorCode.AUTHORIZE_EXPIRED
                              or res['errcode']
                              == RestErrorCode.FAILED_AUTHORIZED):
        session = login(session)
        res = inner_func(session, service, api, data, json, **kwargs)
    session.running = True if res["result"] else False
    return res
コード例 #2
0
ファイル: assist.py プロジェクト: majorma-cqc/hikyuu
 def getServerStatus(session: SessionModel):
     try:
         r = session_get(session, "assist", "status")
         if r["result"]:
             session.running = True
             return "running", _translate("service", "running")
         else:
             session.running = False
             return "stop", _translate("service",
                                       "failed! {}").format(r["errmsg"])
     except Exception as e:
         session.running = False
         logging.info("{}: {}".format(e.__class__.__name__, e))
         return "stop", _translate("service", "failed connect!")
コード例 #3
0
def session_get(session: SessionModel, service, api, params=None, **kwargs):
    def inner_get(session: SessionModel, service, api, params, **kwargs):
        url = getserviceUrl(session.host, session.port, service, api)
        headers = defaultRequestHeader()
        headers["hku_token"] = session.token
        r = get(url, headers=headers, params=params, **kwargs)
        if "update_token" in r:
            session.token = r["update_token"]
        return r

    session.running = False
    if not session.token:
        session = login(session)
    res = inner_get(session, service, api, params, **kwargs)
    if not res["result"] and res['errcode'] == RestErrorCode.AUTHORIZE_EXPIRED:
        session = login(session)
        res = inner_get(session, service, api, params, **kwargs)
    session.running = True if res["result"] else False
    return res