Browse Source

Private members

tags/v0.0.8
Laurent Kislaire 1 year ago
parent
commit
97f56177a6
1 changed files with 13 additions and 13 deletions
  1. +13
    -13
      pyfbx/client.py

+ 13
- 13
pyfbx/client.py View File

@@ -86,8 +86,8 @@ class Fbx():
def __init__(self, url=None, nomdns=False, session=None):
self.log = logging.getLogger("pyfbx.fbx")
self._trn = Transport(url, nomdns=nomdns, session=session)
self.app_id = None
self.token = None
self._app_id = None
self._token = None

# Create on the fly attributes to classes
_globals = globals()
@@ -100,10 +100,10 @@ class Fbx():
"""
Register app
"""
self.app_id = app_id
data = {"app_id": self.app_id, "app_name": app_name, "device_name": device}
self._app_id = app_id
data = {"app_id": self._app_id, "app_name": app_name, "device_name": device}
res = self._trn.api_exec("POST", "login/authorize/", data)
trackid, self.token = res["track_id"], res["app_token"]
trackid, self._token = res["track_id"], res["app_token"]
s = "pending"
self.log.info("Press Ok on the freebox to register application")
while s == "pending":
@@ -111,29 +111,29 @@ class Fbx():
if s == "pending":
time.sleep(1)
self.log.debug("Registration returned: {}".format(s))
return s == "granted" and self.token
return s == "granted" and self._token

def mksession(self, app_id=None, token=None):
self.log.debug("Making session with token={}[{}], app_id={}[{}]".format(
token, self.token, self.app_id, app_id))
token, self._token, app_id, self._app_id))
if token: # Don't overwrite previous token (used for refresh)
self.token = token
self._token = token
if app_id:
self.app_id = app_id
elif not self.app_id:
self._app_id = app_id
elif not self._app_id:
raise Exception("Missing app_id")
login = self._trn.api_exec("GET", "login/")
if not login['logged_in']:
data = {
"app_id": self.app_id,
"password": hmac.new(bytes(self.token, "ascii"),
"app_id": self._app_id,
"password": hmac.new(bytes(self._token, "ascii"),
bytes(login['challenge'], "ascii"),
hashlib.sha1).hexdigest()
}
resp = self._trn.api_exec("POST", "login/session/", data)
session_token = resp["session_token"]
self._trn.set_header(session_token)
self.log.info("Authenticated. Storing token={}, app_id={}".format(self.token, self.app_id))
self.log.info("Authenticated. Storing token={}, app_id={}".format(self._token, self._app_id))
return resp["permissions"]




Loading…
Cancel
Save