[Tutor] Mad Villain Seeks Source Review.

Tesla Coil tescoil@irtc.net
Tue, 21 Aug 2001 03:55:50 -0500


On 21 August 2001, Danny Yoo wrote:
> Hmmm... so would this diabolical plan only wrap
> its terrible tendrils around HTML?  If so, you
> might be able to avoid the parsing issue altogether
> by using the HTMLParser class from htmllib.  Here
> is the darkness that is the BlackHoleParser.py:

Beautiful!  I expect it will have its part as is.
Suitably deployed upon nuisance pages such as:
http://developer.netscape.com/docs/manuals/htmlguid/colortab.htm

> blackhole.feed(spacecraft)

Lines like that are a Drax or Blofeld on the
Bond Villain Personality Test, I'd imagine...

I was about to say that my initial design had failed
to appreciate enough what Tim Peters said only a few
days ago:  "When it comes to computer searches, doing
a stupid thing quickly but many times is often more
effective than doing an intelligent thing slowly [...]
due in part to that writing a *truly* intelligent thing
is much more difficult than is first imagined."

Which suggests grab *everything* that follows a '=', 
strip whitespace and quotations, lowercase it, and 
test to see if it's among named colors.  Unless there's
an even dumber application of brute force.

But I will be looking at sgmllib.

Oh, grayscale function I posted earlier is crocked.
Here's the quick fix:

def grayscale(rgbstring):
    r = rgbstring[0:2]
    g = rgbstring[2:4]
    b = rgbstring[4:6]
    hexcon = lambda x: float(eval('0x'+x))
    vl = map(hexcon, [r,g,b])
    grayrgb = int((0.3*vl[0])+(0.59*vl[1])+(0.11*vl[2]))
    if grayrgb <= 15: 
        grayrgb = str(hex(grayrgb))
	grayrgb = ('0'+ grayrgb[-1])*3
    else:
        grayrgb = str(hex(grayrgb))
        grayrgb = grayrgb[2:]*3
    return grayrgb