Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
9d6da3e2
Commit
9d6da3e2
authored
May 17, 2006
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Delay-import some large modules to speed up urllib2 import.
(fixes #1484793).
parent
e3a25838
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
8 deletions
+28
-8
Lib/urllib2.py
Lib/urllib2.py
+28
-8
No files found.
Lib/urllib2.py
View file @
9d6da3e2
...
@@ -85,11 +85,8 @@ f = urllib2.urlopen('http://www.python.org/')
...
@@ -85,11 +85,8 @@ f = urllib2.urlopen('http://www.python.org/')
# abstract factory for opener
# abstract factory for opener
import
base64
import
base64
import
ftplib
import
httplib
import
inspect
import
hashlib
import
hashlib
import
mimetypes
import
httplib
import
mimetools
import
mimetools
import
os
import
os
import
posixpath
import
posixpath
...
@@ -100,7 +97,6 @@ import sys
...
@@ -100,7 +97,6 @@ import sys
import
time
import
time
import
urlparse
import
urlparse
import
bisect
import
bisect
import
cookielib
try
:
try
:
from
cStringIO
import
StringIO
from
cStringIO
import
StringIO
...
@@ -168,6 +164,23 @@ class HTTPError(URLError, addinfourl):
...
@@ -168,6 +164,23 @@ class HTTPError(URLError, addinfourl):
class
GopherError
(
URLError
):
class
GopherError
(
URLError
):
pass
pass
# copied from cookielib.py
cut_port_re
=
re
.
compile
(
r":\
d+$
")
def request_host(request):
"""Return request-host, as defined by RFC 2965.
Variation from RFC: returned value is lowercased, for convenient
comparison.
"""
url = request.get_full_url()
host = urlparse.urlparse(url)[1]
if host == "":
host = request.get_header("
Host
", "")
# remove port, if present
host = cut_port_re.sub("", host, 1)
return host.lower()
class Request:
class Request:
...
@@ -185,7 +198,7 @@ class Request:
...
@@ -185,7 +198,7 @@ class Request:
self.add_header(key, value)
self.add_header(key, value)
self.unredirected_hdrs = {}
self.unredirected_hdrs = {}
if origin_req_host is None:
if origin_req_host is None:
origin_req_host
=
cookielib
.
request_host
(
self
)
origin_req_host = request_host(self)
self.origin_req_host = origin_req_host
self.origin_req_host = origin_req_host
self.unverifiable = unverifiable
self.unverifiable = unverifiable
...
@@ -413,6 +426,9 @@ def build_opener(*handlers):
...
@@ -413,6 +426,9 @@ def build_opener(*handlers):
If any of the handlers passed as arguments are subclasses of the
If any of the handlers passed as arguments are subclasses of the
default handlers, the default handlers will not be used.
default handlers, the default handlers will not be used.
"""
"""
import types
def isclass(obj):
return isinstance(obj, types.ClassType) or hasattr(obj, "
__bases__
")
opener = OpenerDirector()
opener = OpenerDirector()
default_classes = [ProxyHandler, UnknownHandler, HTTPHandler,
default_classes = [ProxyHandler, UnknownHandler, HTTPHandler,
...
@@ -423,7 +439,7 @@ def build_opener(*handlers):
...
@@ -423,7 +439,7 @@ def build_opener(*handlers):
skip = []
skip = []
for klass in default_classes:
for klass in default_classes:
for check in handlers:
for check in handlers:
if
i
nspect
.
i
sclass
(
check
):
if isclass(check):
if issubclass(check, klass):
if issubclass(check, klass):
skip.append(klass)
skip.append(klass)
elif isinstance(check, klass):
elif isinstance(check, klass):
...
@@ -435,7 +451,7 @@ def build_opener(*handlers):
...
@@ -435,7 +451,7 @@ def build_opener(*handlers):
opener.add_handler(klass())
opener.add_handler(klass())
for h in handlers:
for h in handlers:
if
i
nspect
.
i
sclass
(
h
):
if isclass(h):
h = h()
h = h()
opener.add_handler(h)
opener.add_handler(h)
return opener
return opener
...
@@ -1071,6 +1087,7 @@ if hasattr(httplib, 'HTTPS'):
...
@@ -1071,6 +1087,7 @@ if hasattr(httplib, 'HTTPS'):
class
HTTPCookieProcessor
(
BaseHandler
):
class
HTTPCookieProcessor
(
BaseHandler
):
def
__init__
(
self
,
cookiejar
=
None
):
def
__init__
(
self
,
cookiejar
=
None
):
import
cookielib
if
cookiejar
is
None
:
if
cookiejar
is
None
:
cookiejar
=
cookielib
.
CookieJar
()
cookiejar
=
cookielib
.
CookieJar
()
self
.
cookiejar
=
cookiejar
self
.
cookiejar
=
cookiejar
...
@@ -1168,6 +1185,7 @@ class FileHandler(BaseHandler):
...
@@ -1168,6 +1185,7 @@ class FileHandler(BaseHandler):
# not entirely sure what the rules are here
# not entirely sure what the rules are here
def
open_local_file
(
self
,
req
):
def
open_local_file
(
self
,
req
):
import
email.Utils
import
email.Utils
import
mimetypes
host
=
req
.
get_host
()
host
=
req
.
get_host
()
file
=
req
.
get_selector
()
file
=
req
.
get_selector
()
localfile
=
url2pathname
(
file
)
localfile
=
url2pathname
(
file
)
...
@@ -1188,6 +1206,8 @@ class FileHandler(BaseHandler):
...
@@ -1188,6 +1206,8 @@ class FileHandler(BaseHandler):
class
FTPHandler
(
BaseHandler
):
class
FTPHandler
(
BaseHandler
):
def
ftp_open
(
self
,
req
):
def
ftp_open
(
self
,
req
):
import
ftplib
import
mimetypes
host
=
req
.
get_host
()
host
=
req
.
get_host
()
if
not
host
:
if
not
host
:
raise
IOError
,
(
'ftp error'
,
'no host given'
)
raise
IOError
,
(
'ftp error'
,
'no host given'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment