summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2004-09-18 09:03:49 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2004-09-18 09:03:49 (GMT)
commit39a317890fa7651e8f124c1a566af5f7a72da792 (patch)
tree4852eb7f6523a631654cf843690c962644b80688
parent17cb60083c53b464a329f1a660a922db677389dd (diff)
downloadcpython-39a317890fa7651e8f124c1a566af5f7a72da792.zip
cpython-39a317890fa7651e8f124c1a566af5f7a72da792.tar.gz
cpython-39a317890fa7651e8f124c1a566af5f7a72da792.tar.bz2
Patch #1025790: Add status code constants to httplib.
-rw-r--r--Doc/lib/libhttplib.tex172
-rw-r--r--Lib/httplib.py65
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS2
4 files changed, 227 insertions, 13 deletions
diff --git a/Doc/lib/libhttplib.tex b/Doc/lib/libhttplib.tex
index 60fd7b1..ed15e73 100644
--- a/Doc/lib/libhttplib.tex
+++ b/Doc/lib/libhttplib.tex
@@ -24,16 +24,6 @@ that use HTTP and HTTPS.
to the online docstrings for usage.
\end{notice}
-The constants defined in this module are:
-
-\begin{datadesc}{HTTP_PORT}
- The default port for the HTTP protocol (always \code{80}).
-\end{datadesc}
-
-\begin{datadesc}{HTTPS_PORT}
- The default port for the HTTPS protocol (always \code{443}).
-\end{datadesc}
-
The module provides the following classes:
\begin{classdesc}{HTTPConnection}{host\optional{, port}}
@@ -135,6 +125,168 @@ HTTP status code that we don't understand.
\versionadded{2.0}
\end{excdesc}
+The constants defined in this module are:
+
+\begin{datadesc}{HTTP_PORT}
+ The default port for the HTTP protocol (always \code{80}).
+\end{datadesc}
+
+\begin{datadesc}{HTTPS_PORT}
+ The default port for the HTTPS protocol (always \code{443}).
+\end{datadesc}
+
+and also the following constants for integer status codes:
+
+\begin{tableiii}{l|c|l}{constant}{Constant}{Value}{Definition}
+ \lineiii{CONTINUE}{\code{100}}
+ {HTTP/1.1, \ulink{RFC 2616, Section 10.1.1}
+ {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.1.1}}
+ \lineiii{SWITCHING_PROTOCOLS}{\code{101}}
+ {HTTP/1.1, \ulink{RFC 2616, Section 10.1.2}
+ {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.1.2}}
+ \lineiii{PROCESSING}{\code{102}}
+ {WEBDAV, \ulink{RFC 2518, Section 10.1}
+ {http://www.webdav.org/specs/rfc2518.htm#STATUS_102}}
+
+ \lineiii{OK}{\code{200}}
+ {HTTP/1.1, \ulink{RFC 2616, Section 10.2.1}
+ {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.1}}
+ \lineiii{CREATED}{\code{201}}
+ {HTTP/1.1, \ulink{RFC 2616, Section 10.2.2}
+ {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.2}}
+ \lineiii{ACCEPTED}{\code{202}}
+ {HTTP/1.1, \ulink{RFC 2616, Section 10.2.3}
+ {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.3}}
+ \lineiii{NON_AUTHORITATIVE_INFORMATION}{\code{203}}
+ {HTTP/1.1, \ulink{RFC 2616, Section 10.2.4}
+ {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.4}}
+ \lineiii{NO_CONTENT}{\code{204}}
+ {HTTP/1.1, \ulink{RFC 2616, Section 10.2.5}
+ {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.5}}
+ \lineiii{RESET_CONTENT}{\code{205}}
+ {HTTP/1.1, \ulink{RFC 2616, Section 10.2.6}
+ {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.6}}
+ \lineiii{PARTIAL_CONTENT}{\code{206}}
+ {HTTP/1.1, \ulink{RFC 2616, Section 10.2.7}
+ {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.7}}
+ \lineiii{MULTI_STATUS}{\code{207}}
+ {WEBDAV \ulink{RFC 2518, Section 10.2}
+ {http://www.webdav.org/specs/rfc2518.htm#STATUS_207}}
+ \lineiii{IM_USED}{\code{226}}
+ {Delta encoding in HTTP, \rfc{3229}, Section 10.4.1}
+
+ \lineiii{MULTIPLE_CHOICES}{\code{300}}
+ {HTTP/1.1, \ulink{RFC 2616, Section 10.3.1}
+ {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.1}}
+ \lineiii{MOVED_PERMANENTLY}{\code{301}}
+ {HTTP/1.1, \ulink{RFC 2616, Section 10.3.2}
+ {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.2}}
+ \lineiii{FOUND}{\code{302}}
+ {HTTP/1.1, \ulink{RFC 2616, Section 10.3.3}
+ {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.3}}
+ \lineiii{SEE_OTHER}{\code{303}}
+ {HTTP/1.1, \ulink{RFC 2616, Section 10.3.4}
+ {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.4}}
+ \lineiii{NOT_MODIFIED}{\code{304}}
+ {HTTP/1.1, \ulink{RFC 2616, Section 10.3.5}
+ {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.5}}
+ \lineiii{USE_PROXY}{\code{305}}
+ {HTTP/1.1, \ulink{RFC 2616, Section 10.3.6}
+ {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.6}}
+ \lineiii{TEMPORARY_REDIRECT}{\code{307}}
+ {HTTP/1.1, \ulink{RFC 2616, Section 10.3.8}
+ {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.8}}
+
+ \lineiii{BAD_REQUEST}{\code{400}}
+ {HTTP/1.1, \ulink{RFC 2616, Section 10.4.1}
+ {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.1}}
+ \lineiii{UNAUTHORIZED}{\code{401}}
+ {HTTP/1.1, \ulink{RFC 2616, Section 10.4.2}
+ {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.2}}
+ \lineiii{PAYMENT_REQUIRED}{\code{402}}
+ {HTTP/1.1, \ulink{RFC 2616, Section 10.4.3}
+ {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.3}}
+ \lineiii{FORBIDDEN}{\code{403}}
+ {HTTP/1.1, \ulink{RFC 2616, Section 10.4.4}
+ {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.4}}
+ \lineiii{NOT_FOUND}{\code{404}}
+ {HTTP/1.1, \ulink{RFC 2616, Section 10.4.5}
+ {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.5}}
+ \lineiii{METHOD_NOT_ALLOWED}{\code{405}}
+ {HTTP/1.1, \ulink{RFC 2616, Section 10.4.6}
+ {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.6}}
+ \lineiii{NOT_ACCEPTABLE}{\code{406}}
+ {HTTP/1.1, \ulink{RFC 2616, Section 10.4.7}
+ {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.7}}
+ \lineiii{PROXY_AUTHENTICATION_REQUIRED}
+ {\code{407}}{HTTP/1.1, \ulink{RFC 2616, Section 10.4.8}
+ {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.8}}
+ \lineiii{REQUEST_TIMEOUT}{\code{408}}
+ {HTTP/1.1, \ulink{RFC 2616, Section 10.4.9}
+ {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.9}}
+ \lineiii{CONFLICT}{\code{409}}
+ {HTTP/1.1, \ulink{RFC 2616, Section 10.4.10}
+ {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.10}}
+ \lineiii{GONE}{\code{410}}
+ {HTTP/1.1, \ulink{RFC 2616, Section 10.4.11}
+ {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.11}}
+ \lineiii{LENGTH_REQUIRED}{\code{411}}
+ {HTTP/1.1, \ulink{RFC 2616, Section 10.4.12}
+ {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.12}}
+ \lineiii{PRECONDITION_FAILED}{\code{412}}
+ {HTTP/1.1, \ulink{RFC 2616, Section 10.4.13}
+ {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.13}}
+ \lineiii{REQUEST_ENTITY_TOO_LARGE}
+ {\code{413}}{HTTP/1.1, \ulink{RFC 2616, Section 10.4.14}
+ {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.14}}
+ \lineiii{REQUEST_URI_TOO_LONG}{\code{414}}
+ {HTTP/1.1, \ulink{RFC 2616, Section 10.4.15}
+ {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.15}}
+ \lineiii{UNSUPPORTED_MEDIA_TYPE}{\code{415}}
+ {HTTP/1.1, \ulink{RFC 2616, Section 10.4.16}
+ {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.16}}
+ \lineiii{REQUESTED_RANGE_NOT_SATISFIABLE}{\code{416}}
+ {HTTP/1.1, \ulink{RFC 2616, Section 10.4.17}
+ {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.17}}
+ \lineiii{EXPECTATION_FAILED}{\code{417}}
+ {HTTP/1.1, \ulink{RFC 2616, Section 10.4.18}
+ {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.18}}
+ \lineiii{UNPROCESSABLE_ENTITY}{\code{422}}
+ {WEBDAV, \ulink{RFC 2518, Section 10.3}
+ {http://www.webdav.org/specs/rfc2518.htm#STATUS_422}}
+ \lineiii{LOCKED}{\code{423}}
+ {WEBDAV \ulink{RFC 2518, Section 10.4}
+ {http://www.webdav.org/specs/rfc2518.htm#STATUS_423}}
+ \lineiii{FAILED_DEPENDENCY}{\code{424}}
+ {WEBDAV, \ulink{RFC 2518, Section 10.5}
+ {http://www.webdav.org/specs/rfc2518.htm#STATUS_424}}
+ \lineiii{UPGRADE_REQUIRED}{\code{426}}
+ {HTTP Upgrade to TLS, \rfc{2817}, Section 6}
+
+ \lineiii{INTERNAL_SERVER_ERROR}{\code{500}}
+ {HTTP/1.1, \ulink{RFC 2616, Section 10.5.1}
+ {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5.1}}
+ \lineiii{NOT_IMPLEMENTED}{\code{501}}
+ {HTTP/1.1, \ulink{RFC 2616, Section 10.5.2}
+ {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5.2}}
+ \lineiii{BAD_GATEWAY}{\code{502}}
+ {HTTP/1.1 \ulink{RFC 2616, Section 10.5.3}
+ {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5.3}}
+ \lineiii{SERVICE_UNAVAILABLE}{\code{503}}
+ {HTTP/1.1, \ulink{RFC 2616, Section 10.5.4}
+ {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5.4}}
+ \lineiii{GATEWAY_TIMEOUT}{\code{504}}
+ {HTTP/1.1 \ulink{RFC 2616, Section 10.5.5}
+ {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5.5}}
+ \lineiii{HTTP_VERSION_NOT_SUPPORTED}{\code{505}}
+ {HTTP/1.1, \ulink{RFC 2616, Section 10.5.6}
+ {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5.6}}
+ \lineiii{INSUFFICIENT_STORAGE}{\code{507}}
+ {WEBDAV, \ulink{RFC 2518, Section 10.6}
+ {http://www.webdav.org/specs/rfc2518.htm#STATUS_507}}
+ \lineiii{NOT_EXTENDED}{\code{510}}
+ {An HTTP Extension Framework, \rfc{2774}, Section 7}
+\end{tableiii}
\subsection{HTTPConnection Objects \label{httpconnection-objects}}
diff --git a/Lib/httplib.py b/Lib/httplib.py
index 1fb5e8a..d4fcf7c 100644
--- a/Lib/httplib.py
+++ b/Lib/httplib.py
@@ -93,6 +93,66 @@ _CS_IDLE = 'Idle'
_CS_REQ_STARTED = 'Request-started'
_CS_REQ_SENT = 'Request-sent'
+# status codes
+# informational
+CONTINUE = 100
+SWITCHING_PROTOCOLS = 101
+PROCESSING = 102
+
+# successful
+OK = 200
+CREATED = 201
+ACCEPTED = 202
+NON_AUTHORITATIVE_INFORMATION = 203
+NO_CONTENT = 204
+RESET_CONTENT = 205
+PARTIAL_CONTENT = 206
+MULTI_STATUS = 207
+IM_USED = 226
+
+# redirection
+MULTIPLE_CHOICES = 300
+MOVED_PERMANENTLY = 301
+FOUND = 302
+SEE_OTHER = 303
+NOT_MODIFIED = 304
+USE_PROXY = 305
+TEMPORARY_REDIRECT = 307
+
+# client error
+BAD_REQUEST = 400
+UNAUTHORIZED = 401
+PAYMENT_REQUIRED = 402
+FORBIDDEN = 403
+NOT_FOUND = 404
+METHOD_NOT_ALLOWED = 405
+NOT_ACCEPTABLE = 406
+PROXY_AUTHENTICATION_REQUIRED = 407
+REQUEST_TIMEOUT = 408
+CONFLICT = 409
+GONE = 410
+LENGTH_REQUIRED = 411
+PRECONDITION_FAILED = 412
+REQUEST_ENTITY_TOO_LARGE = 413
+REQUEST_URI_TOO_LONG = 414
+UNSUPPORTED_MEDIA_TYPE = 415
+REQUESTED_RANGE_NOT_SATISFIABLE = 416
+EXPECTATION_FAILED = 417
+UNPROCESSABLE_ENTITY = 422
+LOCKED = 423
+FAILED_DEPENDENCY = 424
+UPGRADE_REQUIRED = 426
+
+# server error
+INTERNAL_SERVER_ERROR = 500
+NOT_IMPLEMENTED = 501
+BAD_GATEWAY = 502
+SERVICE_UNAVAILABLE = 503
+GATEWAY_TIMEOUT = 504
+HTTP_VERSION_NOT_SUPPORTED = 505
+INSUFFICIENT_STORAGE = 507
+NOT_EXTENDED = 510
+
class HTTPMessage(mimetools.Message):
def addheader(self, key, value):
@@ -271,7 +331,7 @@ class HTTPResponse:
# read until we get a non-100 response
while True:
version, status, reason = self._read_status()
- if status != 100:
+ if status != CONTINUE:
break
# skip the header from the 100 response
while True:
@@ -329,8 +389,7 @@ class HTTPResponse:
self.length = None
# does the body have a fixed length? (of zero)
- if (status == 204 or # No Content
- status == 304 or # Not Modified
+ if (status == NO_CONTENT or status == NOT_MODIFIED or
100 <= status < 200 or # 1xx codes
self._method == 'HEAD'):
self.length = 0
diff --git a/Misc/ACKS b/Misc/ACKS
index 04114bf..72fe0cf 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -161,6 +161,7 @@ Eugene Dvurechenski
Maxim Dzumanenko
Hans Eckardt
Grant Edwards
+Andrew Eland
Lance Ellinghaus
David Ely
Jeff Epler
diff --git a/Misc/NEWS b/Misc/NEWS
index fcc52d7..a6ca5fb 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -22,6 +22,8 @@ Extension modules
Library
-------
+- httplib now offers symbolic constants for the HTTP status codes.
+
- SF bug #1028306: Trying to compare a ``datetime.date`` to a
``datetime.datetime`` mistakenly compared only the year, month and day.
Now it acts like a mixed-type comparison: ``False`` for ``==``,