Sophie

Sophie

distrib > Fedora > 18 > i386 > by-pkgid > 6b0aa1636ce9b2e5dec1d363e30e2af3 > files > 10

python-MultipartPostHandler2-0.1.1-4.fc18.noarch.rpm

#!/usr/bin/python
"""
  The main function of this file is a sample which downloads a page and
  then uploads it to the W3C validator.
"""

def main():
    import tempfile, sys, os, urllib2, MultipartPostHandler

    validatorURL = "http://validator.w3.org/check"
    opener = urllib2.build_opener(MultipartPostHandler.MultipartPostHandler)

    def validateFile(url):
        temp = tempfile.mkstemp(suffix=".html")
        os.write(temp[0], opener.open(url).read())
        params = { "ss" : "0",            # show source
                   "doctype" : "Inline",
                   "uploaded_file" : open(temp[1], "rb") }
        print opener.open(validatorURL, params).read()
        os.remove(temp[1])

    if len(sys.argv[1:]) > 0:
        for arg in sys.argv[1:]:
            validateFile(arg)
    else:
        validateFile("http://www.google.com")

if __name__=="__main__":
    main()