Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

se-import

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

se-import

se-import: Modules import in a safe source protection, support for python module code and custom des encryption, ase decryption operation or custom decryption callback module loading

  • 0.0.9
  • PyPI
  • Socket score

Maintainers
1

se-import: Modules import in a safe source protection, support for python module code and custom des encryption, ase decryption operation or custom decryption callback module loading

# -*- coding: utf-8 -*-
# @Time    : 2021/11/10 11:22
'''
    模块的安全导入,对python模块代码支持des和自定义加密,运行des解密或者自定义解密回调
'''

se_import demo:

# -*- coding: utf-8 -*-
# @Time    : 2021/11/9 16:42

import sys
import se_import
print(dir(se_import))

#从内存加载模块
def test_load_mem():
    s = "a = 100\nb=1000"
    #自定义模块名
    name = 'test_load_mem_test'
    ret = se_import.load_module(name,s,name + '.py')
    print(ret)
    print(dir(ret))
    print(ret.a)
    print(ret.b)

#从内存加载模块,支持模块解密回调
def test_load_custom():
    #从内存加载模块
    s = "a = 100\nb=1000"
    # 自定义模块名
    name = 'load_module_custom_test'
    ret= se_import.load_module_custom(name,s,name + '.py',lambda x:x + '\nadasdadada=1000')
    print(ret)
    print(dir(ret))
    print(ret.a)
    print(ret.b)

#从本地 ase加密文件加载模块
def test_save_load_asefile():

    #模块ase 加密,保存到文件
    infile = "./ase.py"
    outfile = './ase.pys'
    key = bytes([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])
    iv = bytes([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])
    #第一个参数类型是字符串 是文件名, bytes 则为二进制文件内容
    ret = se_import.dump_module_to_asefile(infile, key, iv)
    with open(outfile,mode='wb') as f:
        f.write(ret)

    #从文件加载加密模块
    # 自定义模块名
    infile = './ase.pys'
    name = 'test_save_load_asefile_test'
    ret2 = se_import.load_module_from_asefile(name,infile,name + '.py')
    print(ret2)
    print(dir(ret2))

if __name__ == '__main__':
    test_save_load_asefile()

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc