mirror of https://github.com/python/cpython
parent
c71585e069
commit
a2e9818467
|
@ -1,55 +1,54 @@
|
||||||
\section{Standard Module \sectcode{httplib}}
|
\section{Standard Module \sectcode{httplib}}
|
||||||
\label{module-httplib}
|
\label{module-httplib}
|
||||||
\stmodindex{httplib}
|
\stmodindex{httplib}
|
||||||
\index{HTTP}
|
\indexii{HTTP}{protocol}
|
||||||
|
|
||||||
\setindexsubitem{(in module httplib)}
|
|
||||||
|
|
||||||
This module defines a class which implements the client side of the
|
This module defines a class which implements the client side of the
|
||||||
HTTP protocol. It is normally not used directly --- the module
|
HTTP protocol. It is normally not used directly --- the module
|
||||||
\code{urllib} uses it to handle URLs that use HTTP.
|
\module{urllib}\refstmodindex{urllib} uses it to handle URLs that use
|
||||||
\refstmodindex{urllib}
|
HTTP.
|
||||||
|
|
||||||
The module defines one class, \code{HTTP}. An \code{HTTP} instance
|
The module defines one class, \class{HTTP}. An \class{HTTP} instance
|
||||||
represents one transaction with an HTTP server. It should be
|
represents one transaction with an HTTP server. It should be
|
||||||
instantiated passing it a host and optional port number. If no port
|
instantiated passing it a host and optional port number. If no port
|
||||||
number is passed, the port is extracted from the host string if it has
|
number is passed, the port is extracted from the host string if it has
|
||||||
the form \code{host:port}, else the default HTTP port (80) is used.
|
the form \code{\var{host}:\var{port}}, else the default HTTP port (80)
|
||||||
If no host is passed, no connection is made, and the \code{connect}
|
is used. If no host is passed, no connection is made, and the
|
||||||
method should be used to connect to a server. For example, the
|
\method{connect()} method should be used to connect to a server. For
|
||||||
following calls all create instances that connect to the server at the
|
example, the following calls all create instances that connect to the
|
||||||
same host and port:
|
server at the same host and port:
|
||||||
|
|
||||||
\begin{verbatim}
|
\begin{verbatim}
|
||||||
>>> h1 = httplib.HTTP('www.cwi.nl')
|
>>> h1 = httplib.HTTP('www.cwi.nl')
|
||||||
>>> h2 = httplib.HTTP('www.cwi.nl:80')
|
>>> h2 = httplib.HTTP('www.cwi.nl:80')
|
||||||
>>> h3 = httplib.HTTP('www.cwi.nl', 80)
|
>>> h3 = httplib.HTTP('www.cwi.nl', 80)
|
||||||
\end{verbatim}
|
\end{verbatim}
|
||||||
%
|
|
||||||
Once an \code{HTTP} instance has been connected to an HTTP server, it
|
Once an \class{HTTP} instance has been connected to an HTTP server, it
|
||||||
should be used as follows:
|
should be used as follows:
|
||||||
|
|
||||||
\begin{enumerate}
|
\begin{enumerate}
|
||||||
|
|
||||||
\item[1.] Make exactly one call to the \code{putrequest()} method.
|
\item[1.] Make exactly one call to the \method{putrequest()} method.
|
||||||
|
|
||||||
\item[2.] Make zero or more calls to the \code{putheader()} method.
|
\item[2.] Make zero or more calls to the \method{putheader()} method.
|
||||||
|
|
||||||
\item[3.] Call the \code{endheaders()} method (this can be omitted if
|
\item[3.] Call the \method{endheaders()} method (this can be omitted if
|
||||||
step 4 makes no calls).
|
step 4 makes no calls).
|
||||||
|
|
||||||
\item[4.] Optional calls to the \code{send()} method.
|
\item[4.] Optional calls to the \method{send()} method.
|
||||||
|
|
||||||
\item[5.] Call the \code{getreply()} method.
|
\item[5.] Call the \method{getreply()} method.
|
||||||
|
|
||||||
\item[6.] Call the \code{getfile()} method and read the data off the
|
\item[6.] Call the \method{getfile()} method and read the data off the
|
||||||
file object that it returns.
|
file object that it returns.
|
||||||
|
|
||||||
\end{enumerate}
|
\end{enumerate}
|
||||||
|
|
||||||
\subsection{HTTP Objects}
|
\subsection{HTTP Objects}
|
||||||
|
|
||||||
\code{HTTP} instances have the following methods:
|
\class{HTTP} instances have the following methods:
|
||||||
|
|
||||||
\setindexsubitem{(HTTP method)}
|
\setindexsubitem{(HTTP method)}
|
||||||
|
|
||||||
|
@ -59,7 +58,7 @@ The default debug level is \code{0}, meaning no debugging output is
|
||||||
printed.
|
printed.
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
\begin{funcdesc}{connect}{host\optional{\, port}}
|
\begin{funcdesc}{connect}{host\optional{, port}}
|
||||||
Connect to the server given by \var{host} and \var{port}. See the
|
Connect to the server given by \var{host} and \var{port}. See the
|
||||||
intro for the default port. This should be called directly only if
|
intro for the default port. This should be called directly only if
|
||||||
the instance was instantiated without passing a host.
|
the instance was instantiated without passing a host.
|
||||||
|
@ -67,18 +66,18 @@ the instance was instantiated without passing a host.
|
||||||
|
|
||||||
\begin{funcdesc}{send}{data}
|
\begin{funcdesc}{send}{data}
|
||||||
Send data to the server. This should be used directly only after the
|
Send data to the server. This should be used directly only after the
|
||||||
\code{endheaders()} method has been called and before
|
\method{endheaders()} method has been called and before
|
||||||
\code{getreply()} has been called.
|
\method{getreply()} has been called.
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
\begin{funcdesc}{putrequest}{request\, selector}
|
\begin{funcdesc}{putrequest}{request, selector}
|
||||||
This should be the first call after the connection to the server has
|
This should be the first call after the connection to the server has
|
||||||
been made. It sends a line to the server consisting of the
|
been made. It sends a line to the server consisting of the
|
||||||
\var{request} string, the \var{selector} string, and the HTTP version
|
\var{request} string, the \var{selector} string, and the HTTP version
|
||||||
(\code{HTTP/1.0}).
|
(\code{HTTP/1.0}).
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
\begin{funcdesc}{putheader}{header\, argument\optional{\, ...}}
|
\begin{funcdesc}{putheader}{header, argument\optional{, ...}}
|
||||||
Send an \rfc{822} style header to the server. It sends a line to the
|
Send an \rfc{822} style header to the server. It sends a line to the
|
||||||
server consisting of the header, a colon and a space, and the first
|
server consisting of the header, a colon and a space, and the first
|
||||||
argument. If more arguments are given, continuation lines are sent,
|
argument. If more arguments are given, continuation lines are sent,
|
||||||
|
@ -91,20 +90,20 @@ Send a blank line to the server, signalling the end of the headers.
|
||||||
|
|
||||||
\begin{funcdesc}{getreply}{}
|
\begin{funcdesc}{getreply}{}
|
||||||
Complete the request by shutting down the sending end of the socket,
|
Complete the request by shutting down the sending end of the socket,
|
||||||
read the reply from the server, and return a triple (\var{replycode},
|
read the reply from the server, and return a triple
|
||||||
\var{message}, \var{headers}). Here \var{replycode} is the integer
|
\code{(\var{replycode}, \var{message}, \var{headers})}. Here,
|
||||||
reply code from the request (e.g.\ \code{200} if the request was
|
\var{replycode} is the integer reply code from the request (e.g.\
|
||||||
handled properly); \var{message} is the message string corresponding
|
\code{200} if the request was handled properly); \var{message} is the
|
||||||
to the reply code; and \var{headers} is an instance of the class
|
message string corresponding to the reply code; and \var{headers} is
|
||||||
\code{mimetools.Message} containing the headers received from the server.
|
an instance of the class \class{mimetools.Message} containing the
|
||||||
See the description of the \code{mimetools} module.
|
headers received from the server. See the description of the
|
||||||
\refstmodindex{mimetools}
|
\module{mimetools}\refstmodindex{mimetools} module.
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
\begin{funcdesc}{getfile}{}
|
\begin{funcdesc}{getfile}{}
|
||||||
Return a file object from which the data returned by the server can be
|
Return a file object from which the data returned by the server can be
|
||||||
read, using the \code{read()}, \code{readline()} or \code{readlines()}
|
read, using the \method{read()}, \method{readline()} or
|
||||||
methods.
|
\method{readlines()} methods.
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
\subsection{Example}
|
\subsection{Example}
|
||||||
|
|
|
@ -1,55 +1,54 @@
|
||||||
\section{Standard Module \sectcode{httplib}}
|
\section{Standard Module \sectcode{httplib}}
|
||||||
\label{module-httplib}
|
\label{module-httplib}
|
||||||
\stmodindex{httplib}
|
\stmodindex{httplib}
|
||||||
\index{HTTP}
|
\indexii{HTTP}{protocol}
|
||||||
|
|
||||||
\setindexsubitem{(in module httplib)}
|
|
||||||
|
|
||||||
This module defines a class which implements the client side of the
|
This module defines a class which implements the client side of the
|
||||||
HTTP protocol. It is normally not used directly --- the module
|
HTTP protocol. It is normally not used directly --- the module
|
||||||
\code{urllib} uses it to handle URLs that use HTTP.
|
\module{urllib}\refstmodindex{urllib} uses it to handle URLs that use
|
||||||
\refstmodindex{urllib}
|
HTTP.
|
||||||
|
|
||||||
The module defines one class, \code{HTTP}. An \code{HTTP} instance
|
The module defines one class, \class{HTTP}. An \class{HTTP} instance
|
||||||
represents one transaction with an HTTP server. It should be
|
represents one transaction with an HTTP server. It should be
|
||||||
instantiated passing it a host and optional port number. If no port
|
instantiated passing it a host and optional port number. If no port
|
||||||
number is passed, the port is extracted from the host string if it has
|
number is passed, the port is extracted from the host string if it has
|
||||||
the form \code{host:port}, else the default HTTP port (80) is used.
|
the form \code{\var{host}:\var{port}}, else the default HTTP port (80)
|
||||||
If no host is passed, no connection is made, and the \code{connect}
|
is used. If no host is passed, no connection is made, and the
|
||||||
method should be used to connect to a server. For example, the
|
\method{connect()} method should be used to connect to a server. For
|
||||||
following calls all create instances that connect to the server at the
|
example, the following calls all create instances that connect to the
|
||||||
same host and port:
|
server at the same host and port:
|
||||||
|
|
||||||
\begin{verbatim}
|
\begin{verbatim}
|
||||||
>>> h1 = httplib.HTTP('www.cwi.nl')
|
>>> h1 = httplib.HTTP('www.cwi.nl')
|
||||||
>>> h2 = httplib.HTTP('www.cwi.nl:80')
|
>>> h2 = httplib.HTTP('www.cwi.nl:80')
|
||||||
>>> h3 = httplib.HTTP('www.cwi.nl', 80)
|
>>> h3 = httplib.HTTP('www.cwi.nl', 80)
|
||||||
\end{verbatim}
|
\end{verbatim}
|
||||||
%
|
|
||||||
Once an \code{HTTP} instance has been connected to an HTTP server, it
|
Once an \class{HTTP} instance has been connected to an HTTP server, it
|
||||||
should be used as follows:
|
should be used as follows:
|
||||||
|
|
||||||
\begin{enumerate}
|
\begin{enumerate}
|
||||||
|
|
||||||
\item[1.] Make exactly one call to the \code{putrequest()} method.
|
\item[1.] Make exactly one call to the \method{putrequest()} method.
|
||||||
|
|
||||||
\item[2.] Make zero or more calls to the \code{putheader()} method.
|
\item[2.] Make zero or more calls to the \method{putheader()} method.
|
||||||
|
|
||||||
\item[3.] Call the \code{endheaders()} method (this can be omitted if
|
\item[3.] Call the \method{endheaders()} method (this can be omitted if
|
||||||
step 4 makes no calls).
|
step 4 makes no calls).
|
||||||
|
|
||||||
\item[4.] Optional calls to the \code{send()} method.
|
\item[4.] Optional calls to the \method{send()} method.
|
||||||
|
|
||||||
\item[5.] Call the \code{getreply()} method.
|
\item[5.] Call the \method{getreply()} method.
|
||||||
|
|
||||||
\item[6.] Call the \code{getfile()} method and read the data off the
|
\item[6.] Call the \method{getfile()} method and read the data off the
|
||||||
file object that it returns.
|
file object that it returns.
|
||||||
|
|
||||||
\end{enumerate}
|
\end{enumerate}
|
||||||
|
|
||||||
\subsection{HTTP Objects}
|
\subsection{HTTP Objects}
|
||||||
|
|
||||||
\code{HTTP} instances have the following methods:
|
\class{HTTP} instances have the following methods:
|
||||||
|
|
||||||
\setindexsubitem{(HTTP method)}
|
\setindexsubitem{(HTTP method)}
|
||||||
|
|
||||||
|
@ -59,7 +58,7 @@ The default debug level is \code{0}, meaning no debugging output is
|
||||||
printed.
|
printed.
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
\begin{funcdesc}{connect}{host\optional{\, port}}
|
\begin{funcdesc}{connect}{host\optional{, port}}
|
||||||
Connect to the server given by \var{host} and \var{port}. See the
|
Connect to the server given by \var{host} and \var{port}. See the
|
||||||
intro for the default port. This should be called directly only if
|
intro for the default port. This should be called directly only if
|
||||||
the instance was instantiated without passing a host.
|
the instance was instantiated without passing a host.
|
||||||
|
@ -67,18 +66,18 @@ the instance was instantiated without passing a host.
|
||||||
|
|
||||||
\begin{funcdesc}{send}{data}
|
\begin{funcdesc}{send}{data}
|
||||||
Send data to the server. This should be used directly only after the
|
Send data to the server. This should be used directly only after the
|
||||||
\code{endheaders()} method has been called and before
|
\method{endheaders()} method has been called and before
|
||||||
\code{getreply()} has been called.
|
\method{getreply()} has been called.
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
\begin{funcdesc}{putrequest}{request\, selector}
|
\begin{funcdesc}{putrequest}{request, selector}
|
||||||
This should be the first call after the connection to the server has
|
This should be the first call after the connection to the server has
|
||||||
been made. It sends a line to the server consisting of the
|
been made. It sends a line to the server consisting of the
|
||||||
\var{request} string, the \var{selector} string, and the HTTP version
|
\var{request} string, the \var{selector} string, and the HTTP version
|
||||||
(\code{HTTP/1.0}).
|
(\code{HTTP/1.0}).
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
\begin{funcdesc}{putheader}{header\, argument\optional{\, ...}}
|
\begin{funcdesc}{putheader}{header, argument\optional{, ...}}
|
||||||
Send an \rfc{822} style header to the server. It sends a line to the
|
Send an \rfc{822} style header to the server. It sends a line to the
|
||||||
server consisting of the header, a colon and a space, and the first
|
server consisting of the header, a colon and a space, and the first
|
||||||
argument. If more arguments are given, continuation lines are sent,
|
argument. If more arguments are given, continuation lines are sent,
|
||||||
|
@ -91,20 +90,20 @@ Send a blank line to the server, signalling the end of the headers.
|
||||||
|
|
||||||
\begin{funcdesc}{getreply}{}
|
\begin{funcdesc}{getreply}{}
|
||||||
Complete the request by shutting down the sending end of the socket,
|
Complete the request by shutting down the sending end of the socket,
|
||||||
read the reply from the server, and return a triple (\var{replycode},
|
read the reply from the server, and return a triple
|
||||||
\var{message}, \var{headers}). Here \var{replycode} is the integer
|
\code{(\var{replycode}, \var{message}, \var{headers})}. Here,
|
||||||
reply code from the request (e.g.\ \code{200} if the request was
|
\var{replycode} is the integer reply code from the request (e.g.\
|
||||||
handled properly); \var{message} is the message string corresponding
|
\code{200} if the request was handled properly); \var{message} is the
|
||||||
to the reply code; and \var{headers} is an instance of the class
|
message string corresponding to the reply code; and \var{headers} is
|
||||||
\code{mimetools.Message} containing the headers received from the server.
|
an instance of the class \class{mimetools.Message} containing the
|
||||||
See the description of the \code{mimetools} module.
|
headers received from the server. See the description of the
|
||||||
\refstmodindex{mimetools}
|
\module{mimetools}\refstmodindex{mimetools} module.
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
\begin{funcdesc}{getfile}{}
|
\begin{funcdesc}{getfile}{}
|
||||||
Return a file object from which the data returned by the server can be
|
Return a file object from which the data returned by the server can be
|
||||||
read, using the \code{read()}, \code{readline()} or \code{readlines()}
|
read, using the \method{read()}, \method{readline()} or
|
||||||
methods.
|
\method{readlines()} methods.
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
\subsection{Example}
|
\subsection{Example}
|
||||||
|
|
Loading…
Reference in New Issue