diff --git a/boards/default_src/micropython/origin/build/lib/tiny_webdb.py b/boards/default_src/micropython/origin/build/lib/tiny_webdb.py index 2c513fe4..7ff1fde1 100644 --- a/boards/default_src/micropython/origin/build/lib/tiny_webdb.py +++ b/boards/default_src/micropython/origin/build/lib/tiny_webdb.py @@ -1,5 +1,16 @@ 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: @@ -23,14 +34,14 @@ class TinyWebDB: self._password = password def update(self, key, value): - key = urllib_parse.quote(str(key)) - value = urllib_parse.quote(str(value)) + key = url_quote(str(key)) + value = url_quote(str(value)) result = self._request("update", "tag={}&value={}".format(key, value)) if "status" in result and result["status"] == "error": raise RuntimeError(result["message"]) def get(self, key): - key = urllib_parse.quote(str(key)) + key = url_quote(str(key)) result = self._request("get", "tag={}".format(key)) if "status" in result and result["status"] == "error": raise RuntimeError(result["message"]) @@ -45,14 +56,14 @@ class TinyWebDB: def search(self, no=1, count=1, tag='', dtype='both'): no = str(no) 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)) if "status" in result and result["status"] == "error": raise RuntimeError(result["message"]) return result["data"] def delete(self, key): - key = urllib_parse.quote(str(key)) + key = url_quote(str(key)) result = self._request("delete", "tag={}".format(key)) if "status" in result and result["status"] == "error": raise RuntimeError(result["message"])