一个奇怪的函数

在代码里看到的,感觉没用。删了也能跑,但是不敢删。所以先在这里备份一下。

def b64toUnicode(self, s):
    def switch(self, s):
        """
        Rewrite the code based on Javascript. May have a shift but no overflow error.
        """
        unsignedRshift = lambda val, n: val >> n if val >= 0 else (val + 0x100000000) >> n
        L = len(s)
        if L == 4:
            t = ((7 & ord(s[0])) << 18 | (63 & ord(s[1])) << 12 | (63 & ord(s[2])) << 6 | 63 & ord(s[3])) - 65536
            return chr((55296 + unsignedRshift(t, 10)) & 0xffff) + chr((56320 + (1023 & t)) & 0xffff)
        elif L == 3:
            return chr(((15 & ord(s[0])) << 12 | (63 & ord(s[1])) << 6 | 63 & ord(s[2])) & 0xffff)
        else:
            return chr(((31 & ord(s[0])) << 6 | 63 & ord(s[1])) & 0xffff)
    return re.sub(r'/[À-ß][€-¿]|[à-ï][€-¿]{2}|[ð-÷][€-¿]{3}/g', switch, s)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值