python类load_compiled()的实例源码

pluginmanager.py 文件源码 项目:python-otcclient 作者: OpenTelekomCloud 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def load_from_file(filepath):
    mod_name,file_ext = os.path.splitext(os.path.split(filepath)[-1])
    if mod_name.startswith("__init__"): 
        return 
    if file_ext.lower() == '.py':
        py_mod = imp.load_source(mod_name, filepath)
    elif file_ext.lower() == '.pyc':
        py_mod = imp.load_compiled(mod_name, filepath)        
    else:
        return None
    class_inst = getattr(py_mod, mod_name)()
    return class_inst
ihooks.py 文件源码 项目:sslstrip-hsts-openwrt 作者: adde88 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def load_compiled(self, name, filename, file=None):
        return imp.load_compiled(name, filename, file)
compat.py 文件源码 项目:Callandtext 作者: iaora 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def load_module_pyc(module_id, path):
        with open(path, 'rb') as fp:
            mod = imp.load_compiled(module_id, path, fp)
            # no source encoding here
            return mod
oracle_to_redshift_loader.py 文件源码 项目:Oracle-To-Redshift-Data-Loader 作者: alexbuz 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def import_module(filepath):
    class_inst = None
    #expected_class = 'MyClass'

    mod_name,file_ext = os.path.splitext(os.path.split(filepath)[-1])
    assert os.path.isfile(filepath), 'File %s does not exists.' % filepath
    if file_ext.lower() == '.py':
        py_mod = imp.load_source(mod_name, filepath)

    elif file_ext.lower() == '.pyc':
        py_mod = imp.load_compiled(mod_name, filepath)
    return py_mod
csv_loader_for_redshift.py 文件源码 项目:CSV_Loader_For_Redshift 作者: alexbuz 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def import_module(filepath):
    class_inst = None
    #expected_class = 'MyClass'

    mod_name,file_ext = os.path.splitext(os.path.split(filepath)[-1])
    assert os.path.isfile(filepath), 'File %s does not exists.' % filepath
    if file_ext.lower() == '.py':
        py_mod = imp.load_source(mod_name, filepath)

    elif file_ext.lower() == '.pyc':
        py_mod = imp.load_compiled(mod_name, filepath)
    return py_mod
compat.py 文件源码 项目:webapp 作者: superchilli 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def load_module_pyc(module_id, path):
        with open(path, 'rb') as fp:
            mod = imp.load_compiled(module_id, path, fp)
            # no source encoding here
            return mod
ihooks.py 文件源码 项目:pefile.pypy 作者: cloudtracer 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def load_compiled(self, name, filename, file=None):
        return imp.load_compiled(name, filename, file)
main.py 文件源码 项目:Battleground 作者: SpanishArmada 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def load_from_file(filepath, expectedClass):
    class_inst = None

    mod_name,file_ext = splitext(split(filepath)[-1])

    if file_ext.lower() == '.py':
        py_mod = imp.load_source(mod_name, filepath)

    elif file_ext.lower() == '.pyc':
        py_mod = imp.load_compiled(mod_name, filepath)

    if hasattr(py_mod, expectedClass):
        class_inst = getattr(py_mod, expectedClass)()

    return class_inst
ihooks.py 文件源码 项目:ndk-python 作者: gittor 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def load_compiled(self, name, filename, file=None):
        return imp.load_compiled(name, filename, file)
compat.py 文件源码 项目:QualquerMerdaAPI 作者: tiagovizoto 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def load_module_pyc(module_id, path):
        with open(path, 'rb') as fp:
            mod = imp.load_compiled(module_id, path, fp)
            # no source encoding here
            return mod
compat.py 文件源码 项目:gardenbot 作者: GoestaO 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def load_module_pyc(module_id, path):
        with open(path, 'rb') as fp:
            mod = imp.load_compiled(module_id, path, fp)
            # no source encoding here
            return mod
compat.py 文件源码 项目:flask-zhenai-mongo-echarts 作者: Fretice 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def load_module_pyc(module_id, path):
        with open(path, 'rb') as fp:
            mod = imp.load_compiled(module_id, path, fp)
            # no source encoding here
            return mod
ihooks.py 文件源码 项目:empyrion-python-api 作者: huhlig 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def load_compiled(self, name, filename, file=None):
        return imp.load_compiled(name, filename, file)
__init__.py 文件源码 项目:Tattle 作者: nickmaccarthy 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def load_module_from_file(filepath, d=None):
    class_inst = None
    expected_class = 'main'

    mod_name, file_ext = os.path.splitext(os.path.split(filepath)[-1])

    if file_ext.lower() == '.py':
         py_mod = imp.load_source(mod_name, filepath)
    elif file_ext.lower() == '.pyc':
         py_mod = imp.load_compiled(mod_name, filepath)

    if hasattr(py_mod, expected_class):
        class_inst = getattr(py_mod, expected_class)(d)

    return class_inst
postgresql_to_redshift_loader.py 文件源码 项目:PostgreSQL_To_Redshift_Loader 作者: alexbuz 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def import_module(filepath):
    class_inst = None
    #expected_class = 'MyClass'

    mod_name,file_ext = os.path.splitext(os.path.split(filepath)[-1])
    assert os.path.isfile(filepath), 'File %s does not exists.' % filepath
    if file_ext.lower() == '.py':
        py_mod = imp.load_source(mod_name, filepath)

    elif file_ext.lower() == '.pyc':
        py_mod = imp.load_compiled(mod_name, filepath)
    return py_mod
compat.py 文件源码 项目:ngx_status 作者: YoYoAdorkable 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def load_module_pyc(module_id, path):
        with open(path, 'rb') as fp:
            mod = imp.load_compiled(module_id, path, fp)
            # no source encoding here
            return mod
pluginmanager.py 文件源码 项目:VKBot 作者: Fogapod 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def _load_plugins_from(self, path):
        files = sorted(os.listdir(path))  # sorting to ensure that .py goes first
        included = []

        for f in files:
            if f.startswith('plugin_'):
                try:
                    if f.endswith('.py'):
                        if f + 'c' in files:
                            if os.path.getmtime(os.path.join(path, f + 'c')) > os.path.getmtime(os.path.join(path, f)):
                                # .pyc newer
                                continue

                        elif f + 'o' in files:
                            if os.path.getmtime(os.path.join(path, f + 'o')) > os.path.getmtime(os.path.join(path, f)):
                                # .pyo newer
                                continue

                        self._add_plugin(
                            imp.load_source('', os.path.join(path, f)), f, f[7:-3])

                        included.append(f)

                    elif f.endswith('.pyc') or f.endswith('.pyo'):
                        if f[:-1] in included:
                            continue

                        if f.endswith('c') and f[:-1] + 'o' in files:
                            if os.path.getmtime(os.path.join(path, f[:-1] + 'o')) > os.path.getmtime(os.path.join(path, f)):
                                # .pyo newer
                                continue
                        elif f[:-1] + 'c' in files:
                            if os.path.getmtime(os.path.join(path, f[:-1] + 'c')) > os.path.getmtime(os.path.join(path, f)):
                                # .pyc newer
                                continue

                        self._add_plugin(
                            imp.load_compiled('', os.path.join(path, f)), f, f[7:-4])

                        included.append(f[:-1])

                except Exception:
                    self.log(u'[b]?????? ??? ???????? ??????? %s[/b]' % f, 2)
                    self.log(traceback.format_exc().decode('utf8'), 2)


问题


面经


文章

微信
公众号

扫码关注公众号