Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
2 | <html> | |
3 | <head> | |
4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> | |
5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> | |
6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> | |
7 | <link rel="first" href="lib.html" title='Python Library Reference' /> | |
8 | <link rel='contents' href='contents.html' title="Contents" /> | |
9 | <link rel='index' href='genindex.html' title='Index' /> | |
10 | <link rel='last' href='about.html' title='About this document...' /> | |
11 | <link rel='help' href='about.html' title='About this document...' /> | |
12 | <link rel="next" href="node483.html" /> | |
13 | <link rel="prev" href="module-urllib.html" /> | |
14 | <link rel="parent" href="module-urllib.html" /> | |
15 | <link rel="next" href="node483.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>11.4.1 URLopener Objects </title> | |
18 | </head> | |
19 | <body> | |
20 | <DIV CLASS="navigation"> | |
21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
23 | <tr> | |
24 | <td class='online-navigation'><a rel="prev" title="11.4 urllib " | |
25 | href="module-urllib.html"><img src='../icons/previous.png' | |
26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
27 | <td class='online-navigation'><a rel="parent" title="11.4 urllib " | |
28 | href="module-urllib.html"><img src='../icons/up.png' | |
29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
30 | <td class='online-navigation'><a rel="next" title="11.4.2 Examples" | |
31 | href="node483.html"><img src='../icons/next.png' | |
32 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
33 | <td align="center" width="100%">Python Library Reference</td> | |
34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
35 | href="contents.html"><img src='../icons/contents.png' | |
36 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
38 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
39 | <td class='online-navigation'><a rel="index" title="Index" | |
40 | href="genindex.html"><img src='../icons/index.png' | |
41 | border='0' height='32' alt='Index' width='32' /></A></td> | |
42 | </tr></table> | |
43 | <div class='online-navigation'> | |
44 | <b class="navlabel">Previous:</b> | |
45 | <a class="sectref" rel="prev" href="module-urllib.html">11.4 urllib </A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="module-urllib.html">11.4 urllib </A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="node483.html">11.4.2 Examples</A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H2><A NAME="SECTION0013410000000000000000"></A><A NAME="urlopener-objs"></A> | |
56 | <BR> | |
57 | 11.4.1 URLopener Objects | |
58 | </H2> | |
59 | ||
60 | <P> | |
61 | <tt class="class">URLopener</tt> and <tt class="class">FancyURLopener</tt> objects have the | |
62 | following attributes. | |
63 | ||
64 | <P> | |
65 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
66 | <td><nobr><b><tt id='l2h-3212' xml:id='l2h-3212' class="method">open</tt></b>(</nobr></td> | |
67 | <td><var>fullurl</var><big>[</big><var>, data</var><big>]</big><var></var>)</td></tr></table></dt> | |
68 | <dd> | |
69 | Open <var>fullurl</var> using the appropriate protocol. This method sets | |
70 | up cache and proxy information, then calls the appropriate open method with | |
71 | its input arguments. If the scheme is not recognized, | |
72 | <tt class="method">open_unknown()</tt> is called. The <var>data</var> argument | |
73 | has the same meaning as the <var>data</var> argument of <tt class="function">urlopen()</tt>. | |
74 | </dl> | |
75 | ||
76 | <P> | |
77 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
78 | <td><nobr><b><tt id='l2h-3213' xml:id='l2h-3213' class="method">open_unknown</tt></b>(</nobr></td> | |
79 | <td><var>fullurl</var><big>[</big><var>, data</var><big>]</big><var></var>)</td></tr></table></dt> | |
80 | <dd> | |
81 | Overridable interface to open unknown URL types. | |
82 | </dl> | |
83 | ||
84 | <P> | |
85 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
86 | <td><nobr><b><tt id='l2h-3214' xml:id='l2h-3214' class="method">retrieve</tt></b>(</nobr></td> | |
87 | <td><var>url</var><big>[</big><var>, | |
88 | filename</var><big>[</big><var>, | |
89 | reporthook</var><big>[</big><var>, data</var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt> | |
90 | <dd> | |
91 | Retrieves the contents of <var>url</var> and places it in <var>filename</var>. The | |
92 | return value is a tuple consisting of a local filename and either a | |
93 | <tt class="class">mimetools.Message</tt> object containing the response headers (for remote | |
94 | URLs) or <code>None</code> (for local URLs). The caller must then open and read the | |
95 | contents of <var>filename</var>. If <var>filename</var> is not given and the URL | |
96 | refers to a local file, the input filename is returned. If the URL is | |
97 | non-local and <var>filename</var> is not given, the filename is the output of | |
98 | <tt class="function">tempfile.mktemp()</tt> with a suffix that matches the suffix of the last | |
99 | path component of the input URL. If <var>reporthook</var> is given, it must be | |
100 | a function accepting three numeric parameters. It will be called after each | |
101 | chunk of data is read from the network. <var>reporthook</var> is ignored for | |
102 | local URLs. | |
103 | ||
104 | <P> | |
105 | If the <var>url</var> uses the <span class="file">http:</span> scheme identifier, the optional | |
106 | <var>data</var> argument may be given to specify a <code>POST</code> request | |
107 | (normally the request type is <code>GET</code>). The <var>data</var> argument | |
108 | must in standard <span class="mimetype">application/x-www-form-urlencoded</span> format; | |
109 | see the <tt class="function">urlencode()</tt> function below. | |
110 | </dl> | |
111 | ||
112 | <P> | |
113 | <dl><dt><b><tt id='l2h-3215' xml:id='l2h-3215' class="member">version</tt></b></dt> | |
114 | <dd> | |
115 | Variable that specifies the user agent of the opener object. To get | |
116 | <tt class="module"><a href="module-urllib.html">urllib</a></tt> to tell servers that it is a particular user agent, | |
117 | set this in a subclass as a class variable or in the constructor | |
118 | before calling the base constructor. | |
119 | </dl> | |
120 | ||
121 | <P> | |
122 | The <tt class="class">FancyURLopener</tt> class offers one additional method that | |
123 | should be overloaded to provide the appropriate behavior: | |
124 | ||
125 | <P> | |
126 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
127 | <td><nobr><b><tt id='l2h-3216' xml:id='l2h-3216' class="method">prompt_user_passwd</tt></b>(</nobr></td> | |
128 | <td><var>host, realm</var>)</td></tr></table></dt> | |
129 | <dd> | |
130 | Return information needed to authenticate the user at the given host | |
131 | in the specified security realm. The return value should be a tuple, | |
132 | <code>(<var>user</var>, <var>password</var>)</code>, which can be used for basic | |
133 | authentication. | |
134 | ||
135 | <P> | |
136 | The implementation prompts for this information on the terminal; an | |
137 | application should override this method to use an appropriate | |
138 | interaction model in the local environment. | |
139 | </dl> | |
140 | ||
141 | <P> | |
142 | ||
143 | <DIV CLASS="navigation"> | |
144 | <div class='online-navigation'> | |
145 | <p></p><hr /> | |
146 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
147 | <tr> | |
148 | <td class='online-navigation'><a rel="prev" title="11.4 urllib " | |
149 | href="module-urllib.html"><img src='../icons/previous.png' | |
150 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
151 | <td class='online-navigation'><a rel="parent" title="11.4 urllib " | |
152 | href="module-urllib.html"><img src='../icons/up.png' | |
153 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
154 | <td class='online-navigation'><a rel="next" title="11.4.2 Examples" | |
155 | href="node483.html"><img src='../icons/next.png' | |
156 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
157 | <td align="center" width="100%">Python Library Reference</td> | |
158 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
159 | href="contents.html"><img src='../icons/contents.png' | |
160 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
161 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
162 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
163 | <td class='online-navigation'><a rel="index" title="Index" | |
164 | href="genindex.html"><img src='../icons/index.png' | |
165 | border='0' height='32' alt='Index' width='32' /></A></td> | |
166 | </tr></table> | |
167 | <div class='online-navigation'> | |
168 | <b class="navlabel">Previous:</b> | |
169 | <a class="sectref" rel="prev" href="module-urllib.html">11.4 urllib </A> | |
170 | <b class="navlabel">Up:</b> | |
171 | <a class="sectref" rel="parent" href="module-urllib.html">11.4 urllib </A> | |
172 | <b class="navlabel">Next:</b> | |
173 | <a class="sectref" rel="next" href="node483.html">11.4.2 Examples</A> | |
174 | </div> | |
175 | </div> | |
176 | <hr /> | |
177 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
178 | </DIV> | |
179 | <!--End of Navigation Panel--> | |
180 | <ADDRESS> | |
181 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
182 | </ADDRESS> | |
183 | </BODY> | |
184 | </HTML> |