Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2442015

Browse files
committed
Create http package. #2883.
1 parent 744c2cd commit 2442015

50 files changed

Lines changed: 930 additions & 1203 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Doc/howto/urllib2.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ Because the default handlers handle redirects (codes in the 300 range), and
230230
codes in the 100-299 range indicate success, you will usually only see error
231231
codes in the 400-599 range.
232232

233-
``BaseHTTPServer.BaseHTTPRequestHandler.responses`` is a useful dictionary of
233+
:attr:`http.server.BaseHTTPRequestHandler.responses` is a useful dictionary of
234234
response codes in that shows all the response codes used by RFC 2616. The
235235
dictionary is reproduced here for convenience ::
236236

@@ -385,7 +385,7 @@ redirect. The URL of the page fetched may not be the same as the URL requested.
385385

386386
**info** - this returns a dictionary-like object that describes the page
387387
fetched, particularly the headers sent by the server. It is currently an
388-
``httplib.HTTPMessage`` instance.
388+
``http.client.HTTPMessage`` instance.
389389

390390
Typical headers include 'Content-length', 'Content-type', and so on. See the
391391
`Quick Reference to HTTP Headers <http://www.cs.tut.fi/~jkorpela/http.html>`_
@@ -526,13 +526,13 @@ Sockets and Layers
526526
==================
527527

528528
The Python support for fetching resources from the web is layered. urllib2 uses
529-
the httplib library, which in turn uses the socket library.
529+
the http.client library, which in turn uses the socket library.
530530

531531
As of Python 2.3 you can specify how long a socket should wait for a response
532532
before timing out. This can be useful in applications which have to fetch web
533533
pages. By default the socket module has *no timeout* and can hang. Currently,
534-
the socket timeout is not exposed at the httplib or urllib2 levels. However,
535-
you can set the default timeout globally for all sockets using ::
534+
the socket timeout is not exposed at the http.client or urllib2 levels.
535+
However, you can set the default timeout globally for all sockets using ::
536536

537537
import socket
538538
import urllib2

Doc/library/cgihttpserver.rst

Lines changed: 0 additions & 73 deletions
This file was deleted.

Doc/library/codecs.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,8 +1159,8 @@ convert between Unicode and the ACE. Furthermore, the :mod:`socket` module
11591159
transparently converts Unicode host names to ACE, so that applications need not
11601160
be concerned about converting host names themselves when they pass them to the
11611161
socket module. On top of that, modules that have host names as function
1162-
parameters, such as :mod:`httplib` and :mod:`ftplib`, accept Unicode host names
1163-
(:mod:`httplib` then also transparently sends an IDNA hostname in the
1162+
parameters, such as :mod:`http.client` and :mod:`ftplib`, accept Unicode host
1163+
names (:mod:`http.client` then also transparently sends an IDNA hostname in the
11641164
:mailheader:`Host` field if it sends that field at all).
11651165

11661166
When receiving host names from the wire (such as in reverse name lookup), no
Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1+
:mod:`http.client` --- HTTP protocol client
2+
===========================================
13

2-
:mod:`httplib` --- HTTP protocol client
3-
=======================================
4-
5-
.. module:: httplib
4+
.. module:: http.client
65
:synopsis: HTTP and HTTPS protocol client (requires sockets).
76

87

98
.. index::
109
pair: HTTP; protocol
11-
single: HTTP; httplib (standard module)
10+
single: HTTP; http.client (standard module)
1211

1312
.. index:: module: urllib
1413

@@ -39,10 +38,10 @@ The module provides the following classes:
3938
For example, the following calls all create instances that connect to the server
4039
at the same host and port::
4140

42-
>>> h1 = httplib.HTTPConnection('www.cwi.nl')
43-
>>> h2 = httplib.HTTPConnection('www.cwi.nl:80')
44-
>>> h3 = httplib.HTTPConnection('www.cwi.nl', 80)
45-
>>> h3 = httplib.HTTPConnection('www.cwi.nl', 80, timeout=10)
41+
>>> h1 = http.client.HTTPConnection('www.cwi.nl')
42+
>>> h2 = http.client.HTTPConnection('www.cwi.nl:80')
43+
>>> h3 = http.client.HTTPConnection('www.cwi.nl', 80)
44+
>>> h3 = http.client.HTTPConnection('www.cwi.nl', 80, timeout=10)
4645

4746

4847
.. class:: HTTPSConnection(host[, port[, key_file[, cert_file[, strict[, timeout]]]]])
@@ -338,7 +337,7 @@ and also the following constants for integer status codes:
338337

339338
This dictionary maps the HTTP 1.1 status codes to the W3C names.
340339

341-
Example: ``httplib.responses[httplib.NOT_FOUND]`` is ``'Not Found'``.
340+
Example: ``http.client.responses[http.client.NOT_FOUND]`` is ``'Not Found'``.
342341

343342

344343
.. _httpconnection-objects:
@@ -464,15 +463,13 @@ HTTPResponse Objects
464463
Reason phrase returned by server.
465464

466465

467-
.. _httplib-examples:
468-
469466
Examples
470467
--------
471468

472469
Here is an example session that uses the ``GET`` method::
473470

474-
>>> import httplib
475-
>>> conn = httplib.HTTPConnection("www.python.org")
471+
>>> import http.client
472+
>>> conn = http.client.HTTPConnection("www.python.org")
476473
>>> conn.request("GET", "/index.html")
477474
>>> r1 = conn.getresponse()
478475
>>> print(r1.status, r1.reason)
@@ -487,11 +484,11 @@ Here is an example session that uses the ``GET`` method::
487484

488485
Here is an example session that shows how to ``POST`` requests::
489486

490-
>>> import httplib, urllib
487+
>>> import http.client, urllib
491488
>>> params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0})
492489
>>> headers = {"Content-type": "application/x-www-form-urlencoded",
493490
... "Accept": "text/plain"}
494-
>>> conn = httplib.HTTPConnection("musi-cal.mojam.com:80")
491+
>>> conn = http.client.HTTPConnection("musi-cal.mojam.com:80")
495492
>>> conn.request("POST", "/cgi-bin/query", params, headers)
496493
>>> response = conn.getresponse()
497494
>>> print(response.status, response.reason)
Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1+
:mod:`http.cookiejar` --- Cookie handling for HTTP clients
2+
==========================================================
13

