當前位置: 首頁>>代碼示例>>Python>>正文


Python ubinascii.a2b_base64方法代碼示例

本文整理匯總了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") 
開發者ID:BetaRavener,項目名稱:uPyLoader,代碼行數:22,代碼來源:upload.py

示例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) 
開發者ID:digidotcom,項目名稱:xbee-micropython,代碼行數:25,代碼來源:main.py

示例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 
開發者ID:pfalcon,項目名稱:picoweb,代碼行數:20,代碼來源:example_basic_auth_deco.py

示例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) 
開發者ID:fadushin,項目名稱:esp8266,代碼行數:16,代碼來源:__init__.py

示例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)) 
開發者ID:pfalcon,項目名稱:picoweb,代碼行數:16,代碼來源:example_basic_auth.py


注:本文中的ubinascii.a2b_base64方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。