This commit is contained in:
yumoqing 2020-07-11 17:31:36 +08:00
parent 5a099bef66
commit 97da3d6207
3 changed files with 10 additions and 84 deletions

View File

@ -277,7 +277,8 @@ class Blocks(EventDispatcher):
btotal = len(desc.get('subwidgets',[])) btotal = len(desc.get('subwidgets',[]))
def doit(self,widget,bcnt,btotal,desc,o,w): def doit(self,widget,bcnt,btotal,desc,o,w):
bcnt += 1 bcnt += 1
w.parenturl = widget.parenturl if hasattr(widget,'parenturl'):
w.parenturl = widget.parenturl
widget.add_widget(w) widget.add_widget(w)
if hasattr(widget,'addChild'): if hasattr(widget,'addChild'):
widget.addChild(w) widget.addChild(w)
@ -433,7 +434,6 @@ class Blocks(EventDispatcher):
except Exception as e: except Exception as e:
print_exc() print_exc()
doerr(None,e) doerr(None,e)
print('&&&&&&&&&&&&&&&&&',e)
return return
def doerr(o,e): def doerr(o,e):

View File

@ -22,7 +22,10 @@ class KivySizes:
if config.font_sizes: if config.font_sizes:
self.myFontSizes = config.font_sizes self.myFontSizes = config.font_sizes
if name is None: if name is None:
name = getConfig().font_name name = config.font_name
print('font_sizes=',config.font_sizes,
'font_name=',config.font_name,
'myFS=',self.myFontSizes)
x = self.myFontSizes.get(name,None) x = self.myFontSizes.get(name,None)
if x == None: if x == None:
x = self.myFontSizes.get('normal') x = self.myFontSizes.get('normal')

View File

@ -7,7 +7,8 @@ from kivy.event import EventDispatcher
from kivy.clock import Clock from kivy.clock import Clock
from kivy.app import App from kivy.app import App
from .login import LoginForm from .login import LoginForm
from .utils import NeedLogin, InsufficientPrivilege, HTTPError
from appPublic.http_client import Http_Client
class ThreadCall(Thread,EventDispatcher): class ThreadCall(Thread,EventDispatcher):
def __init__(self,target, args=(), kwargs={}): def __init__(self,target, args=(), kwargs={}):
@ -78,85 +79,11 @@ class Workers(Thread):
with self.lock: with self.lock:
self.tasks.insert(0,[callee,callback,errback,kwargs]) self.tasks.insert(0,[callee,callback,errback,kwargs])
hostsessions = {} class HttpClient(Http_Client):
class HttpClient:
def __init__(self): def __init__(self):
self.s = requests.Session() super().__init__()
self.s.verify = False
self.workers = App.get_running_app().workers self.workers = App.get_running_app().workers
def url2domain(self,url):
parts = url.split('/')[:3]
pre = '/'.join(parts)
return pre
def _webcall(self,url,method="GET",
params={},
files={},
headers={},
stream=False):
app = App.get_running_app()
domain = self.url2domain(url)
sessionid = hostsessions.get(domain,None)
if sessionid:
headers.update({'session':sessionid})
elif app.getAuthHeader():
headers.update(app.getAuthHeader())
# print('headers=',headers)
if method in ['GET']:
req = requests.Request(method,url,
params=params,headers=headers)
else:
req = requests.Request(method,url,
data=params,files=files,headers=headers)
prepped = self.s.prepare_request(req)
resp = self.s.send(prepped)
if resp.status_code == 200:
h = resp.headers.get('Set-Cookie',None)
if h:
sessionid = h.split(';')[0]
hostsessions[domain] = sessionid
if resp.status_code == 401:
print('NeedLogin:',url)
raise NeedLogin
if resp.status_code == 403:
raise InsufficientPrivilege
if resp.status_code != 200:
print('Error', url, method,
params, resp.status_code,
type(resp.status_code))
raise HTTPError(resp.status_code)
return resp
def webcall(self,url,method="GET",
params={},
files={},
headers={},
stream=False):
resp = self._webcall(url,method=method,
params=params,
files=files,
headers=headers,
stream=stream)
if stream:
return resp
try:
data = resp.json()
if type(data) != type({}):
return data
status = data.get('status',None)
if status is None:
return data
if status == 'OK':
return data['data']
return data
except:
return resp.text
def __call__(self,url,method="GET", def __call__(self,url,method="GET",
params={}, params={},
headers={}, headers={},
@ -174,10 +101,6 @@ class HttpClient:
return cb(None,resp) return cb(None,resp)
except Exception as e: except Exception as e:
raise e raise e
except Exception as e:
if errback is not None:
errback(e)
return None
kwargs = { kwargs = {
"url":url, "url":url,
"method":method, "method":method,