zoukankan      html  css  js  c++  java
  • 项目里用到的python知识点


    1 ini文件处理
    创建ini文件
    config = configparser.ConfigParser()
    config.read(AUTH_STATUS_FILE)
    config.add_section("authorization")
    config.set("authorization", "file_status", "normal")    
    config.set("authorization", "auth_status", "normal")
    config.set("authorization", "remain_time", "100")
    config.add_section("systime")
    config.set("systime", "file_status", "normal")
    config.set("systime", "time_status", "normal")
    config.write(open(AUTH_STATUS_FILE, "w"))  
    从字符串解析ini文件
    config = configparser.ConfigParser(allow_no_value=True)
    config.read_string(auth_info.decode())
    auth_id = config.get('auth_id', 'id')
    start_time = config.get('auth_date', 'start')
    end_time = config.get('auth_date', 'end')

    2 时间转换与比较
    tStart = time.strptime(start_time, "%Y%m%d%H%M%S")
    tEnd = time.strptime(end_time, "%Y%m%d%H%M%S")
    dStart = datetime.datetime(* tStart[:6])
    dEnd = datetime.datetime(* tEnd[:6])
    dCurrent = datetime.datetime.now()

    3 文件读写
    with open(FACEMP_AUTH_OUT, 'r') as f:
        auth_crypt_info = f.read()
        
    4 把python源码编译为pyc
    py_compile.compile('./facemp_check.py')

    5 生成rsa公私钥对
    from M2Crypto import RSA,BIO
    rsa = RSA.gen_key(1024, 3, lambda *agr:None)
    rsa.save_pub_key('facemp_pub.key')
    rsa.save_key('facemp_pri.key', None)

    6 私钥加密
    privkey = M2Crypto.RSA.load_key('facemp_pri.key')
    encrypted = privkey.private_encrypt(message, M2Crypto.RSA.pkcs1_padding)

    7 公钥解密
    pubkey = M2Crypto.RSA.load_pub_key(FACEMP_PUB_KEY)
    auth_info = pubkey.public_decrypt(auth_crypt_info, M2Crypto.RSA.pkcs1_padding)   

     

  • 相关阅读:
    EasyUI中datagrid的行编辑模式中,找到特定的Editor,并为其添加事件
    easyui datagrid plunges 扩展 插件
    jQuery EasyUI DataGrid Checkbox 数据设定与取值
    Easyui Tree方法扩展
    记账凭证
    部分扩展功能总结
    凭证
    voucer
    Box2D 一、学习资料(库、pdf)
    EUI EXML内部类Skin和ItemRenderer
  • 原文地址:https://www.cnblogs.com/mingzhang/p/7543438.html
Copyright © 2011-2022 走看看