mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Correct description/example of how to override User-agent.
This commit is contained in:
parent
e2713becd8
commit
8e97fbf360
1 changed files with 4 additions and 4 deletions
|
@ -160,8 +160,8 @@ can be accomplished with the following code:
|
||||||
import urllib
|
import urllib
|
||||||
|
|
||||||
class AppURLopener(urllib.FancyURLopener):
|
class AppURLopener(urllib.FancyURLopener):
|
||||||
|
version = "App/1.7"
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.version = "App/1.7"
|
|
||||||
urllib.FancyURLopener.__init__(self, *args)
|
urllib.FancyURLopener.__init__(self, *args)
|
||||||
|
|
||||||
urllib._urlopener = AppURLopener()
|
urllib._urlopener = AppURLopener()
|
||||||
|
@ -243,9 +243,9 @@ By default, the \class{URLopener} class sends a
|
||||||
\mailheader{User-Agent} header of \samp{urllib/\var{VVV}}, where
|
\mailheader{User-Agent} header of \samp{urllib/\var{VVV}}, where
|
||||||
\var{VVV} is the \module{urllib} version number. Applications can
|
\var{VVV} is the \module{urllib} version number. Applications can
|
||||||
define their own \mailheader{User-Agent} header by subclassing
|
define their own \mailheader{User-Agent} header by subclassing
|
||||||
\class{URLopener} or \class{FancyURLopener} and setting the instance
|
\class{URLopener} or \class{FancyURLopener} and setting the class
|
||||||
attribute \member{version} to an appropriate string value before the
|
attribute \member{version} to an appropriate string value in the
|
||||||
\method{open()} method is called.
|
subclass definition.
|
||||||
|
|
||||||
The optional \var{proxies} parameter should be a dictionary mapping
|
The optional \var{proxies} parameter should be a dictionary mapping
|
||||||
scheme names to proxy URLs, where an empty dictionary turns proxies
|
scheme names to proxy URLs, where an empty dictionary turns proxies
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue