Ñò
§ÚêLc @ sö d Z d Z d g Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k
Z
y d d k l Z Wn# e
j
o d d k l Z n Xd e i f d „ ƒ YZ e e i d „ Z e d j o e ƒ n d S( s’ Simple HTTP Server.
This module builds on BaseHTTPServer by implementing the standard GET
and HEAD requests in a fairly straightforward manner.
s 0.6t SimpleHTTPRequestHandleriÿÿÿÿN( t StringIOc B s§ e Z d Z d e Z d „ Z d „ Z d „ Z d „ Z d „ Z d „ Z
d „ Z e i
p e i ƒ n e i i ƒ Z e i h d d
6d d 6d d
6d d 6ƒ RS( sW 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.
s SimpleHTTP/c C s8 | i ƒ } | o! | i | | i ƒ | i ƒ n d S( s Serve a GET request.N( t send_headt copyfilet wfilet close( t selft f( ( s( /usr/lib64/python2.6/SimpleHTTPServer.pyt do_GET* s c C s% | i ƒ } | o | i ƒ n d S( s Serve a HEAD request.N( R R ( R R ( ( s( /usr/lib64/python2.6/SimpleHTTPServer.pyt do_HEAD1 s c
C s… | i | i ƒ } d } t i i | ƒ o› | i i d ƒ p3 | i d ƒ | i d | i d ƒ | i ƒ d SxR d D]9 } t i i | | ƒ } t i i
| ƒ o | } Pqx qx W| i | ƒ Sn | i | ƒ } y t
| d ƒ } Wn$ t j
o | i d d ƒ d SX| i d ƒ | i d
| ƒ t i | i ƒ ƒ } | i d t | d ƒ ƒ | i d
| i | i ƒ ƒ | i ƒ | S( s{ 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.
t /i- t Locations
index.htmls index.htmt rbi” s File not foundiÈ s Content-types Content-Lengthi s
Last-ModifiedN( s
index.htmls index.htm( t translate_patht patht Nonet ost isdirt endswitht
send_responset send_headert end_headerst joint existst list_directoryt
guess_typet opent IOErrort
send_errort fstatt filenot strt date_time_stringt st_mtime( R R R t indext ctypet fs( ( s( /usr/lib64/python2.6/SimpleHTTPServer.pyR 7 s8
c C sÌ y t i | ƒ } Wn' t i j
o | i d d ƒ d SX| i d d „ ƒ t ƒ } t i t i
| i ƒ ƒ } | i d ƒ | i d | ƒ | i d | ƒ | i d ƒ x¢ | D]š } t i i
| | ƒ } | } } t i i | ƒ o | d } | d } n t i i | ƒ o | d
} n | i d t i | ƒ t i | ƒ f ƒ q· W| i d ƒ | i ƒ } | i d
ƒ | i d ƒ t i ƒ }
| i d d |
ƒ | i d t | ƒ ƒ | i ƒ | S( sû 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” s No permission to list directoryt keyc S s
| i ƒ S( ( t lower( t a( ( s( /usr/lib64/python2.6/SimpleHTTPServer.pyt Directory listing for %s
s
R
t @s
i iÈ s Content-types text/html; charset=%ss Content-LengthN( R t listdirt errorR R t sortR t cgit escapet urllibt unquoteR t writeR R t islinkt quotet tellt seekR t syst getfilesystemencodingR R R ( R R t listR t displaypatht namet fullnamet displaynamet linknamet lengtht encoding( ( s( /usr/lib64/python2.6/SimpleHTTPServer.pyR c s@
$
c C sè | i d d ƒ d } | i d d ƒ d } t i t i | ƒ ƒ } | i d ƒ } t d | ƒ } t i ƒ } xs | D]k } t i i
| ƒ \ } } t i i | ƒ \ } } | t i t i f j o qu n t i i
| | ƒ } qu W| S( sñ 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.)
t ?i i t #R
N( t splitt posixpatht normpathR/ R0 t filterR R t getcwdR t
splitdrivet curdirt pardirR ( R R t wordst wordt drivet head( ( s( /usr/lib64/python2.6/SimpleHTTPServer.pyR
s c C s t i | | ƒ d S( sñ 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( t shutilt copyfileobj( R t sourcet
outputfile( ( s( /usr/lib64/python2.6/SimpleHTTPServer.pyR £ s c C sh t i | ƒ \ } } | | i j o | i | S| i ƒ } | | i j o | i | S| i d Sd S( s» 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.
t N( RC t splitextt extensions_mapR&