Spade
Mini Shell
| Directory:~$ /lib/python2.7/site-packages/future/backports/http/ |
| [Home] [System Details] [Kill Me] |
�
,�]c@`shdZddlmZmZmZmZddlmZddlTdZ ddgZ
ddlmZdd l
mZdd
lmZddlmZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZd
ZdZ
d�Z!dej"fd��YZ#dej$fd��YZ%de%fd��YZ&d�Z'e(a)d�Z*d�Z+de&fd��YZ,e%e#ddd�Z-e.dkrdej/�Z0e0j1dd
d!d"d#�e0j1d$d
d%d&dd'e2d(d)d"d*�e0j3�Z4e4j5rKe-d+e,d,e4j6�ne-d+e&d,e4j6�ndS(-uQHTTP
server classes.
From Python 3.3
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
i(tabsolute_importtdivisiontprint_functiontunicode_literals(tutils(t*u0.6u
HTTPServeruBaseHTTPRequestHandler(thtml(tclient(tparse(tsocketserverNu�<!DOCTYPE
HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html;charset=utf-8">
<title>Error response</title>
</head>
<body>
<h1>Error response</h1>
<p>Error code: %(code)d</p>
<p>Message: %(message)s.</p>
<p>Error code explanation: %(code)s - %(explain)s.</p>
</body>
</html>
utext/html;charset=utf-8cC`s(|jdd�jdd�jdd�S(Nu&u&u<u<u>u>(treplace(R((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pyt_quote_html�st
HTTPServercB`seZdZd�ZRS(icC`sHtjj|�|jj�d
\}}tj|�|_||_dS(u.Override server_bind to store the server
name.iN(R t TCPServertserver_bindtsockettgetsocknametgetfqdntserver_nametserver_port(tselfthosttport((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pyR�s(t__name__t
__module__tallow_reuse_addressR(((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pyR�stBaseHTTPRequestHandlerc
B`s}eZdZdejj�dZdeZe Z
eZdZ
d�Zd�Zd�Zd�Zd�d �Zd�d
�Zd�d�Zd�Zd
�Zd�Zddd�Zd�Zd�Zd�Zd�d�Zd�ZdddddddgZd�dddd
d!d"d#d$d%d&d'd(g
Z
d)�Z!d*Z"e#j$Z%i,d�d-6d�d06d�d36d�d66d�d96d�d<6d�d?6d�dB6d�dE6d�dH6d�dK6d�dN6d�dQ6d�dT6d�dW6d�dY6d�d\6d�d_6d�db6d�de6d�dh6d�dk6d�dn6d�dq6d�dt6d�dw6d�dz6d�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�6d�d�6d�d�6d�d�6d�d�6Z&RS(�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".
uPython/iu BaseHTTP/uHTTP/0.9c
C`sd|_|j|_}d|_t|jd�}|jd�}||_|j �}t
|�dkr�|\}}}|d
dkr�|jdd|�tSyd|j d d�d}|j d
�}t
|�dkr�t
�nt|d�t|d�f}Wn,t
tfk
r3|jdd|�tSX|dkr[|jd
kr[d|_n|dkr�|jdd|�tSnpt
|�dkr�|\}}d|_|dkr�|jdd|�tSn"|s�tS|jdd|�tS||||_|_|_y"tj|jd|j�|_Wn%tjk
rX|jdd�tSX|jjdd�}|j�dkr�d|_n-|j�dkr�|jd
kr�d|_n|jjdd�} | j�dkr|jd
kr|jd
kr|j�stSntS(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.
iu
iso-8859-1u
iiuHTTP/i�uBad request version (%r)u/u.iiuHTTP/1.1i�uInvalid
HTTP Version (%s)uGETuBad HTTP/0.9 request type (%r)uBad request syntax
(%r)t_classu
Line too longu
Connectionuucloseu
keep-aliveuExpectu100-continueN(ii(ii(tNonetcommandtdefault_request_versiontrequest_versiontclose_connectiontstrtraw_requestlinetrstriptrequestlinetsplittlent
send_errortFalset
ValueErrortintt
IndexErrortprotocol_versiontpaththttp_clientt
parse_headerstrfiletMessageClasstheaderstLineTooLongtgettlowerthandle_expect_100tTrue(
RtversionR$twordsRR-tbase_version_numbertversion_numbertconntypetexpect((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pyt
parse_requestst $ cC`s|jd�|j�tS(u7Decide
what to do with an "Expect: 100-continue" header.
If the client is expecting a 100 Continue response, we must
respond with either a 100 Continue or a final response before
waiting for the request body. The default is to always respond
with a 100 Continue. You can behave differently (for example,
reject unauthorized requests) by overriding this method.
This method should either return True (possibly after sending
a 100 Continue response) or send an error response and return
False.
id(tsend_response_onlyt
flush_headersR7(R((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pyR6]s
cC`sy�|jjd�|_t|j�dkrYd|_d|_d|_|jd�dS|jsod|_dS|j �sdSd|j}t
||�s�|jdd |j�dSt||�}|�|jj
�Wn0tjk
r}|jd
|�d|_dSXdS(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.
iiui�Niudo_i�uUnsupported method (%r)uRequest timed
out: %r(R0treadlineR"R&R$RRR'R
R>thasattrtgetattrtwfiletflushRttimeoutt log_error(Rtmnametmethodte((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pythandle_one_requestos0
cC`s1d|_|j�x|js,|j�qWdS(u&Handle
multiple requests if necessary.iN(R
RK(R((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pythandle�s
cC`sy|j|\}}Wntk
r6d\}}nX|dkrL|}n|}|jd||�|ji|d6t|�d6|d6}|j||�|jd|j�|jdd�|j �|j
d kr|d
kr|dkr|jj|j
d
d��ndS(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???ucode %d, message %sucodeumessageuexplainuContent-Typeu
ConnectionucloseuHEADi�i�i0uUTF-8ureplaceN(u???u???(i�i0(t responsestKeyErrorRRGterror_message_formatRt
send_responsetsend_headerterror_content_typetend_headersRRDtwritetencode(Rtcodetmessagetshortmsgtlongmsgtexplaintcontent((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pyR'�s
"
'cC`sM|j|�|j||�|jd|j��|jd|j��dS(u�Add
the response header to the headers buffer and log the
response code.
Also send two standard headers with the server software
version and the current date.
uServeruDateN(tlog_requestR?RQtversion_stringtdate_time_string(RRVRW((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pyRP�s
cC`s�|dkr8||jkr/|j|d}q8d}n|jdkr�t|d�sbg|_n|jjd|j||fjdd��ndS( uSend
the response header only.iuuHTTP/0.9u_headers_bufferu
%s %d %s
ulatin-1ustrictN(RRMRRBt_headers_buffertappendR,RU(RRVRW((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pyR?�s cC`s�|jdkrSt|d�s*g|_n|jjd||fjdd��n|j�dkr�|j�dkr�d|_q�|j�d kr�d
|_q�ndS(u)Send a MIME header to the headers
buffer.uHTTP/0.9u_headers_bufferu%s: %s
ulatin-1ustrictu
connectionucloseiu
keep-aliveiN(RRBR_R`RUR5R
(Rtkeywordtvalue((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pyRQ�s
cC`s0|jdkr,|jjd�|j�ndS(u,Send the blank line
ending the MIME headers.uHTTP/0.9s
N(RR_R`R@(R((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pyRS�scC`s;t|d�r7|jjdj|j��g|_ndS(Nu_headers_buffert(RBRDRTtjoinR_(R((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pyR@�su-cC`s)|jd|jt|�t|��dS(uNLog
an accepted request.
This is called by send_response().
u
"%s" %s
%sN(tlog_messageR$R!(RRVtsize((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pyR\�s cG`s|j||�dS(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(Re(Rtformattargs((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pyRG�scG`s1tjjd|j�|j�||f�dS(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 ip and current date/time are prefixed to
every message.
u%s - - [%s] %s
N(tsyststderrRTtaddress_stringtlog_date_time_string(RRgRh((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pyRes cC`s|jd|jS(u*Return
the server software version string.u
(tserver_versiontsys_version(R((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pyR]sc C`sv|dkrtj�}ntj|�\ }}}}}}}} }
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(Rttimetgmtimetweekdaynamet monthname(Rt timestamptyeartmonthtdaythhtmmtsstwdtytzts((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pyR^s*
c C`s]tj�}tj|�\ }}}}}}}} }
d||j|||||f}|S(u.Return the current time formatted for
logging.u%02d/%3s/%04d
%02d:%02d:%02d(Rot localtimeRr(RtnowRtRuRvRwRxRytxR{R|R}((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pyRl*s
*
uMonuTueuWeduThuuFriuSatuSunuJanuFebuMaruApruMayuJunuJuluAuguSepuOctuNovuDeccC`s|jdS(uReturn
the client
address.i(tclient_address(R((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pyRk8suHTTP/1.0uContinueu!Request
received, please continueiduSwitching Protocolsu.Switching to new
protocol; obey Upgrade headerieuOKu#Request fulfilled, document
followsi�uCreateduDocument created, URL followsi�uAcceptedu/Request
accepted, processing continues off-linei�uNon-Authoritative
InformationuRequest fulfilled from cachei�u
No Contentu"Request fulfilled, nothing followsi�u
Reset
Contentu#Clear input form for further input.i�uPartial ContentuPartial
content follows.i�uMultiple Choicesu,Object has several resources -- see
URI listi,uMoved Permanentlyu(Object moved permanently -- see URI
listi-uFoundu(Object moved temporarily -- see URI listi.u See
Otheru'Object moved -- see Method and URL listi/uNot
Modifiedu)Document has not changed since given timei0u Use ProxyuAYou must
use proxy specified in Location to access this resource.i1uTemporary
Redirecti3uBad Requestu(Bad request syntax or unsupported
methodi�uUnauthorizedu*No permission -- see authorization
schemesi�uPayment Requiredu"No payment -- see charging
schemesi�u Forbiddenu0Request forbidden -- authorization will not
helpi�u Not FounduNothing matches the given URIi�uMethod Not
Allowedu.Specified method is invalid for this resource.i�uNot
Acceptableu&URI not available in preferred format.i�uProxy
Authentication Requiredu8You must authenticate with this proxy before
proceeding.i�uRequest Timeoutu#Request timed out; try again
later.i�uConflictuRequest conflict.i�uGoneu6URI no longer exists
and has been permanently removed.i�uLength Requiredu#Client must
specify Content-Length.i�uPrecondition Failedu!Precondition in headers
is false.i�uRequest Entity Too LargeuEntity is too
large.i�uRequest-URI Too LonguURI is too long.i�uUnsupported Media
Typeu"Entity body in unsupported format.i�uRequested Range Not
SatisfiableuCannot satisfy request range.i�uExpectation Failedu(Expect
condition could not be satisfied.i�uPrecondition Requiredu9The origin
server requires the request to be conditional.i�uToo Many RequestsuPThe
user has sent too many requests in a given amount of time ("rate
limiting").i�uRequest Header Fields Too LargeuWThe server is
unwilling to process the request because its header fields are too
large.i�uInternal Server ErroruServer got itself in troublei�uNot
Implementedu&Server does not support this operationi�uBad
Gatewayu,Invalid responses from another server/proxy.i�uService
Unavailableu8The server cannot process the request due to a high
loadi�uGateway Timeoutu4The gateway server did not receive a timely
responsei�uHTTP Version Not SupporteduCannot fulfill
request.i�uNetwork Authentication Requiredu8The client needs to
authenticate to gain network access.i�N(uContinueu!Request received,
please continue(uSwitching Protocolsu.Switching to new protocol; obey
Upgrade header(uOKu#Request fulfilled, document
follows(uCreateduDocument created, URL follows(uAcceptedu/Request
accepted, processing continues off-line(uNon-Authoritative
InformationuRequest fulfilled from cache(u
No Contentu"Request fulfilled, nothing follows(u
Reset Contentu#Clear
input form for further input.(uPartial ContentuPartial content
follows.(uMultiple Choicesu,Object has several resources -- see URI
list(uMoved Permanentlyu(Object moved permanently -- see URI
list(uFoundu(Object moved temporarily -- see URI list(u See
Otheru'Object moved -- see Method and URL list(uNot
Modifiedu)Document has not changed since given time(u Use ProxyuAYou must
use proxy specified in Location to access this resource.(uTemporary
Redirectu(Object moved temporarily -- see URI list(uBad Requestu(Bad
request syntax or unsupported method(uUnauthorizedu*No permission -- see
authorization schemes(uPayment Requiredu"No payment -- see charging
schemes(u Forbiddenu0Request forbidden -- authorization will not
help(u Not FounduNothing matches the given URI(uMethod Not
Allowedu.Specified method is invalid for this resource.(uNot
Acceptableu&URI not available in preferred format.(uProxy
Authentication Requiredu8You must authenticate with this proxy before
proceeding.(uRequest Timeoutu#Request timed out; try again
later.(uConflictuRequest conflict.(uGoneu6URI no longer exists and has
been permanently removed.(uLength Requiredu#Client must specify
Content-Length.(uPrecondition Failedu!Precondition in headers is
false.(uRequest Entity Too LargeuEntity is too large.(uRequest-URI Too
LonguURI is too long.(uUnsupported Media Typeu"Entity body in
unsupported format.(uRequested Range Not SatisfiableuCannot satisfy
request range.(uExpectation Failedu(Expect condition could not be
satisfied.(uPrecondition Requiredu9The origin server requires the request
to be conditional.(uToo Many RequestsuPThe user has sent too many
requests in a given amount of time ("rate limiting").(uRequest
Header Fields Too LargeuWThe server is unwilling to process the request
because its header fields are too large.(uInternal Server ErroruServer
got itself in trouble(uNot Implementedu&Server does not support this
operation(uBad Gatewayu,Invalid responses from another
server/proxy.(uService Unavailableu8The server cannot process the request
due to a high load(uGateway Timeoutu4The gateway server did not receive a
timely response(uHTTP Version Not SupporteduCannot fulfill
request.(uNetwork Authentication Requiredu8The client needs to
authenticate to gain network
access.('RRt__doc__RiR8R%Rnt__version__RmtDEFAULT_ERROR_MESSAGEROtDEFAULT_ERROR_CONTENT_TYPERRRR>R6RKRLRR'RPR?RQRSR@R\RGReR]R^RlRqRrRkR,R.tHTTPMessageR1RM(((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pyR�s�f
Q #
tSimpleHTTPRequestHandlercB`s�eZdZdeZd�Zd�Zd�Zd�Zd�Z d�Z
d�Zej
skej�nejj�Zejid d
6dd6dd
6dd6�RS(uWSimple 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.
uSimpleHTTP/cC`s6|j�}|r2|j||j�|j�ndS(uServe a
GET
request.N(t send_headtcopyfileRDtclose(Rtf((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pytdo_GET�scC`s#|j�}|r|j�ndS(uServe
a HEAD
request.N(R�R�(RR�((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pytdo_HEAD�scC`s}|j|j�}d}tjj|�r�|jjd�sn|jd�|jd|jd�|j�dSxOdD]7}tjj ||�}tjj
|�ru|}PququW|j|�Sn|j|�}yt
|d�}Wn"tk
r|jdd�dSX|jd �|jd
|�tj|j��}|jdt|d��|jd
|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-uLocationu
index.htmlu index.htmurbi�uFile not
foundi�uContent-typeuContent-Lengthiu
Last-ModifiedN(u
index.htmlu index.htm(ttranslate_pathR-RtostisdirtendswithRPRQRSRdtexiststlist_directoryt
guess_typetopentIOErrorR'tfstattfilenoR!R^tst_mtime(RR-R�tindextctypetfs((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pyR��s6
c
C`sytj|�}Wn%tjk
r:|jdd�dSX|jdd��g}tjtj |j
��}tj�}d|}|j
d�|j
d�|j
d|�|j
d |�|j
d
|�|j
d�x�|D]�}tj
j||�}|} }
tj
j|�r4|d} |d}
ntj
j|�rS|d
} n|j
dtj|
�tj| �f�q�W|j
d�dj|�j|�}tj�}|j|�|jd�|jd�|jdd|�|jdtt|���|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�uNo permission to list directorytkeycS`s
|j�S(N(R5(ta((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pyt<lambda>�suDirectory
listing for %suZ<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML
4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">u
<html>
<head>u@<meta http-equiv="Content-Type"
content="text/html;
charset=%s">u<title>%s</title>
</head>u<body>
<h1>%s</h1>u <hr>
<ul>u/u@u<li><a
href="%s">%s</a></li>u</ul>
<hr>
</body>
</html>
u
ii�uContent-typeutext/html;
charset=%suContent-LengthN(R�tlistdirterrorR'RtsortRtescapeturllib_parsetunquoteR-RitgetfilesystemencodingR`RdR�tislinktquoteRUtiotBytesIORTtseekRPRQR!R&RS(
RR-tlisttrtdisplaypathtencttitletnametfullnametdisplaynametlinknametencodedR�((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pyR��sJ
$
cC`s�|jdd�d}|jdd�d}tjtj|��}|jd�}td|�}tj�}xq|D]i}tj j
|�\}}tj j|�\}}|tjtjfkr�quntj j
||�}quW|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?iiu#u/N(R%t posixpathtnormpathR�R�tfilterRR�tgetcwdR-t
splitdrivetcurdirtpardirRd(RR-R9twordtdrivethead((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pyR�
s
cC`stj||�dS(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(tshutiltcopyfileobj(Rtsourcet
outputfile((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pyR�#scC`sdtj|�\}}||jkr/|j|S|j�}||jkrU|j|S|jdSdS(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.
uN(R�tsplitexttextensions_mapR5(RR-tbasetext((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pyR�3suapplication/octet-streamuu
text/plainu.pyu.cu.h(RRR�R�RmR�R�R�R�R�R�R�t mimetypestinitedtinitt types_maptcopyR�tupdate(((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pyR��s"
) 4
cC`s�|jd�}g}xM|d
D]A}|dkr?|j�q |r |dkr |j|�q q
W|r�|j�}|r�|dkr�|j�d}q�|dkr�d}q�q�nd}ddj|�|f}dj|�}|S(u`
Given a URL path, remove extra '/'s and '.' path
elements and collapse
any '..' references and returns a colllapsed path.
Implements something akin to RFC-2396 5.2 step 6 to parse relative
paths.
The utility of this function is limited to is_cgi method and helps
preventing some security attacks.
Returns: A tuple of (head, tail) where tail is everything after the
final /
and head is everything before it. Head will always start with a
'/' and,
if it contains anything else, never have a trailing '/'.
Raises: IndexError if too many '..' occur within the path.
u/i����u..u.u(R%tpopR`Rd(R-t
path_partst
head_partstpartt tail_partt splitpathtcollapsed_path((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pyt_url_collapse_pathXs&
cC`s~tr
tSyddl}Wntk
r.dSXy|jd�daWn1tk
rydtd�|j�D��anXtS(u$Internal routine to get
nobody's
uidiNi����unobodyiics`s|]}|dVqdS(iN((t.0R�((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pys <genexpr>�s(tnobodytpwdtImportErrortgetpwnamRNtmaxtgetpwall(R�((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pyt
nobody_uid�s
$cC`stj|tj�S(uTest for
executable
file.(R�taccesstX_OK(R-((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pyt
executable�stCGIHTTPRequestHandlercB`seeZdZeed�ZdZd�Zd�Zd�Z ddgZ
d�Zd �Zd
�Z
RS(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.
uforkicC`s-|j�r|j�n|jdd�dS(uRServe a POST
request.
This is only implemented for CGI scripts.
i�uCan only POST to CGI
scriptsN(tis_cgitrun_cgiR'(R((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pytdo_POST�s
cC`s'|j�r|j�Stj|�SdS(u-Version
of send_head that support CGI
scriptsN(R�R�R�R�(R((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pyR��s
cC`s`t|j�}|jdd�}||
||d}}||jkr\||f|_tStS(u3Test whether self.path
corresponds to a CGI script.
Returns True and updates the cgi_info attribute to the tuple
(dir, rest) if self.path requires running a CGI script.
Returns False otherwise.
If any exception is raised, the caller should assume that
self.path was rejected as invalid and act accordingly.
The default implementation tests whether the normalized url
path begins with one of the strings in self.cgi_directories
(and the next character is a '/' or the end of the
string).
u/i(R�R-tfindtcgi_directoriestcgi_infoR7R((RR�tdir_sepR�ttail((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pyR��su/cgi-binu/htbincC`s
t|�S(u1Test whether argument path is an executable
file.(R�(RR-((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pyt
is_executable�scC`s(tjj|�\}}|j�dkS(u.Test
whether argument path is a Python
script.u.pyu.pyw(u.pyu.pyw(R�R-R�R5(RR-R�R�((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pyt is_python�sc(C`s�|j}|j\}}|jdt|�d�}xv|dkr�||
}||d}|j|�}tjj|�r�||}}|jdt|�d�}q7Pq7W|jd�}|dkr�||
||d}}nd}|jd�}|dkr|| ||} }n
|d} }|d| }
|j|
�}tjj|�sq|j dd|
�dStjj
|�s�|j d d
|
�dS|j|
�}|js�|r�|j
|�s�|j d d|
�dSntjtj�}
|j�|
d<|jj|
d
<d|
d<|j|
d<t|jj�|
d<|j|
d<tj|�}||
d<|j|�|
d<|
|
d<|r�||
d<n|jd|
d<|jjd�}|r�|j�}t|�dkr�ddl}ddl}|d|
d<|dj
�dkr�yS|dj!d�}t"j#rV|j$|�j%d�}n|j&|�j%d�}Wn|j't(fk
r�q�X|jd�}t|�dkr�|d|
d<q�q�q�n|jjd�dkr�|jj*�|
d
<n|jd|
d
<|jjd!�}|r+||
d"<n|jjd#�}|rP||
d$<ng}xW|jj+d%�D]C}|d
d&kr�|j,|j-��qi||d'jd(�}qiWd(j.|�|
d)<|jjd*�}|r�||
d+<nt/d|jj0d,g��}d-j.|�}|r(||
d.<nxdCD]}|
j1|d�q/W|j2d0d1�|j3�|j4d2d3�}|jr�| g}d4|kr�|j,|�nt5�}|j6j7�tj8�}|dkrEtj9|d�\}}x<t:j:|j;gggd�dr'|j;j<d�s�Pq�q�W|rA|j=d5|�ndSyqytj>|�Wntj?k
ronXtj@|j;jA�d�tj@|j6jA�d�tjB|||
�Wq�|jjC|jD|j�tjEd6�q�XnddlF}|g}
|j|�rStGjH}!|!j �jId7�r@|!d8 |!d9}!n|!d:g| } nd4|kro|
j,|�n|jJd;|jK| ��ytL|�}"WntMtNfk
r�d}"nX|jO| d<|jPd=|jPd>|jPd?|
�}#|jj
�d@kr|"dkr|j;j<|"�}$nd}$xBt:j:|j;jQgggd�drh|j;jQjRd�s'Pq'q'W|#jS|$�\}%}&|j6jT|%�|&r�|j=dA|&�n|#jUjV�|#jWjV�|#jX}'|'r�|j=d5|'�n
|jJdB�dS(DuExecute
a CGI script.u/iiu?ui�uNo such CGI script (%r)Ni�u#CGI script is
not a plain file (%r)u!CGI script is not executable
(%r)uSERVER_SOFTWAREuSERVER_NAMEuCGI/1.1uGATEWAY_INTERFACEuSERVER_PROTOCOLuSERVER_PORTuREQUEST_METHODu PATH_INFOuPATH_TRANSLATEDuSCRIPT_NAMEuQUERY_STRINGuREMOTE_ADDRu
authorizationiu AUTH_TYPEubasicuasciiu:uREMOTE_USERucontent-typeuCONTENT_TYPEucontent-lengthuCONTENT_LENGTHurefereruHTTP_REFERERuacceptu
iu,uHTTP_ACCEPTu
user-agentuHTTP_USER_AGENTucookieu,
uHTTP_COOKIEuREMOTE_HOSTi�uScript output followsu+u u=uCGI script
exit status %#xiuw.exei����i����u-uucommand:
%ststdintstdoutRjtenvupostu%suCGI script exited
OK(uQUERY_STRINGuREMOTE_HOSTuCONTENT_LENGTHuHTTP_USER_AGENTuHTTP_COOKIEuHTTP_REFERER(YR-R�R�R&R�R�R�trfindR�R'tisfileR�t have_forkR�R�tdeepcopytenvironR]tserverRR,R!RRR�R�R�R2R4R%tbase64tbinasciiR5RURtPY3tdecodebytestdecodetdecodestringtErrortUnicodeErrorRtget_content_typetgetallmatchingheadersR`tstripRdR�tget_allt
setdefaultRPR@R
R�RDREtforktwaitpidtselectR0treadRGtsetuidR�tdup2R�texecvethandle_errortrequestt_exitt
subprocessRiR�R�Retlist2cmdlineR*t TypeErrorR)tPopentPIPEt_socktrecvtcommunicateRTRjR�R�t
returncode((RR-tdirtresttitnextdirtnextrestt scriptdirtquerytscriptt
scriptnamet
scriptfiletispyR�tuqrestt
authorizationR�R�tlengthtreferertaccepttlinetuatcot
cookie_strtkt
decoded_queryRhR�tpidtstsRtcmdlinetinterptnbytestptdataR�Rjtstatus((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pyR��s8
%
!(
(RRR�RBR�R�trbufsizeR�R�R�R�R�R�R�(((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pyR��s uHTTP/1.0i@cC`s�d|f}||_|||�}|jj�}td|dd|dd�y|j�Wn2tk
r�td�|j�tjd�nXdS( uTest the HTTP request handler
class.
This runs an HTTP server on port 8000 (or the first command line
argument).
uuServing HTTP oniuportiu...u&
Keyboard interrupt received,
exiting.N( R,RRtprintt
serve_forevertKeyboardInterrupttserver_closeRitexit(tHandlerClasstServerClasstprotocolRtserver_addressthttpdtsa((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pyttest�s
u__main__u--cgitactionu
store_truethelpuRun as CGI
Serveruportustoretdefaultttypetnargsu?u&Specify alternate port
[default: 8000]R9R(7R�t
__future__RRRRtfutureRtfuture.builtinsR�t__all__tfuture.backportsRtfuture.backports.httpRR.tfuture.backports.urllibRR�R R�R�R�R�RR�RRiRoR�targparseR�R�RR
RtStreamRequestHandlerRR�R�RR�R�R�R�R?RtArgumentParsertparsertadd_argumentR*t
parse_argsRhtcgiR(((s@/usr/lib/python2.7/site-packages/future/backports/http/server.pyt<module>"s`"
3 ��� + �