Python Popen WHOIS OS command fail test
Question: Prefacing this with the text 'just another beginner'. when you have the result
of a whois command via the Popen command, how do you test if its good ?

Normally when Python returns a list of whatever you can test the length of it
and that has usually sufficed for me, but this is a little more arbitrary.

eg im testing for a domains country of origin, but sometimes the domains that
gethostbyaddr gives me are not recognised by the WHOIS server. So, i thought i
would go with sending it an ip in case of failure but I've ended up with this
not so pretty less than 70 characters test. Just wondering if anyone knows
what the 'standard' way of doing this is.

    
    
    w = Popen(['whois', domain], stdout=PIPE, stdin=PIPE, stderr=STDOUT)
                    whois_result = w.communicate()[0]
                    print len(whois_result)
                    if len(whois_result) <= 70:
                            w = Popen(['whois', p_ip], stdout=PIPE, stdin=PIPE, stderr=STDOUT)
                            whois_result = w.communicate()[0]
                            print len(whois_result)
                            if len(whois_result) <= 70:
                                    print "complete and utter whois failure, its you isnt it, not me."
                            test = re.search("country.+([A-Z].)",whois_result)
                            countryid = test.group(1)
    


Answer: To answer your direct question, look for this string in the output of a
`whois` command to see whether there was a problem...

> No match for "insert_domain_here"

To address other meaningful issues to your task... your `Popen` command is
going at things the hard way... you don't need a `PIPE` for `stdin` and you
can call `.communicate()` directly on the `Popen` to make this a bit more
efficient... I rewrote with what I think you have in mind...

    
    
    from subprocess import Popen, PIPE, STDOUT
    import re
    
    ## Text result of the whois is stored in whois_result...
    whois_result = Popen(['whois', domain], stdout=PIPE,
        stderr=STDOUT).communicate()[0]
    if 'No match for' in whois_result:
        print "Processing whois failure on '%s'" % domain
        whois_result = Popen(['whois', p_ip], stdout=PIPE,
            stderr=STDOUT).communicate()[0]
        if 'No match for' in whois_result:
                print "complete and utter whois failure, its you isnt it, not me."
        test = re.search("country.+([A-Z].)",whois_result)
        countryid = test.group(1)
    

