fix(boards): 修复micropython下由于urllib_parse模块所导致的内存占用异常
This commit is contained in:
@@ -1,5 +1,16 @@
|
|||||||
import urequests as requests
|
import urequests as requests
|
||||||
import urllib_parse
|
|
||||||
|
|
||||||
|
def url_quote(s):
|
||||||
|
safe = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.-"
|
||||||
|
s = str(s)
|
||||||
|
res = bytearray()
|
||||||
|
for b in s.encode('utf-8'):
|
||||||
|
if b in safe:
|
||||||
|
res.append(b)
|
||||||
|
else:
|
||||||
|
res.extend(b'%' + b'%02X' % b)
|
||||||
|
return res.decode()
|
||||||
|
|
||||||
|
|
||||||
class TinyWebDB:
|
class TinyWebDB:
|
||||||
@@ -23,14 +34,14 @@ class TinyWebDB:
|
|||||||
self._password = password
|
self._password = password
|
||||||
|
|
||||||
def update(self, key, value):
|
def update(self, key, value):
|
||||||
key = urllib_parse.quote(str(key))
|
key = url_quote(str(key))
|
||||||
value = urllib_parse.quote(str(value))
|
value = url_quote(str(value))
|
||||||
result = self._request("update", "tag={}&value={}".format(key, value))
|
result = self._request("update", "tag={}&value={}".format(key, value))
|
||||||
if "status" in result and result["status"] == "error":
|
if "status" in result and result["status"] == "error":
|
||||||
raise RuntimeError(result["message"])
|
raise RuntimeError(result["message"])
|
||||||
|
|
||||||
def get(self, key):
|
def get(self, key):
|
||||||
key = urllib_parse.quote(str(key))
|
key = url_quote(str(key))
|
||||||
result = self._request("get", "tag={}".format(key))
|
result = self._request("get", "tag={}".format(key))
|
||||||
if "status" in result and result["status"] == "error":
|
if "status" in result and result["status"] == "error":
|
||||||
raise RuntimeError(result["message"])
|
raise RuntimeError(result["message"])
|
||||||
@@ -45,14 +56,14 @@ class TinyWebDB:
|
|||||||
def search(self, no=1, count=1, tag='', dtype='both'):
|
def search(self, no=1, count=1, tag='', dtype='both'):
|
||||||
no = str(no)
|
no = str(no)
|
||||||
count = str(count)
|
count = str(count)
|
||||||
tag = urllib_parse.quote(tag)
|
tag = url_quote(tag)
|
||||||
result = self._request("search", "no={}&count={}&tag={}&type={}".format(no, count, tag, dtype))
|
result = self._request("search", "no={}&count={}&tag={}&type={}".format(no, count, tag, dtype))
|
||||||
if "status" in result and result["status"] == "error":
|
if "status" in result and result["status"] == "error":
|
||||||
raise RuntimeError(result["message"])
|
raise RuntimeError(result["message"])
|
||||||
return result["data"]
|
return result["data"]
|
||||||
|
|
||||||
def delete(self, key):
|
def delete(self, key):
|
||||||
key = urllib_parse.quote(str(key))
|
key = url_quote(str(key))
|
||||||
result = self._request("delete", "tag={}".format(key))
|
result = self._request("delete", "tag={}".format(key))
|
||||||
if "status" in result and result["status"] == "error":
|
if "status" in result and result["status"] == "error":
|
||||||
raise RuntimeError(result["message"])
|
raise RuntimeError(result["message"])
|
||||||
|
|||||||
Reference in New Issue
Block a user