本文整理汇总了Python中ubinascii.a2b_base64方法的典型用法代码示例。如果您正苦于以下问题:Python ubinascii.a2b_base64方法的具体用法?Python ubinascii.a2b_base64怎么用?Python ubinascii.a2b_base64使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ubinascii
的用法示例。
在下文中一共展示了ubinascii.a2b_base64方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _upload
# 需要导入模块: import ubinascii [as 别名]
# 或者: from ubinascii import a2b_base64 [as 别名]
def _upload():
suc = False
with open("file_name.py", "wb") as f:
while True:
d = _read_timeout(3)
if not d or d[0] != "#":
x = sys.stdout.write("#2")
break
cnt = int(d[1:3])
if cnt == 0:
suc = True
break
d = _read_timeout(cnt)
if d:
x = f.write(a2b_base64(d))
x = sys.stdout.write("#1")
else:
x = sys.stdout.write("#3")
break
x = sys.stdout.write("#0" if suc else "#4")
示例2: generate_sas_token
# 需要导入模块: import ubinascii [as 别名]
# 或者: from ubinascii import a2b_base64 [as 别名]
def generate_sas_token(uri: str, key: str, policy_name=None, expiry: int = 36000) -> str:
"""
Create an Azure SAS token.
:param uri: URI/URL/Host Name to connect to with the token.
:param key: The key.
:param policy_name: Not sure what it is right now, defaults to None.
:param expiry: How long until the token expires. defaults to one hour.
:return: An SAS token to be used with Azure.
"""
ttl = time() + expiry + 946684800
sign_key = "{uri}\n{ttl}".format(uri=quote_plus(uri), ttl=int(ttl))
signature = b64encode(hmac_digest(b64decode(key), sign_key.encode())).rstrip(b'\n')
rawtoken = {
'sr': uri,
'sig': signature,
'se': str(int(ttl))
}
if policy_name is not None:
rawtoken['skn'] = policy_name
return 'SharedAccessSignature ' + urlencode(rawtoken)
示例3: require_auth
# 需要导入模块: import ubinascii [as 别名]
# 或者: from ubinascii import a2b_base64 [as 别名]
def require_auth(func):
def auth(req, resp):
auth = req.headers.get(b"Authorization")
if not auth:
yield from resp.awrite(
'HTTP/1.0 401 NA\r\n'
'WWW-Authenticate: Basic realm="Picoweb Realm"\r\n'
'\r\n'
)
return
auth = auth.split(None, 1)[1]
auth = ubinascii.a2b_base64(auth).decode()
req.username, req.passwd = auth.split(":", 1)
yield from func(req, resp)
return auth
示例4: is_authorized
# 需要导入模块: import ubinascii [as 别名]
# 或者: from ubinascii import a2b_base64 [as 别名]
def is_authorized(self, authorization):
import ubinascii
try:
tmp = authorization.split()
if tmp[0].lower() == "basic":
str = ubinascii.a2b_base64(tmp[1].strip().encode()).decode()
ra = str.split(':')
auth_result = ra[0] == self._config['user'] and ra[1] == self._config['password']
return auth_result, ra[0]
else:
raise BadRequestException(
"Unsupported authorization method: {}".format(tmp[0]))
except Exception as e:
raise BadRequestException(e)
示例5: index
# 需要导入模块: import ubinascii [as 别名]
# 或者: from ubinascii import a2b_base64 [as 别名]
def index(req, resp):
if b"Authorization" not in req.headers:
yield from resp.awrite(
'HTTP/1.0 401 NA\r\n'
'WWW-Authenticate: Basic realm="Picoweb Realm"\r\n'
'\r\n'
)
return
auth = req.headers[b"Authorization"].split(None, 1)[1]
auth = ubinascii.a2b_base64(auth).decode()
username, passwd = auth.split(":", 1)
yield from picoweb.start_response(resp)
yield from resp.awrite("You logged in with username: %s, password: %s" % (username, passwd))