2-
:mod:`cookielib` --- Cookie handling for HTTP clients
3-
=====================================================
4-
5-
.. module:: cookielib
4+
.. module:: http.cookiejar
65
:synopsis: Classes for automatic handling of HTTP cookies.
76
.. moduleauthor:: John J. Lee <[email protected]>
87
.. sectionauthor:: John J. Lee <[email protected]>
98

109

11-
The :mod:`cookielib` module defines classes for automatic handling of HTTP
10+
The :mod:`http.cookiejar` module defines classes for automatic handling of HTTP
1211
cookies. It is useful for accessing web sites that require small pieces of data
1312
-- :dfn:`cookies` -- to be set on the client machine by an HTTP response from a
1413
web server, and then returned to the server in later HTTP requests.
@@ -18,7 +17,7 @@ Both the regular Netscape cookie protocol and the protocol defined by
1817
:rfc:`2109` cookies are parsed as Netscape cookies and subsequently treated
1918
either as Netscape or RFC 2965 cookies according to the 'policy' in effect.
2019
Note that the great majority of cookies on the Internet are Netscape cookies.
21-
:mod:`cookielib` attempts to follow the de-facto Netscape cookie protocol (which
20+
:mod:`http.cookiejar` attempts to follow the de-facto Netscape cookie protocol (which
2221
differs substantially from that set out in the original Netscape specification),
2322
including taking note of the ``max-age`` and ``port`` cookie-attributes
2423
introduced with RFC 2965.
@@ -94,7 +93,7 @@ The following classes are provided:
9493
.. class:: Cookie()
9594

9695
This class represents Netscape, RFC 2109 and RFC 2965 cookies. It is not
97-
expected that users of :mod:`cookielib` construct their own :class:`Cookie`
96+
expected that users of :mod:`http.cookiejar` construct their own :class:`Cookie`
9897
instances. Instead, if necessary, call :meth:`make_cookies` on a
9998
:class:`CookieJar` instance.
10099

@@ -104,9 +103,10 @@ The following classes are provided:
104103
Module :mod:`urllib2`
105104
URL opening with automatic cookie handling.
106105

107-
Module :mod:`Cookie`
106+
Module :mod:`http.cookies`
108107
HTTP cookie classes, principally useful for server-side code. The
109-
:mod:`cookielib` and :mod:`Cookie` modules do not depend on each other.
108+
:mod:`http.cookiejar` and :mod:`http.cookies` modules do not depend on each
109+
other.
110110

111111
http://wwwsearch.sf.net/ClientCookie/
112112
Extensions to this module, including a class for reading Microsoft Internet
@@ -115,7 +115,7 @@ The following classes are provided:
115115
http://wp.netscape.com/newsref/std/cookie_spec.html
116116
The specification of the original Netscape cookie protocol. Though this is
117117
still the dominant protocol, the 'Netscape cookie protocol' implemented by all
118-
the major browsers (and :mod:`cookielib`) only bears a passing resemblance to
118+
the major browsers (and :mod:`http.cookiejar`) only bears a passing resemblance to
119119
the one sketched out in ``cookie_spec.html``.
120120

121121
:rfc:`2109` - HTTP State Management Mechanism
@@ -339,7 +339,7 @@ methods:
339339

340340
Return boolean value indicating whether cookie should be accepted from server.
341341

342-
*cookie* is a :class:`cookielib.Cookie` instance. *request* is an object
342+
*cookie* is a :class:`Cookie` instance. *request* is an object
343343
implementing the interface defined by the documentation for
344344
:meth:`CookieJar.extract_cookies`.
345345

@@ -348,7 +348,7 @@ methods:
348348

349349
Return boolean value indicating whether cookie should be returned to server.
350350

351-
*cookie* is a :class:`cookielib.Cookie` instance. *request* is an object
351+
*cookie* is a :class:`Cookie` instance. *request* is an object
352352
implementing the interface defined by the documentation for
353353
:meth:`CookieJar.add_cookie_header`.
354354

@@ -424,10 +424,10 @@ The easiest way to provide your own policy is to override this class and call
424424
its methods in your overridden implementations before adding your own additional
425425
checks::
426426

427-
import cookielib
428-
class MyCookiePolicy(cookielib.DefaultCookiePolicy):
427+
import http.cookiejar
428+
class MyCookiePolicy(http.cookiejar.DefaultCookiePolicy):
429429
def set_ok(self, cookie, request):
430-
if not cookielib.DefaultCookiePolicy.set_ok(self, cookie, request):
430+
if not http.cookiejar.DefaultCookiePolicy.set_ok(self, cookie, request):
431431
return False
432432
if i_dont_want_to_store_this_cookie(cookie):
433433
return False
@@ -584,8 +584,6 @@ combinations of the above flags:
584584
Equivalent to ``DomainStrictNoDots|DomainStrictNonDomain``.
585585

586586

587-
.. _cookielib-cookie-objects:
588-
589587
Cookie Objects
590588
--------------
591589

@@ -594,7 +592,7 @@ standard cookie-attributes specified in the various cookie standards. The
594592
correspondence is not one-to-one, because there are complicated rules for
595593
assigning default values, because the ``max-age`` and ``expires``
596594
cookie-attributes contain equivalent information, and because RFC 2109 cookies
597-
may be 'downgraded' by :mod:`cookielib` from version 1 to version 0 (Netscape)
595+
may be 'downgraded' by :mod:`http.cookiejar` from version 1 to version 0 (Netscape)
598596
cookies.
599597

600598
Assignment to these attributes should not be necessary other than in rare
@@ -606,7 +604,7 @@ internal consistency, so you should know what you're doing if you do that.
606604

607605
Integer or :const:`None`. Netscape cookies have :attr:`version` 0. RFC 2965 and
608606
RFC 2109 cookies have a ``version`` cookie-attribute of 1. However, note that
609-
:mod:`cookielib` may 'downgrade' RFC 2109 cookies to Netscape cookies, in which
607+
:mod:`http.cookiejar` may 'downgrade' RFC 2109 cookies to Netscape cookies, in which
610608
case :attr:`version` is 0.
611609

612610

@@ -664,7 +662,7 @@ internal consistency, so you should know what you're doing if you do that.
664662
True if this cookie was received as an RFC 2109 cookie (ie. the cookie
665663
arrived in a :mailheader:`Set-Cookie` header, and the value of the Version
666664
cookie-attribute in that header was 1). This attribute is provided because
667-
:mod:`cookielib` may 'downgrade' RFC 2109 cookies to Netscape cookies, in
665+
:mod:`http.cookiejar` may 'downgrade' RFC 2109 cookies to Netscape cookies, in
668666
which case :attr:`version` is 0.
669667

670668

@@ -713,23 +711,21 @@ The :class:`Cookie` class also defines the following method:
713711
cookie has expired at the specified time.
714712

715713

716-
.. _cookielib-examples:
717-
718714
Examples
719715
--------
720716

721-
The first example shows the most common usage of :mod:`cookielib`::
717+
The first example shows the most common usage of :mod:`http.cookiejar`::
722718

723-
import cookielib, urllib2
724-
cj = cookielib.CookieJar()
719+
import http.cookiejar, urllib2
720+
cj = http.cookiejar.CookieJar()
725721
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
726722
r = opener.open("http://example.com/")
727723

728724
This example illustrates how to open a URL using your Netscape, Mozilla, or Lynx
729725
cookies (assumes Unix/Netscape convention for location of the cookies file)::
730726

731-
import os, cookielib, urllib2
732-
cj = cookielib.MozillaCookieJar()
727+
import os, http.cookiejar, urllib2
728+
cj = http.cookiejar.MozillaCookieJar()
733729
cj.load(os.path.join(os.environ["HOME"], ".netscape/cookies.txt"))
734730
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
735731
r = opener.open("http://example.com/")
@@ -740,7 +736,7 @@ Netscape cookies, and block some domains from setting cookies or having them
740736
returned::
741737

742738
import urllib2
743-
from cookielib import CookieJar, DefaultCookiePolicy
739+
from http.cookiejar import CookieJar, DefaultCookiePolicy
744740
policy = DefaultCookiePolicy(
745741
rfc2965=True, strict_ns_domain=Policy.DomainStrict,
746742
blocked_domains=["ads.net", ".ads.net"])

0 commit comments

Comments
 (0)