def _hashsupplier(*args, **kw): if not args[0].startswith(hash): hashname = hash + args[0] if not hashname in holes: try: return imp(hashname, *(args[1:]), **kw) except ImportError: holes[hashname] = True return imp(*args, **kw)
def _load_modules_int(logger): modules = set() for _app in apps.get_app_configs(): # noinspection PyBroadException try: if not hasattr(_app.module, 'generators'): imp("{}.generator".format(_app.label)) generators = getattr(_app.module, 'generators') if hasattr(generators, 'accept_and_generate'): modules.add(generators) continue except Exception, e: logger.warn("Can't check module {} for generators.accept_and_generate".format(_app.label), exc_info=e) logger.info("Application %s contain no generator " % (_app.label,))
def interact(): init() global stdlang stdlang = imp("%s.std" % __name__).std print "(type logix.license for more information)" LogixConsole().interact("Welcome to Logix")
def init(): logixModuleName = __name__ global quotelang, syntaxlang, langlang, baselang quotelang, syntaxlang, langlang, baselang = \ rootops.makeLanguages(logixModuleName, home, lmodules) global stdlang stdlang = imp("%s/std" % logixModuleName).std
def symbol_by_name(name, aliases={}, imp=None, package=None, sep='.', default=None, **kwargs): """Get symbol by qualified name. The name should be the full dot-separated path to the class:: modulename.ClassName Example:: celery.concurrency.processes.TaskPool ^- class name or using ':' to separate module and symbol:: celery.concurrency.processes:TaskPool If `aliases` is provided, a dict containing short name/long name mappings, the name is looked up in the aliases first. Examples: >>> symbol_by_name("celery.concurrency.processes.TaskPool") <class 'celery.concurrency.processes.TaskPool'> >>> symbol_by_name("default", { ... "default": "celery.concurrency.processes.TaskPool"}) <class 'celery.concurrency.processes.TaskPool'> # Does not try to look up non-string names. >>> from celery.concurrency.processes import TaskPool >>> symbol_by_name(TaskPool) is TaskPool True """ if imp is None: imp = importlib.import_module if not isinstance(name, basestring): return name # already a class name = aliases.get(name) or name sep = ':' if ':' in name else sep module_name, _, cls_name = name.rpartition(sep) if not module_name: cls_name, module_name = None, package if package else cls_name try: try: module = imp(module_name, package=package, **kwargs) except ValueError, exc: exc = ValueError("Couldn't import %r: %s" % (name, exc)) six.reraise(ValueError, exc, sys.exc_info()[2]) return getattr(module, cls_name) if cls_name else module
def init(with_std=True): logixModuleName = __name__ global quotelang, syntaxlang, langlang, baselang quotelang, syntaxlang, langlang, baselang = \ rootops.makeLanguages(logixModuleName, home, lmodules) if with_std: global stdlang, doclang std = imp("%s.std" % logixModuleName) stdlang = std.std doclang = std.doclang.doclang
def import_from_cwd(module, imp=None, package=None): """Import module, but make sure it finds modules located in the current directory. Modules located in the current directory has precedence over modules located in `sys.path`. """ if imp is None: imp = importlib.import_module with cwd_in_path(): return imp(module, package=package)
def _smart_import(self, path, imp=None): imp = self.import_module if imp is None else imp if ":" in path: # Path includes attribute so can just jump here. # e.g. ``os.path:abspath``. return symbol_by_name(path, imp=imp) # Not sure if path is just a module name or if it includes an # attribute name (e.g. ``os.path``, vs, ``os.path.abspath`` try: return imp(path) except ImportError: # Not a module name, so try module + attribute. return symbol_by_name(path, imp=imp)
def group_picture(self, group_jid, path): if self.assertConnected(): with PILOptionalModule( failMessage=self.__class__.FAIL_OPT_PILLOW) as imp: Image = imp("Image") def onSuccess(resultIqEntity, originalIqEntity): self.output("Group picture updated successfully") def onError(errorIqEntity, originalIqEntity): logger.error("Error updating Group picture") #example by @aesedepece in https://github.com/tgalal/yowsup/pull/781 #modified to support python3 src = Image.open(path) pictureData = src.resize((640, 640)).tobytes("jpeg", "RGB") picturePreview = src.resize((96, 96)).tobytes("jpeg", "RGB") iq = SetPictureIqProtocolEntity(self.aliasToJid(group_jid), picturePreview, pictureData) self._sendIq(iq, onSuccess, onError)
def profile_setPicture(self, path): if self.assertConnected(): with PILOptionalModule( failMessage="No PIL library installed, try install pillow" ) as imp: Image = imp("Image") def onSuccess(resultIqEntity, originalIqEntity): self.output("Profile picture updated successfully") def onError(errorIqEntity, originalIqEntity): logger.error("Error updating profile picture") #example by @aesedepece in https://github.com/tgalal/yowsup/pull/781 #modified to support python3 src = Image.open(path) pictureData = src.resize((640, 640)).tobytes("jpeg", "RGB") picturePreview = src.resize((96, 96)).tobytes("jpeg", "RGB") iq = SetPictureIqProtocolEntity(self.getOwnJid(), picturePreview, pictureData) self._sendIq(iq, onSuccess, onError)
def test_future_absolute_import(self): def imp(): from pkg import absolute assert hasattr(absolute.struct, 'pack') imp()