This original _parse_color was someone in the wrong part of the diff; so I'm
resending that portion of the color changes (but not the dictionary change)

The changes do some extra guards against case changes, save some dictionary
lookups, and always send a default (instead of just sometimes) if it can't
get an answer.

> def _parse_color (value):
>     """Get the RGB value.  
>     
>     Try text colorname (e.g. 'silver'), 
>     then try to lower-case that (e.g., 'Silver')
>     then try an RGB value (e.g. #C0C0C0),
>     then try an RGB value missing the # (e.g. C0C0C0)
>     then default to black ("#000000").
>     """
>     
>     try:
>         return Colornames[value]
>     except KeyError:
>         pass    
>     
>     # This is redundant, if the page is coded entirely properly.
>     try:
>         return Colornames[value.lower()]
>     except KeyError:
>         pass    
>     
>     if value[0] == '#':
>         value = value[1:]
>     
>     try:
>         val = '%06x' % string.atoi(value, 16)
>         return val.upper()
>     except ValueError:
>         pass
>     
>     message (1, "Giving up on color %s, using black.", value)
>     return "000000"
 

480,499c700,701
<         # assess whether a hex color (eg #C0C0C0) or a text colorname (eg
'silver')
<         rgb = None
<         if value in Colornames.keys():
<             rgb = Colornames[value]
<         elif value[0] == '#':
<             try:
<                 val = string.atoi(value[1:], 16)
<                 rgb = '%06x' % val
<             except:
<                 pass
<         # May need to do error checking, at this last bit, if people using
non
<         #  standard color text names    
<         else:
<             try:
<                 # possible hex value without leading hash mark...
<                 val = string.atoi(value, 16)
<                 rgb = '%06x' % val
<             except:
<                 pass
<             
_______________________________________________
plucker-dev mailing list
[EMAIL PROTECTED]
http://lists.rubberchicken.org/mailman/listinfo/plucker-dev

Reply via email to