()
Test this module.

    The test consists of retrieving and displaying the Python
    home page, along with the error code and error string returned
    by the www.python.org server.
Test this module.
Test this module .
def test():
    """Test this module.

    The test consists of retrieving and displaying the Python
    home page, along with the error code and error string returned
    by the www.python.org server.
    """

    import sys
    import getopt
    opts, args = getopt.getopt(sys.argv[1:], 'd')
    dl = 0
    for o, a in opts:
        if o == '-d': dl = dl + 1
    host = 'www.python.org'
    selector = '/'
    if args[0:]: host = args[0]
    if args[1:]: selector = args[1]
    h = HTTP()
    h.set_debuglevel(dl)
    h.connect(host)
    h.putrequest('GET', selector)
    h.endheaders()
    status, reason, headers = h.getreply()
    print 'status =', status
    print 'reason =', reason
    print
    if headers:
        for header in headers.headers: print string.strip(header)
    print
    print h.getfile().read()

    # minimal test that code to extract host from url works
    class HTTP11(HTTP):
        _http_vsn = 11
        _http_vsn_str = 'HTTP/1.1'

    h = HTTP11('www.python.org')
    h.putrequest('GET', 'http://www.python.org/~jeremy/')
    h.endheaders()
    h.getreply()
    h.close()

    if hasattr(socket, 'ssl'):
        host = 'sourceforge.net'
        selector = '/projects/python'
        hs = HTTPS()
        hs.connect(host)
        hs.putrequest('GET', selector)
        hs.endheaders()
        status, reason, headers = hs.getreply()
        print 'status =', status
        print 'reason =', reason
        print
        if headers:
            for header in headers.headers: print string.strip(header)
        print
        print hs.getfile().read()
def test ( ) : import sys import getopt opts , args = getopt . getopt ( sys . argv [ 1 : ] , 'd' ) dl = 0 for o , a in opts : if o == '-d' : dl = dl + 1 host = 'www.python.org' selector = '/' if args [ 0 : ] : host = args [ 0 ] if args [ 1 : ] : selector = args [ 1 ] h = HTTP ( ) h . set_debuglevel ( dl ) h . connect ( host ) h . putrequest ( 'GET' , selector ) h . endheaders ( ) status , reason , headers = h . getreply ( ) print 'status =' , status print 'reason =' , reason print if headers : for header in headers . headers : print string . strip ( header ) print print h . getfile ( ) . read ( ) # minimal test that code to extract host from url works class HTTP11 ( HTTP ) : _http_vsn = 11 _http_vsn_str = 'HTTP/1.1' h = HTTP11 ( 'www.python.org' ) h . putrequest ( 'GET' , 'http://www.python.org/~jeremy/' ) h . endheaders ( ) h . getreply ( ) h . close ( ) if hasattr ( socket , 'ssl' ) : host = 'sourceforge.net' selector = '/projects/python' hs = HTTPS ( ) hs . connect ( host ) hs . putrequest ( 'GET' , selector ) hs . endheaders ( ) status , reason , headers = hs . getreply ( ) print 'status =' , status print 'reason =' , reason print if headers : for header in headers . headers : print string . strip ( header ) print print hs . getfile ( ) . read ( )