;
"Ic               @   s  d  Z  d Z d d g Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l	 Z	 d d l
 Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d Z d Z d   Z Gd	   d e j  Z Gd
   d e j  Z Gd   d e  Z e a d   Z d   Z Gd   d e  Z e e d d  Z  e! d k o+ e  d e  e  d e  e  d e  n d S(   u@  HTTP server classes.

Note: BaseHTTPRequestHandler doesn't implement any HTTP request; see
SimpleHTTPRequestHandler for simple implementations of GET, HEAD and POST,
and CGIHTTPRequestHandler for CGI scripts.

It does, however, optionally implement HTTP/1.1 persistent connections,
as of version 0.3.

Notes on CGIHTTPRequestHandler
------------------------------

This class implements GET and POST requests to cgi-bin scripts.

If the os.fork() function is not present (e.g. on Windows),
subprocess.Popen() is used as a fallback, with slightly altered semantics.

In all cases, the implementation is intentionally naive -- all
requests are executed synchronously.

SECURITY WARNING: DON'T USE THIS CODE UNLESS YOU ARE INSIDE A FIREWALL
-- it may execute arbitrary Python code or external programs.

Note that status code 200 is sent prior to execution of a CGI script, so
scripts cannot send other status codes such as 302 (redirect).

XXX To do:

- log requests even later (to capture byte count)
- log user-agent header and other interesting goodies
- send error log to separate file
u   0.6u
   HTTPServeru   BaseHTTPRequestHandleri    Nu   <head>
<title>Error response</title>
</head>
<body>
<h1>Error response</h1>
<p>Error code %(code)d.
<p>Message: %(message)s.
<p>Error code explanation: %(code)s = %(explain)s.
</body>
u   text/html;charset=utf-8c             C   s(   |  j  d d  j  d d  j  d d  S(   Nu   &u   &amp;u   <u   &lt;u   >u   &gt;(   u   replace(   u   html(    (    u(   /mit/python/lib/python3.0/http/server.pyu   _quote_htmlu   s    c             B   s   |  Ee  Z d  Z d   Z d S(   i   c             C   sN   t  j j |   |  j j   d d  \ } } t j |  |  _ | |  _ d S(   u.   Override server_bind to store the server name.Ni   (   u   socketserveru	   TCPServeru   server_bindu   socketu   getsocknameu   getfqdnu   server_nameu   server_port(   u   selfu   hostu   port(    (    u(   /mit/python/lib/python3.0/http/server.pyu   server_bind|   s    N(   u   __name__u
   __module__u   allow_reuse_addressu   server_bind(   u
   __locals__(    (    u(   /mit/python/lib/python3.0/http/server.pyu
   HTTPServerx   s   
c             B   sX  |  Ee  Z d  Z d e j j   d Z d e Z e	 Z
 e Z d Z d   Z d   Z d   Z d( d  Z d( d	  Z d
   Z d   Z d d d  Z d   Z d   Z d   Z d( d  Z d   Z d d d d d d d g Z d( d d d d d d d  d! d" d# d$ d% g Z d&   Z d' Z d d( l  Z! e! j" j# Z$ i( d d+ 6d d. 6d d1 6d d4 6d d7 6d d: 6d d= 6d d@ 6d dC 6d dF 6d dI 6d dL 6d dO 6d dR 6d dU 6d dW 6d dZ 6d d] 6d d` 6d dc 6d df 6d di 6d dl 6d do 6d dr 6d du 6d dx 6d d{ 6d d~ 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6Z% d( S(   u  HTTP request handler base class.

    The following explanation of HTTP serves to guide you through the
    code as well as to expose any misunderstandings I may have about
    HTTP (so you don't need to read the code to figure out I'm wrong
    :-).

    HTTP (HyperText Transfer Protocol) is an extensible protocol on
    top of a reliable stream transport (e.g. TCP/IP).  The protocol
    recognizes three parts to a request:

    1. One line identifying the request type and path
    2. An optional set of RFC-822-style headers
    3. An optional data part

    The headers and data are separated by a blank line.

    The first line of the request has the form

    <command> <path> <version>

    where <command> is a (case-sensitive) keyword such as GET or POST,
    <path> is a string containing path information for the request,
    and <version> should be the string "HTTP/1.0" or "HTTP/1.1".
    <path> is encoded using the URL encoding scheme (using %xx to signify
    the ASCII character with hex code xx).

    The specification specifies that lines are separated by CRLF but
    for compatibility with the widest range of clients recommends
    servers also handle LF.  Similarly, whitespace in the request line
    is treated sensibly (allowing multiple spaces between components
    and allowing trailing whitespace).

    Similarly, for output, lines ought to be separated by CRLF pairs
    but most clients grok LF characters just fine.

    If the first line of the request has the form

    <command> <path>

    (i.e. <version> is left out) then this is assumed to be an HTTP
    0.9 request; this form has no optional headers and data part and
    the reply consists of just the data.

    The reply form of the HTTP 1.x protocol again has three parts:

    1. One line giving the response code
    2. An optional set of RFC-822-style headers
    3. The data

    Again, the headers and data are separated by a blank line.

    The response code line has the form

    <version> <responsecode> <responsestring>

    where <version> is the protocol version ("HTTP/1.0" or "HTTP/1.1"),
    <responsecode> is a 3-digit response code indicating success or
    failure of the request, and <responsestring> is an optional
    human-readable string explaining what the response code means.

    This server parses the request and the headers, and then calls a
    function specific to the request type (<command>).  Specifically,
    a request SPAM will be handled by a method do_SPAM().  If no
    such method exists the server sends an error response to the
    client.  If it exists, it is called with no arguments:

    do_SPAM()

    Note that the request name is case sensitive (i.e. SPAM and spam
    are different requests).

    The various request details are stored in instance variables:

    - client_address is the client IP address in the form (host,
    port);

    - command, path and version are the broken-down request line;

    - headers is an instance of email.message.Message (or a derived
    class) containing the header information;

    - rfile is a file object open for reading positioned at the
    start of the optional input data part;

    - wfile is a file object open for writing.

    IT IS IMPORTANT TO ADHERE TO THE PROTOCOL FOR WRITING!

    The first thing to be written must be the response line.  Then
    follow 0 or more header lines, then a blank line, and then the
    actual data (if any).  The meaning of the header lines depends on
    the command executed by the server; in most cases, when data is
    returned, there should be at least one header line of the form

    Content-type: <type>/<subtype>

    where <type> and <subtype> should be registered MIME types,
    e.g. "text/html" or "text/plain".

    u   Python/i    u	   BaseHTTP/u   HTTP/0.9c          
   C   s[  d |  _ |  j |  _ } d |  _ t |  j d  } | d d  d k o | d d  } n, | d d  d k o | d d  } n | |  _ | j   } t	 |  d k o.| \ } } } | d d	  d
 k o |  j
 d d |  d Syf | j d d  d } | j d  } t	 |  d k o
 t  n t | d  t | d  f } Wn2 t t f k
 o  |  j
 d d |  d SYn X| d  k o |  j d k o d |  _ n | d! k o |  j
 d d |  d Snw t	 |  d k o? | \ } } d |  _ | d k o |  j
 d d |  d Sn% | p d S|  j
 d d |  d S| | | |  _ |  _ |  _ g  } x1 |  j j   }	 | j |	  |	 d" k o Pq|q|t j d j |  j d   }
 t j j d |  j  j |
  |  _ |  j j d d  } | j   d k o d |  _ n1 | j   d k o |  j d k o d |  _ n d# S($   u'  Parse a request (internal).

        The request should be stored in self.raw_requestline; the results
        are in self.command, self.path, self.request_version and
        self.headers.

        Return True for success, False for failure; on failure, an
        error is sent back.

        i   u
   iso-8859-1iNu   
iu   
i   i   u   HTTP/i  u   Bad request version (%r)u   /u   .i   i    u   HTTP/1.1i  u   Invalid HTTP Version (%s)u   GETu   Bad HTTP/0.9 request type (%r)u   Bad request syntax (%r)s   
s   
s    u   _classu
   Connectionu    u   closeu
   keep-aliveF(   i   i   (   i   i    (   s   
s   
s    T(!   u   Noneu   commandu   default_request_versionu   request_versionu   close_connectionu   stru   raw_requestlineu   requestlineu   splitu   lenu
   send_erroru   Falseu
   ValueErroru   intu
   IndexErroru   protocol_versionu   pathu   rfileu   readlineu   appendu   iou   StringIOu   joinu   decodeu   emailu   parseru   Parseru   MessageClassu   parseu   headersu   getu   loweru   True(   u   selfu   versionu   requestlineu   wordsu   commandu   pathu   base_version_numberu   version_numberu   headersu   lineu   hfileu   conntype(    (    u(   /mit/python/lib/python3.0/http/server.pyu   parse_request   sr    			
$
						!$c             C   s   |  j  j   |  _ |  j p d |  _ d S|  j   p d Sd |  j } t |  |  p |  j d d |  j  d St |  |  } |   d S(   u   Handle a single HTTP request.

        You normally don't need to override this method; see the class
        __doc__ string for information on how to handle specific HTTP
        commands such as GET and POST.

        i   Nu   do_i  u   Unsupported method (%r)(	   u   rfileu   readlineu   raw_requestlineu   close_connectionu   parse_requestu   commandu   hasattru
   send_erroru   getattr(   u   selfu   mnameu   method(    (    u(   /mit/python/lib/python3.0/http/server.pyu   handle_one_requestR  s    
	c             C   s3   d |  _  |  j   x |  j  p |  j   q Wd S(   u&   Handle multiple requests if necessary.i   N(   u   close_connectionu   handle_one_request(   u   self(    (    u(   /mit/python/lib/python3.0/http/server.pyu   handleg  s
    	
 
c          
   C   s  y |  j  | \ } } Wn  t k
 o d \ } } Yn X| d k o
 | } n | } |  j d | |  |  j i | d 6t |  d 6| d 6} |  j | |  |  j d |  j  |  j d d  |  j	   |  j
 d	 k o: | d
 k o- | d k o  |  j j | j d d   n d S(   u  Send and log an error reply.

        Arguments are the error code, and a detailed message.
        The detailed message defaults to the short entry matching the
        response code.

        This sends an error response (so it must be called before any
        output has been generated), logs the error, and finally sends
        a piece of HTML explaining the error to the user.

        u   ???u   code %d, message %su   codeu   messageu   explainu   Content-Typeu
   Connectionu   closeu   HEADi   i   i0  u   UTF-8u   replaceN(   u   ???u   ???(   i   i0  (   u	   responsesu   KeyErroru   Noneu	   log_erroru   error_message_formatu   _quote_htmlu   send_responseu   send_headeru   error_content_typeu   end_headersu   commandu   wfileu   writeu   encode(   u   selfu   codeu   messageu   shortmsgu   longmsgu   explainu   content(    (    u(   /mit/python/lib/python3.0/http/server.pyu
   send_erroro  s     
"
*c             C   s   |  j  |  | d	 k o/ | |  j k o |  j | d } qI d } n |  j d k o0 |  j j d |  j | | f j d d   n |  j d |  j	    |  j d |  j
    d	 S(
   u   Send the response header and log the response code.

        Also send two standard headers with the server software
        version and the current date.

        i    u    u   HTTP/0.9u
   %s %d %s
u   ASCIIu   strictu   Serveru   DateN(   u   log_requestu   Noneu	   responsesu   request_versionu   wfileu   writeu   protocol_versionu   encodeu   send_headeru   version_stringu   date_time_string(   u   selfu   codeu   message(    (    u(   /mit/python/lib/python3.0/http/server.pyu   send_response  s    
$c             C   s   |  j  d k o* |  j j d | | f j d d   n | j   d k oD | j   d k o d |  _ q | j   d k o d	 |  _ q n d
 S(   u   Send a MIME header.u   HTTP/0.9u   %s: %s
u   ASCIIu   strictu
   connectionu   closei   u
   keep-alivei    N(   u   request_versionu   wfileu   writeu   encodeu   loweru   close_connection(   u   selfu   keywordu   value(    (    u(   /mit/python/lib/python3.0/http/server.pyu   send_header  s    *c             C   s(   |  j  d k o |  j j d  n d S(   u,   Send the blank line ending the MIME headers.u   HTTP/0.9s   
N(   u   request_versionu   wfileu   write(   u   self(    (    u(   /mit/python/lib/python3.0/http/server.pyu   end_headers  s    u   -c             C   s)   |  j  d |  j t |  t |   d S(   uN   Log an accepted request.

        This is called by send_response().

        u
   "%s" %s %sN(   u   log_messageu   requestlineu   str(   u   selfu   codeu   size(    (    u(   /mit/python/lib/python3.0/http/server.pyu   log_request  s    	c             G   s   |  j  | |  d S(   u   Log an error.

        This is called when a request cannot be fulfilled.  By
        default it passes the message on to log_message().

        Arguments are the same as for log_message().

        XXX This should go to the separate error log.

        N(   u   log_message(   u   selfu   formatu   args(    (    u(   /mit/python/lib/python3.0/http/server.pyu	   log_error  s    c             G   s1   t  j j d |  j   |  j   | | f  d S(   u  Log an arbitrary message.

        This is used by all other logging functions.  Override
        it if you have specific logging wishes.

        The first argument, FORMAT, is a format string for the
        message to be logged.  If the format string contains
        any % escapes requiring parameters, they should be
        specified as subsequent arguments (it's just like
        printf!).

        The client host and current date/time are prefixed to
        every message.

        u   %s - - [%s] %s
N(   u   sysu   stderru   writeu   address_stringu   log_date_time_string(   u   selfu   formatu   args(    (    u(   /mit/python/lib/python3.0/http/server.pyu   log_message  s    		c             C   s   |  j  d |  j S(   u*   Return the server software version string.u    (   u   server_versionu   sys_version(   u   self(    (    u(   /mit/python/lib/python3.0/http/server.pyu   version_string  s    c          	   C   sx   | d k o t j   } n t j |  \	 } } } } } } } }	 }
 d |  j | | |  j | | | | | f } | S(   u@   Return the current date and time formatted for a message header.u#   %s, %02d %3s %4d %02d:%02d:%02d GMTN(   u   Noneu   timeu   gmtimeu   weekdaynameu	   monthname(   u   selfu	   timestampu   yearu   monthu   dayu   hhu   mmu   ssu   wdu   yu   zu   s(    (    u(   /mit/python/lib/python3.0/http/server.pyu   date_time_string  s    *
c          	   C   s]   t  j    } t  j |  \	 } } } } } } } }	 }
 d | |  j | | | | | f } | S(   u.   Return the current time formatted for logging.u   %02d/%3s/%04d %02d:%02d:%02d(   u   timeu	   localtimeu	   monthname(   u   selfu   nowu   yearu   monthu   dayu   hhu   mmu   ssu   xu   yu   zu   s(    (    u(   /mit/python/lib/python3.0/http/server.pyu   log_date_time_string  s
    * u   Monu   Tueu   Wedu   Thuu   Friu   Satu   Sunu   Janu   Febu   Maru   Apru   Mayu   Junu   Julu   Augu   Sepu   Octu   Novu   Decc             C   s&   |  j  d d  \ } } t j |  S(   u   Return the client address formatted for logging.

        This version looks up the full hostname using gethostbyaddr(),
        and tries to find a name that contains at least one dot.

        Ni   (   u   client_addressu   socketu   getfqdn(   u   selfu   hostu   port(    (    u(   /mit/python/lib/python3.0/http/server.pyu   address_string  s    u   HTTP/1.0Nu   Continueu!   Request received, please continueid   u   Switching Protocolsu.   Switching to new protocol; obey Upgrade headerie   u   OKu#   Request fulfilled, document followsi   u   Createdu   Document created, URL followsi   u   Acceptedu/   Request accepted, processing continues off-linei   u   Non-Authoritative Informationu   Request fulfilled from cachei   u
   No Contentu"   Request fulfilled, nothing followsi   u   Reset Contentu#   Clear input form for further input.i   u   Partial Contentu   Partial content follows.i   u   Multiple Choicesu,   Object has several resources -- see URI listi,  u   Moved Permanentlyu(   Object moved permanently -- see URI listi-  u   Foundu(   Object moved temporarily -- see URI listi.  u	   See Otheru'   Object moved -- see Method and URL listi/  u   Not Modifiedu)   Document has not changed since given timei0  u	   Use ProxyuA   You must use proxy specified in Location to access this resource.i1  u   Temporary Redirecti3  u   Bad Requestu(   Bad request syntax or unsupported methodi  u   Unauthorizedu*   No permission -- see authorization schemesi  u   Payment Requiredu"   No payment -- see charging schemesi  u	   Forbiddenu0   Request forbidden -- authorization will not helpi  u	   Not Foundu   Nothing matches the given URIi  u   Method Not Allowedu,   Specified method is invalid for this server.i  u   Not Acceptableu&   URI not available in preferred format.i  u   Proxy Authentication Requiredu8   You must authenticate with this proxy before proceeding.i  u   Request Timeoutu#   Request timed out; try again later.i  u   Conflictu   Request conflict.i  u   Goneu6   URI no longer exists and has been permanently removed.i  u   Length Requiredu#   Client must specify Content-Length.i  u   Precondition Failedu!   Precondition in headers is false.i  u   Request Entity Too Largeu   Entity is too large.i  u   Request-URI Too Longu   URI is too long.i  u   Unsupported Media Typeu"   Entity body in unsupported format.i  u   Requested Range Not Satisfiableu   Cannot satisfy request range.i  u   Expectation Failedu(   Expect condition could not be satisfied.i  u   Internal Server Erroru   Server got itself in troublei  u   Not Implementedu&   Server does not support this operationi  u   Bad Gatewayu,   Invalid responses from another server/proxy.i  u   Service Unavailableu8   The server cannot process the request due to a high loadi  u   Gateway Timeoutu4   The gateway server did not receive a timely responsei  u   HTTP Version Not Supportedu   Cannot fulfill request.i  (   u   Continueu!   Request received, please continue(   u   Switching Protocolsu.   Switching to new protocol; obey Upgrade header(   u   OKu#   Request fulfilled, document follows(   u   Createdu   Document created, URL follows(   u   Acceptedu/   Request accepted, processing continues off-line(   u   Non-Authoritative Informationu   Request fulfilled from cache(   u
   No Contentu"   Request fulfilled, nothing follows(   u   Reset Contentu#   Clear input form for further input.(   u   Partial Contentu   Partial content follows.(   u   Multiple Choicesu,   Object has several resources -- see URI list(   u   Moved Permanentlyu(   Object moved permanently -- see URI list(   u   Foundu(   Object moved temporarily -- see URI list(   u	   See Otheru'   Object moved -- see Method and URL list(   u   Not Modifiedu)   Document has not changed since given time(   u	   Use ProxyuA   You must use proxy specified in Location to access this resource.(   u   Temporary Redirectu(   Object moved temporarily -- see URI list(   u   Bad Requestu(   Bad request syntax or unsupported method(   u   Unauthorizedu*   No permission -- see authorization schemes(   u   Payment Requiredu"   No payment -- see charging schemes(   u	   Forbiddenu0   Request forbidden -- authorization will not help(   u	   Not Foundu   Nothing matches the given URI(   u   Method Not Allowedu,   Specified method is invalid for this server.(   u   Not Acceptableu&   URI not available in preferred format.(   u   Proxy Authentication Requiredu8   You must authenticate with this proxy before proceeding.(   u   Request Timeoutu#   Request timed out; try again later.(   u   Conflictu   Request conflict.(   u   Goneu6   URI no longer exists and has been permanently removed.(   u   Length Requiredu#   Client must specify Content-Length.(   u   Precondition Failedu!   Precondition in headers is false.(   u   Request Entity Too Largeu   Entity is too large.(   u   Request-URI Too Longu   URI is too long.(   u   Unsupported Media Typeu"   Entity body in unsupported format.(   u   Requested Range Not Satisfiableu   Cannot satisfy request range.(   u   Expectation Failedu(   Expect condition could not be satisfied.(   u   Internal Server Erroru   Server got itself in trouble(   u   Not Implementedu&   Server does not support this operation(   u   Bad Gatewayu,   Invalid responses from another server/proxy.(   u   Service Unavailableu8   The server cannot process the request due to a high load(   u   Gateway Timeoutu4   The gateway server did not receive a timely response(   u   HTTP Version Not Supportedu   Cannot fulfill request.(&   u   __name__u
   __module__u   __doc__u   sysu   versionu   splitu   sys_versionu   __version__u   server_versionu   DEFAULT_ERROR_MESSAGEu   error_message_formatu   DEFAULT_ERROR_CONTENT_TYPEu   error_content_typeu   default_request_versionu   parse_requestu   handle_one_requestu   handleu   Noneu
   send_erroru   send_responseu   send_headeru   end_headersu   log_requestu	   log_erroru   log_messageu   version_stringu   date_time_stringu   log_date_time_stringu   weekdaynameu	   monthnameu   address_stringu   protocol_versionu   http.clientu   httpu   clientu   HTTPMessageu   MessageClassu	   responses(   u
   __locals__(    (    u(   /mit/python/lib/python3.0/http/server.pyu   BaseHTTPRequestHandler   s   
f
	U				
					                 c             B   s   |  Ee  Z d  Z d e Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z e j p e j   n e j j   Z e j i d	 d
 6d d 6d d 6d d 6 d S(   uW  Simple HTTP request handler with GET and HEAD commands.

    This serves files from the current directory and any of its
    subdirectories.  The MIME type for files is determined by
    calling the .guess_type() method.

    The GET and HEAD requests are identical except that the HEAD
    request omits the actual contents of the file.

    u   SimpleHTTP/c             C   s8   |  j    } | o! |  j | |  j  | j   n d S(   u   Serve a GET request.N(   u	   send_headu   copyfileu   wfileu   close(   u   selfu   f(    (    u(   /mit/python/lib/python3.0/http/server.pyu   do_GETg  s    c             C   s%   |  j    } | o | j   n d S(   u   Serve a HEAD request.N(   u	   send_headu   close(   u   selfu   f(    (    u(   /mit/python/lib/python3.0/http/server.pyu   do_HEADn  s    c             C   s  |  j  |  j  } d } t j j |  o |  j j d  p3 |  j d  |  j d |  j d  |  j   d SxR d D]9 } t j j	 | |  } t j j
 |  o | } Pqx qx W|  j |  Sn |  j |  } y t | d  } Wn( t k
 o |  j d d  d SYn X|  j d	  |  j d
 |  t j | j    } |  j d t | d   |  j d |  j | j   |  j   | S(   u{  Common code for GET and HEAD commands.

        This sends the response code and MIME headers.

        Return value is either a file object (which has to be copied
        to the outputfile by the caller unless the command was HEAD,
        and must be closed by the caller under all circumstances), or
        None, in which case the caller has nothing further to do.

        u   /i-  u   Locationu
   index.htmlu	   index.htmu   rbi  u   File not foundi   u   Content-typeu   Content-Lengthi   u   Last-ModifiedN(   u
   index.htmlu	   index.htm(   u   translate_pathu   pathu   Noneu   osu   isdiru   endswithu   send_responseu   send_headeru   end_headersu   joinu   existsu   list_directoryu
   guess_typeu   openu   IOErroru
   send_erroru   fstatu   filenou   stru   date_time_stringu   st_mtime(   u   selfu   pathu   fu   indexu   ctypeu   fs(    (    u(   /mit/python/lib/python3.0/http/server.pyu	   send_headt  s8    
 	

c             C   s  y t  j |  } Wn+ t  j k
 o |  j d d  d SYn X| j d d    g  } t j t j	 j
 |  j   } | j d  | j d |  | j d |  | j d  x | D] } t  j j | |  } | } } t  j j |  o | d	 } | d	 } n t  j j |  o | d
 } n | j d t j	 j |  t j |  f  q W| j d  t j   }	 d j |  j |	  }
 t j   } | j |
  | j d  |  j d  |  j d d |	  |  j d t t |
    |  j   | S(   u   Helper to produce a directory listing (absent index.html).

        Return value is either a file object, or None (indicating an
        error).  In either case, the headers are sent, making the
        interface the same as for send_head().

        i  u   No permission to list directoryu   keyc             S   s
   |  j    S(    (   u   lower(   u   a(    (    u(   /mit/python/lib/python3.0/http/server.pyu   <lambda>  s    u7   <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">u/   <html>
<title>Directory listing for %s</title>
u)   <body>
<h2>Directory listing for %s</h2>
u
   <hr>
<ul>
u   /u   @u   <li><a href="%s">%s</a>
u   </ul>
<hr>
</body>
</html>
u    i    i   u   Content-typeu   text/html; charset=%su   Content-LengthN(   u   osu   listdiru   erroru
   send_erroru   Noneu   sortu   cgiu   escapeu   urllibu   parseu   unquoteu   pathu   appendu   joinu   isdiru   islinku   quoteu   sysu   getfilesystemencodingu   encodeu   iou   BytesIOu   writeu   seeku   send_responseu   send_headeru   stru   lenu   end_headers(   u   selfu   pathu   listu   ru   displaypathu   nameu   fullnameu   displaynameu   linknameu   encu   encodedu   f(    (    u(   /mit/python/lib/python3.0/http/server.pyu   list_directory  sD    
 

	'
c             C   s   | j  d d  d } | j  d d  d } t j t j j |   } | j  d  } t d |  } t j	   } xs | D]k } t j
 j |  \ } } t j
 j  |  \ } } | t j t j f k o qx n t j
 j | |  } qx W| S(   u   Translate a /-separated PATH to the local filename syntax.

        Components that mean special things to the local file system
        (e.g. drive or directory names) are ignored.  (XXX They should
        probably be diagnosed.)

        u   ?i   i    u   #u   /N(   u   splitu	   posixpathu   normpathu   urllibu   parseu   unquoteu   filteru   Noneu   osu   getcwdu   pathu
   splitdriveu   curdiru   pardiru   join(   u   selfu   pathu   wordsu   wordu   driveu   head(    (    u(   /mit/python/lib/python3.0/http/server.pyu   translate_path  s    	  c             C   s   t  j | |  d S(   u  Copy all data between two file objects.

        The SOURCE argument is a file object open for reading
        (or anything with a read() method) and the DESTINATION
        argument is a file object open for writing (or
        anything with a write() method).

        The only reason for overriding this would be to change
        the block size or perhaps to replace newlines by CRLF
        -- note however that this the default server uses this
        to copy binary data as well.

        N(   u   shutilu   copyfileobj(   u   selfu   sourceu
   outputfile(    (    u(   /mit/python/lib/python3.0/http/server.pyu   copyfile  s    c             C   sh   t  j |  \ } } | |  j k o |  j | S| j   } | |  j k o |  j | S|  j d Sd S(   u  Guess the type of a file.

        Argument is a PATH (a filename).

        Return value is a string of the form type/subtype,
        usable for a MIME Content-type header.

        The default implementation looks the file's extension
        up in the table self.extensions_map, using application/octet-stream
        as a default; however it would be permissible (if
        slow) to look inside the data to make a better guess.

        u    N(   u	   posixpathu   splitextu   extensions_mapu   lower(   u   selfu   pathu   baseu   ext(    (    u(   /mit/python/lib/python3.0/http/server.pyu
   guess_type  s    u   application/octet-streamu    u
   text/plainu   .pyu   .cu   .hN(   u   __name__u
   __module__u   __doc__u   __version__u   server_versionu   do_GETu   do_HEADu	   send_headu   list_directoryu   translate_pathu   copyfileu
   guess_typeu	   mimetypesu   initedu   initu	   types_mapu   copyu   extensions_mapu   update(   u
   __locals__(    (    u(   /mit/python/lib/python3.0/http/server.pyu   SimpleHTTPRequestHandlerX  s"   

			)	,			
	u   SimpleHTTPRequestHandlerc              C   s   t  o t  Sy d d l }  Wn t k
 o d SYn Xy |  j d  d a  Wn6 t k
 o* d t t d   |  j     a  Yn Xt  S(   u$   Internal routine to get nobody's uidi    Niu   nobodyi   i   c             S   s   |  d  S(   i   (    (   u   x(    (    u(   /mit/python/lib/python3.0/http/server.pyu   <lambda>"  s    (   u   nobodyu   pwdu   ImportErroru   getpwnamu   KeyErroru   maxu   mapu   getpwall(   u   pwd(    (    u(   /mit/python/lib/python3.0/http/server.pyu
   nobody_uid  s    
(c             C   sB   y t  j |   } Wn t  j k
 o d SYn X| j d @d k S(   u   Test for executable file.iI   i    F(   u   osu   statu   erroru   Falseu   st_mode(   u   pathu   st(    (    u(   /mit/python/lib/python3.0/http/server.pyu
   executable&  s
    
c             B   sk   |  Ee  Z d  Z e e d  Z d Z d   Z d   Z d   Z	 d d g Z
 d   Z d	   Z d
   Z d S(   u   Complete HTTP server with GET, HEAD and POST commands.

    GET and HEAD also support running CGI scripts.

    The POST command is *only* implemented for CGI scripts.

    u   forki    c             C   s/   |  j    o |  j   n |  j d d  d S(   uR   Serve a POST request.

        This is only implemented for CGI scripts.

        i  u   Can only POST to CGI scriptsN(   u   is_cgiu   run_cgiu
   send_error(   u   self(    (    u(   /mit/python/lib/python3.0/http/server.pyu   do_POST@  s    c             C   s)   |  j    o |  j   St j |   Sd S(   u-   Version of send_head that support CGI scriptsN(   u   is_cgiu   run_cgiu   SimpleHTTPRequestHandleru	   send_head(   u   self(    (    u(   /mit/python/lib/python3.0/http/server.pyu	   send_headL  s    c             C   s   |  j  } x |  j D]x } t |  } | d |  | k oO | | d  p | | d k o, | d |  | | d d  f |  _ d Sq Wd S(   u  Test whether self.path corresponds to a CGI script.

        Return a tuple (dir, rest) if self.path requires running a
        CGI script, None if not.  Note that rest begins with a
        slash if it is not empty.

        The default implementation tests whether the path
        begins with one of the strings in the list
        self.cgi_directories (and the next character is a '/'
        or the end of the string).

        Nu   /i   TF(   u   pathu   cgi_directoriesu   lenu   cgi_infou   Trueu   False(   u   selfu   pathu   xu   i(    (    u(   /mit/python/lib/python3.0/http/server.pyu   is_cgiS  s    	
 :'	u   /cgi-binu   /htbinc             C   s
   t  |  S(   u1   Test whether argument path is an executable file.(   u
   executable(   u   selfu   path(    (    u(   /mit/python/lib/python3.0/http/server.pyu   is_executablel  s    c             C   s(   t  j j |  \ } } | j   d k S(   u.   Test whether argument path is a Python script.u   .pyu   .pyw(   u   .pyu   .pyw(   u   osu   pathu   splitextu   lower(   u   selfu   pathu   headu   tail(    (    u(   /mit/python/lib/python3.0/http/server.pyu	   is_pythonp  s    c       (      C   s[	  |  j  } |  j \ } } | j d t |  d  } x | d k ox | d |  } | | d d  } |  j |  } t j  j |  o- | | } } | j d t |  d  } q7 Pq7 W| j d  } | d k o) | d |  | | d d  } } n d } | j d  } | d k o% | d |  | | d  }	 } n | d }	 } | d |	 }
 |  j |
  } t j  j |  p |  j	 d d |
  d St j  j
 |  p |  j	 d	 d
 |
  d S|  j |
  } | p- |  j |  p |  j	 d	 d |
  d Sn i  } |  j   | d <|  j j | d <d | d <|  j | d <t |  j j  | d <|  j | d <t j j |  } | | d <|  j |  | d <|
 | d <| o | | d <n |  j   } | |  j d k o | | d <n |  j d | d <|  j j d  } | o | j   } t |  d k o d d l } d d l } | d | d <| d j   d k o y/ | d j d  } | j  |  j! d  } Wn | j" t# f k
 o YqX| j d  } t |  d k o | d | d <qqqn |  j j d   d k o |  j j%   | d! <n |  j d  | d! <|  j j d"  } | o | | d# <n |  j j d$  } | o | | d% <n g  } xe |  j j& d&  D]Q } | d d  d' k o | j' | j(    q| | d( d  j d)  } qWd) j) |  | d* <|  j j d+  } | o | | d, <n t* d |  j j+ d- g    } | o d. j) |  | d/ <n x dD D] } | j, | d  qyWt j- j. |  |  j/ d0 d1  | j0 d2 d3  } |  j1 o}|	 g } d4 | k o | j' |  n t2   } |  j3 j4   t j5   } | d k o{ t j6 | d  \ } } x@ t7 j7 |  j8 g g  g  d  d o |  j8 j9 d  p Pq@q@W| o |  j: d5 |  n d Syw y t j; |  Wn t j< k
 o Yn Xt j= |  j8 j>   d  t j= |  j3 j>   d  t j? | | t j-  WqW	|  j j@ |  jA |  j  t jB d6  YqW	Xnd d lC } | }  |  j |  oU tD jE }! |! j   jF d7  o" |! d d8  |! d9 d  }! n d: |! |  f }  n d4 | k o! d; | k o d< |  | f }  n |  jG d= |   y tH |  }" Wn  tI tJ f k
 o d }" Yn X| jK |  d> | jL d? | jL d@ | jL }# |  j j   dA k o# |" d k o |  j8 j9 |"  }$ n d }$ xF t7 j7 |  j8 jM g g  g  d  d o |  j8 jM jN d  p PqqW|# jO |$  \ }% }& |  j3 jP |%  |& o |  j: dB |&  n |# jQ }' |' o |  j: d5 |'  n |  jG dC  d S(E   u   Execute a CGI script.u   /i   i    Nu   ?u    i  u   No such CGI script (%r)i  u#   CGI script is not a plain file (%r)u!   CGI script is not executable (%r)u   SERVER_SOFTWAREu   SERVER_NAMEu   CGI/1.1u   GATEWAY_INTERFACEu   SERVER_PROTOCOLu   SERVER_PORTu   REQUEST_METHODu	   PATH_INFOu   PATH_TRANSLATEDu   SCRIPT_NAMEu   QUERY_STRINGu   REMOTE_HOSTu   REMOTE_ADDRu   authorizationi   u	   AUTH_TYPEu   basicu   asciiu   :u   REMOTE_USERu   content-typeu   CONTENT_TYPEu   content-lengthu   CONTENT_LENGTHu   refereru   HTTP_REFERERu   acceptu   	
 i   u   ,u   HTTP_ACCEPTu
   user-agentu   HTTP_USER_AGENTu   cookieu   , u   HTTP_COOKIEi   u   Script output followsu   +u    u   =u   CGI script exit status %#xi   u   w.exeiiu   %s -u %su   "u   %s "%s"u   command: %su   stdinu   stdoutu   stderru   postu   %su   CGI script exited OK(   u   QUERY_STRINGu   REMOTE_HOSTu   CONTENT_LENGTHu   HTTP_USER_AGENTu   HTTP_COOKIEu   HTTP_REFERER(R   u   pathu   cgi_infou   findu   lenu   translate_pathu   osu   isdiru   rfindu   existsu
   send_erroru   isfileu	   is_pythonu   is_executableu   version_stringu   serveru   server_nameu   protocol_versionu   stru   server_portu   commandu   urllibu   parseu   unquoteu   address_stringu   client_addressu   headersu   getu   splitu   base64u   binasciiu   loweru   encodeu   decodestringu   decodeu   Erroru   UnicodeErroru   Noneu   get_content_typeu   getallmatchingheadersu   appendu   stripu   joinu   filteru   get_allu
   setdefaultu   environu   updateu   send_responseu   replaceu	   have_forku
   nobody_uidu   wfileu   flushu   forku   waitpidu   selectu   rfileu   readu	   log_erroru   setuidu   erroru   dup2u   filenou   execveu   handle_erroru   requestu   _exitu
   subprocessu   sysu
   executableu   endswithu   log_messageu   intu	   TypeErroru
   ValueErroru   Popenu   PIPEu   _socku   recvu   communicateu   writeu
   returncode((   u   selfu   pathu   diru   restu   iu   nextdiru   nextrestu	   scriptdiru   queryu   scriptu
   scriptnameu
   scriptfileu   ispyu   envu   uqrestu   hostu   authorizationu   base64u   binasciiu   lengthu   refereru   acceptu   lineu   uau   cou   ku   decoded_queryu   argsu   nobodyu   pidu   stsu
   subprocessu   cmdlineu   interpu   nbytesu   pu   datau   stdoutu   stderru   status(    (    u(   /mit/python/lib/python3.0/http/server.pyu   run_cgiu  s:   	  )%	


 ! 
		 #
	"		# &
	N(   u   __name__u
   __module__u   __doc__u   hasattru   osu	   have_forku   rbufsizeu   do_POSTu	   send_headu   is_cgiu   cgi_directoriesu   is_executableu	   is_pythonu   run_cgi(   u
   __locals__(    (    u(   /mit/python/lib/python3.0/http/server.pyu   CGIHTTPRequestHandler/  s   
					u   CGIHTTPRequestHandleru   HTTP/1.0c             C   s   t  j d d  o t t  j d  } n d } d | f } | |  _ | | |   } | j j   } t d | d d | d d  | j   d S(	   u   Test the HTTP request handler class.

    This runs an HTTP server on port 8000 (or the first command line
    argument).

    i   Ni@  u    u   Serving HTTP oni    u   portu   ...(   u   sysu   argvu   intu   protocol_versionu   socketu   getsocknameu   printu   serve_forever(   u   HandlerClassu   ServerClassu   protocolu   portu   server_addressu   httpdu   sa(    (    u(   /mit/python/lib/python3.0/http/server.pyu   test5  s    		u   __main__u   HandlerClass("   u   __doc__u   __version__u   __all__u   iou   osu   sysu   cgiu   timeu   socketu   shutilu   urllib.parseu   urllibu   selectu	   mimetypesu	   posixpathu   socketserveru   email.messageu   emailu   email.parseru   DEFAULT_ERROR_MESSAGEu   DEFAULT_ERROR_CONTENT_TYPEu   _quote_htmlu	   TCPServeru
   HTTPServeru   StreamRequestHandleru   BaseHTTPRequestHandleru   SimpleHTTPRequestHandleru   Noneu   nobodyu
   nobody_uidu
   executableu   CGIHTTPRequestHandleru   testu   __name__(    (    (    u(   /mit/python/lib/python3.0/http/server.pyu   <module>    sD   3	 			 