[PATCH] color: add support for terminfo-based attributes and color

Martin Geisler mg at lazybytes.net
Fri Aug 28 14:51:50 CDT 2009


Danek Duvall <duvall at comfychair.org> writes:

> Martin Geisler wrote:
>
>> > +# Mapping from effect name to terminfo attribute name or color number
>> > +_terminfo_params = {'none': (True, 'sgr0'),
>> > +                    'black': (False, curses.COLOR_BLACK),
>> 
>> It looks to me like this will break if curses is not imported? You
>> should probably set 'curses = None' if the import fails, and then test
>> on curses before using it here and in the rest of the code.
>
> Good point.
>
> I also realized that the demandimport thing is messing with my ability
> to know whether curses imported properly. The try/except ImportError
> is useless, and "curses" is not in sys.modules, nor is its presence in
> globals() indicative of a successful load.

Right, demandimport doesn't touch the disk when you import a module. So
no checking is done for non-existing modules.

> So what's the right way to test for successful load? Trigger the load
> by accessing a member and catch ImportError there?

Yes, that's the way it's done.

-- 
Martin Geisler

VIFF (Virtual Ideal Functionality Framework) brings easy and efficient
SMPC (Secure Multiparty Computation) to Python. See: http://viff.dk/.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://selenic.com/pipermail/mercurial-devel/attachments/20090828/264afec9/attachment.pgp 


More information about the Mercurial-devel mailing list