From 97da3d620714a34f765e4c41025205934dea7013 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Sat, 11 Jul 2020 17:31:36 +0800 Subject: [PATCH] bugfix --- kivyblocks/blocks.py | 4 +- kivyblocks/kivysize.py | 5 ++- kivyblocks/threadcall.py | 85 ++-------------------------------------- 3 files changed, 10 insertions(+), 84 deletions(-) diff --git a/kivyblocks/blocks.py b/kivyblocks/blocks.py index 010e597..3bf70b4 100755 --- a/kivyblocks/blocks.py +++ b/kivyblocks/blocks.py @@ -277,7 +277,8 @@ class Blocks(EventDispatcher): btotal = len(desc.get('subwidgets',[])) def doit(self,widget,bcnt,btotal,desc,o,w): bcnt += 1 - w.parenturl = widget.parenturl + if hasattr(widget,'parenturl'): + w.parenturl = widget.parenturl widget.add_widget(w) if hasattr(widget,'addChild'): widget.addChild(w) @@ -433,7 +434,6 @@ class Blocks(EventDispatcher): except Exception as e: print_exc() doerr(None,e) - print('&&&&&&&&&&&&&&&&&',e) return def doerr(o,e): diff --git a/kivyblocks/kivysize.py b/kivyblocks/kivysize.py index 077f48e..b7e7376 100644 --- a/kivyblocks/kivysize.py +++ b/kivyblocks/kivysize.py @@ -22,7 +22,10 @@ class KivySizes: if config.font_sizes: self.myFontSizes = config.font_sizes 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) if x == None: x = self.myFontSizes.get('normal') diff --git a/kivyblocks/threadcall.py b/kivyblocks/threadcall.py index 3e1add6..0f06ef4 100644 --- a/kivyblocks/threadcall.py +++ b/kivyblocks/threadcall.py @@ -7,7 +7,8 @@ from kivy.event import EventDispatcher from kivy.clock import Clock from kivy.app import App from .login import LoginForm -from .utils import NeedLogin, InsufficientPrivilege, HTTPError + +from appPublic.http_client import Http_Client class ThreadCall(Thread,EventDispatcher): def __init__(self,target, args=(), kwargs={}): @@ -78,85 +79,11 @@ class Workers(Thread): with self.lock: self.tasks.insert(0,[callee,callback,errback,kwargs]) -hostsessions = {} - -class HttpClient: +class HttpClient(Http_Client): def __init__(self): - self.s = requests.Session() - self.s.verify = False + super().__init__() 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", params={}, headers={}, @@ -174,10 +101,6 @@ class HttpClient: return cb(None,resp) except Exception as e: raise e - except Exception as e: - if errback is not None: - errback(e) - return None kwargs = { "url":url, "method":method,