美文网首页
Python直接根据URL直接调用远程代码

Python直接根据URL直接调用远程代码

作者: 飞翔的理念 | 来源:发表于2019-08-19 11:51 被阅读0次

https://www.fuweihu.xyz/2019/08/05/Python%E7%9B%B4%E6%8E%A5%E6%A0%B9%E6%8D%AEURL%E7%9B%B4%E6%8E%A5%E8%B0%83%E7%94%A8%E8%BF%9C%E7%A8%8B%E4%BB%A3%E7%A0%81/#more

#!/usr/bin/env python3

# =============================================================================
# File Name: load_code.py
# Author: DaiDai
# Mail: daidai4269@aliyun.com
# Created Time: Fri 02 Aug 2019 04:41:19 PM CST
# =============================================================================


"""
TODO:
    proxy


example:

from load_code import LoadCode
LoadCode("xxx/xxx")  # py code url, xxx is a url
"""


import os
import sys
import requests


if sys.version < '3':
    VERSION = 2
else:
    VERSION = 3


GITHUB = "https://raw.githubusercontent.com/"
GITEE = ""  # TODO
GITLAB = ""  # TODO


class LoadCode(object):
    def __init__(self, url):
        url = os.path.join(GITHUB, url)
        code = requests.get(url).text
        if VERSION == 3:  # for print
            exec("from __future__ import print_function")
        exec(code)


if __name__ == "__main__":
    pass

相关文章

网友评论

      本文标题:Python直接根据URL直接调用远程代码

      本文链接:https://www.haomeiwen.com/subject/wvrssctx.html