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
1d99433a
Commit
1d99433a
authored
Dec 03, 2000
by
Martin v. Löwis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert Unicode strings to byte strings before passing them into specific
protocols. Closes bug #119822.
parent
57657bce
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
14 deletions
+25
-14
Lib/urllib.py
Lib/urllib.py
+25
-14
No files found.
Lib/urllib.py
View file @
1d99433a
...
@@ -26,9 +26,9 @@ import string
...
@@ -26,9 +26,9 @@ import string
import
socket
import
socket
import
os
import
os
import
sys
import
sys
import
types
__version__
=
'1.14'
# XXX This version is not always updated :-(
__version__
=
'1.13'
# XXX This version is not always updated :-(
MAXFTPCACHE
=
10
# Trim the ftp cache beyond this size
MAXFTPCACHE
=
10
# Trim the ftp cache beyond this size
...
@@ -136,23 +136,23 @@ class URLopener:
...
@@ -136,23 +136,23 @@ class URLopener:
# External interface
# External interface
def
open
(
self
,
fullurl
,
data
=
None
):
def
open
(
self
,
fullurl
,
data
=
None
):
"""Use URLopener().open(file) instead of open(file, 'r')."""
"""Use URLopener().open(file) instead of open(file, 'r')."""
fullurl
=
unwrap
(
fullurl
)
fullurl
=
unwrap
(
toBytes
(
fullurl
)
)
if
self
.
tempcache
and
self
.
tempcache
.
has_key
(
fullurl
):
if
self
.
tempcache
and
self
.
tempcache
.
has_key
(
fullurl
):
filename
,
headers
=
self
.
tempcache
[
fullurl
]
filename
,
headers
=
self
.
tempcache
[
fullurl
]
fp
=
open
(
filename
,
'rb'
)
fp
=
open
(
filename
,
'rb'
)
return
addinfourl
(
fp
,
headers
,
fullurl
)
return
addinfourl
(
fp
,
headers
,
fullurl
)
type
,
url
=
splittype
(
fullurl
)
url
type
,
url
=
splittype
(
fullurl
)
if
not
type
:
if
not
url
type
:
type
=
'file'
url
type
=
'file'
if
self
.
proxies
.
has_key
(
type
):
if
self
.
proxies
.
has_key
(
url
type
):
proxy
=
self
.
proxies
[
type
]
proxy
=
self
.
proxies
[
url
type
]
type
,
proxyhost
=
splittype
(
proxy
)
url
type
,
proxyhost
=
splittype
(
proxy
)
host
,
selector
=
splithost
(
proxyhost
)
host
,
selector
=
splithost
(
proxyhost
)
url
=
(
host
,
fullurl
)
# Signal special case to open_*()
url
=
(
host
,
fullurl
)
# Signal special case to open_*()
else
:
else
:
proxy
=
None
proxy
=
None
name
=
'open_'
+
type
name
=
'open_'
+
url
type
self
.
type
=
type
self
.
type
=
url
type
if
'-'
in
name
:
if
'-'
in
name
:
# replace - with _
# replace - with _
name
=
string
.
join
(
string
.
split
(
name
,
'-'
),
'_'
)
name
=
string
.
join
(
string
.
split
(
name
,
'-'
),
'_'
)
...
@@ -183,7 +183,7 @@ class URLopener:
...
@@ -183,7 +183,7 @@ class URLopener:
def
retrieve
(
self
,
url
,
filename
=
None
,
reporthook
=
None
,
data
=
None
):
def
retrieve
(
self
,
url
,
filename
=
None
,
reporthook
=
None
,
data
=
None
):
"""retrieve(url) returns (filename, None) for a local object
"""retrieve(url) returns (filename, None) for a local object
or (tempfilename, headers) for a remote object."""
or (tempfilename, headers) for a remote object."""
url
=
unwrap
(
url
)
url
=
unwrap
(
toBytes
(
url
)
)
if
self
.
tempcache
and
self
.
tempcache
.
has_key
(
url
):
if
self
.
tempcache
and
self
.
tempcache
.
has_key
(
url
):
return
self
.
tempcache
[
url
]
return
self
.
tempcache
[
url
]
type
,
url1
=
splittype
(
url
)
type
,
url1
=
splittype
(
url
)
...
@@ -238,7 +238,7 @@ class URLopener:
...
@@ -238,7 +238,7 @@ class URLopener:
"""Use HTTP protocol."""
"""Use HTTP protocol."""
import
httplib
import
httplib
user_passwd
=
None
user_passwd
=
None
if
type
(
url
)
is
type
(
""
)
:
if
type
(
url
)
is
type
s
.
StringType
:
host
,
selector
=
splithost
(
url
)
host
,
selector
=
splithost
(
url
)
if
host
:
if
host
:
user_passwd
,
host
=
splituser
(
host
)
user_passwd
,
host
=
splituser
(
host
)
...
@@ -313,7 +313,7 @@ class URLopener:
...
@@ -313,7 +313,7 @@ class URLopener:
"""Use HTTPS protocol."""
"""Use HTTPS protocol."""
import
httplib
import
httplib
user_passwd
=
None
user_passwd
=
None
if
type
(
url
)
i
s
type
(
""
)
:
if
type
(
url
)
i
n
types
.
StringTypes
:
host
,
selector
=
splithost
(
url
)
host
,
selector
=
splithost
(
url
)
if
host
:
if
host
:
user_passwd
,
host
=
splituser
(
host
)
user_passwd
,
host
=
splituser
(
host
)
...
@@ -852,6 +852,17 @@ def basejoin(base, url):
...
@@ -852,6 +852,17 @@ def basejoin(base, url):
# unquote('abc%20def') -> 'abc def'
# unquote('abc%20def') -> 'abc def'
# quote('abc def') -> 'abc%20def')
# quote('abc def') -> 'abc%20def')
def
toBytes
(
url
):
"""toBytes(u"URL") --> 'URL'."""
# Most URL schemes require ASCII. If that changes, the conversion
# can be relaxed
if
type
(
url
)
is
types
.
UnicodeType
:
try
:
url
=
url
.
encode
(
"ASCII"
)
except
UnicodeError
:
raise
UnicodeError
(
"URL "
+
repr
(
url
)
+
" contains non-ASCII characters"
)
return
url
def
unwrap
(
url
):
def
unwrap
(
url
):
"""unwrap('<URL:type://host/path>') --> 'type://host/path'."""
"""unwrap('<URL:type://host/path>') --> 'type://host/path'."""
url
=
string
.
strip
(
url
)
url
=
string
.
strip
(
url
)
...
...
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