当前位置: 首页>>代码示例>>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;未经允许,请勿转载。