Python直接根据URL直接调用远程代码
2019-08-19 本文已影响0人
飞翔的理念
#!/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