The PEAK Developers' Center   Diff for "Importing" UserPreferences
 
HelpContents Search Diffs Info Edit Subscribe XML Print View
Ignore changes in the amount of whitespace

Differences between version dated 2007-08-11 07:06:02 and 2010-08-23 16:16:08 (spanning 4 versions)

Deletions are marked like this.
Additions are marked like this.

Dynamic, Lazy, and Weak Imports with the ``Importing`` Toolkit
==============================================================
 
NEW in 1.10: ``@whenImported`` can now be used as a decorator for lazy imports
 
Need to import an object when all you've got is its name? Need to lazily
import modules, such that they don't actually get loaded until you use them?
Want to have some code in a module that only gets run *if* another module is

    If `string_or_sequence` is not a string but is iterable, this returns a
    list created by calling ``importObject()`` on each element of the sequence.
 
    Note that you could view this as always using importObject; it just takes
    advantage of the knowledge that string.split() will always return a list
    of strings, rather than arbitrary objects.
 
importSuite(name_or_sequence [, globalDict])
    Convert a string or sequence to a ``unittest.TestSuite``
 

with normal imports of the targeted module(s), whether they are lazily loaded
before or after the normal imports.)
 
Question -- could lazyModule and whenImported be added the the standard library?
I would like to be rid of the function-internal imports, but I would also like to
be able to add aspects (such as logging) to the stdlib without adding run-time
slowdowns when they aren't used. -jJ
 
lazyModule(moduleName)
    Return module `moduleName`, but with its contents loaded "on demand"
 

 
    Example usage::
 
        sdist = lazyModule('distutils.commands.sdist')
        sdist = lazyModule('distutils.command.sdist')
 
    This is roughly equivalent to ``import distutils.commands.sdist as sdist``,
    This is roughly equivalent to ``import distutils.command.sdist as sdist``,
    except that the real import doesn't take place until/unless you try to
    access some attribute of the ``sdist`` object -- unless of course the
    module was already imported before the above line was executed.

the callback will be invoked only as soon as the third-party module is *used*
(i.e. any of its attributes are accessed), and not a moment before.
 
whenImported(moduleName, callback)
    Call ``callback(module)`` when module named `moduleName` is first used
@whenImported(moduleName)
    Call ``func(module)`` when module named `moduleName` is first used
 
    `moduleName` must be a fully qualified (i.e. absolute) module name.
 
    `callback` must accept one argument: the module object named by
    `moduleName`. `moduleName` must be a fully qualified (i.e. absolute)
    module name. The callback **must not allow any unhandled exceptions to
    escape**, or it may prevent other registered callbacks from running.
 
    If the named module has already been loaded, ``callback(module)`` is
    called immediately, and the module object is returned from this function.
 
    If the module has not been imported, or has only been imported lazily,
    then the callback is invoked when the module is first *used*, and a lazy
    import of the module is returned from this function.
 
    If the module was imported lazily and used before calling this function,
    the hook is called immediately, and the loaded module is returned from this
    function.
 
    Note that using this function implies a possible lazy import of the
    specified module, and lazy importing means that any 'ImportError' will be
    deferred until the module is used.
    If the named module has already been loaded, the decorated function
    is called immediately. If the named module is not yet loaded, the
    decorated function is registered as a callback that will be invoked
    when the named module is actually used.
 
    In either case, the decorated function will be passed one argument:
    the module object named by `moduleName`. It **must not allow any
    unhandled exceptions to escape**, or it may prevent other registered
    callbacks from running.
 
    Using this function implies a possible lazy import of the specified module,
    and lazy importing means that any ``ImportError`` will be deferred until
    the module is actually used.
 
    (Note: in older versions of the Importing toolkit, this function actually
    took a second argument: the callback to be registered or called. If you
    use it in this fashion, the return value is not the decorated function, but
    is instead the module object or lazy module object named by `moduleName`.)
 
 
Deprecated Features

 
Please direct questions regarding this package to the PEAK mailing list; see
http://www.eby-sarna.com/mailman/listinfo/PEAK/ for details.
 [http://bruits.freewebpages.org/7.html old testament fhe] | [http://lairds.741.com/34.html mothers panty boyspanking] | [http://molybdenum.fcpages.com/75.html latin young models] | [http://gleans.150m.com/35.html women torturing cock] | [http://chlorides.741.com/56.html sapphic girls kissing] | [http://ordainment.exactpages.com/81.html highheel shoe masturbation] | [http://choppiest.00freehost.com/83.html redhead clit] | [http://gleans.150m.com/6.html herpes dating sites] | [http://burst.dreamstation.com/48.html fat bbw galleries] | [http://molybdenum.fcpages.com/94.html 1996 gran prix] | [http://unsurely.kogaryu.com/22.html piss tgp] | [http://melanistic.envy.nu/2.html solo twinks] | [http://licente.9cy.com/75.html free hot date] | [http://clubbed.dreamstation.com/29.html bick cock amateur] | [http://weigh.1sweethost.com/94.html masterbate clitoris] | [http://guallatiri.1accesshost.com/92.html virginia female domination] | [http://adjure.1accesshost.com/95.html twinks orgy] | [http://pannier.ibnsites.com/14.html milf cruiser laura] | [http://troubles.freecities.com/49.html huge ass hoes] | [http://spookiest.g0g.net/37.html georgia facial rejuvenation] | [http://headbutt.angelcities.com/9.html girl like spanking] | [http://humanness.greatnow.com/71.html teen home videos] | [http://stalely.freewebpages.org/14.html asian anal fisting] | [http://denser.ibnsites.com/32.html cum shot big] | [http://undertook.freecities.com/5.html kim possible upskirt] | [http://tawdriest.freewebsitehosting.com/49.html asian clitoris] | [http://emanated.00freehost.com/67.html 3 foot dick] | [http://shlock.bravepages.com/49.html bbw mud hardcore] | [http://vigilantly.angelcities.com/43.html fuck in lingerie] | [http://adjure.1accesshost.com/67.html plump feeding women]

PythonPowered
ShowText of this page
EditText of this page
FindPage by browsing, title search , text search or an index
Or try one of these actions: AttachFile, DeletePage, LikePages, LocalSiteMap, SpellCheck