def imports(modules, forgive=False):
def wrap(f):<EOL><INDENT>if modules:<EOL><INDENT>setattr(f, '<STR_LIT>', modules)<EOL>for alternatives in modules:<EOL><INDENT>alternatives = alternatives.split('<STR_LIT:U+002C>')<EOL>mod_name = alternatives[<NUM_LIT:0>].split('<STR_LIT:.>')[-<NUM_LIT:1>]<EOL>for mod in alternatives:<EOL><INDENT>mod = mod.strip().split('<STR_LIT:.>')<EOL>try:<EOL><INDENT>if len(mod) == <NUM_LIT:1>:<EOL><INDENT>module = __import__(mod[<NUM_LIT:0>])<EOL><DEDENT>else:<EOL><INDENT>module = getattr(__import__('<STR_LIT:.>'.join(mod[:-<NUM_LIT:1>]),fromlist=[mod[-<NUM_LIT:1>]]), mod[-<NUM_LIT:1>])<EOL><DEDENT>f.__globals__[mod_name] = module<EOL>break <EOL><DEDENT>except ImportError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if forgive: <EOL><INDENT>warnings.warn('<STR_LIT>' % alternatives)<EOL><DEDENT>else:<EOL><INDENT>raise ImportError('<STR_LIT>' % alternatives)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return f<EOL><DEDENT>return wrap<EOL>
Should be used as a decorator to *attach* import statments to function
definitions. These imports are added to the global (i.e. module-level of 
the decorated function) namespace.

Two forms of import statements are supported (in the following examples
``foo``, ``bar``, ``oof, and ``rab`` are modules not classes or functions)::

    import foo, bar              # -> @imports(['foo', 'bar'])
    import foo.oof as oof            
    import bar.rab as rab        # -> @imports(['foo.oof', 'bar.rab'])

It provides support for alternatives::

    try:
        import foo
    except ImportError:
        import bar

which is expressed as::

    @imports(['foo,bar'])

or alternatively::

    try:
        import foo.oof as oof
    except ImportError:
        import bar.rab as oof

becomes::

    @imports(['foo.oof,bar.rab'])


This import is available in the body of the function as ``oof`` All needed
imports should be attached for every function (even if two function are in
the same module and have the same ``globals``)

Arguments:

    - modules (``list``) A list of modules in the following forms 
      ``['foo', 'bar', ..., 'baz']`` or  
      ``['foo.oof', 'bar.rab', ..., 'baz.zab']``
    - forgive (``bool``) [default: ``False``] If ``True`` will not raise 
      `ImportError``