Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
7e7ca0ba
Kaydet (Commit)
7e7ca0ba
authored
Mar 26, 1998
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
A few lines were indented using spaces instead of tabs -- fix them.
üst
8ca84206
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
64 deletions
+65
-64
urllib.py
Lib/urllib.py
+65
-64
No files found.
Lib/urllib.py
Dosyayı görüntüle @
7e7ca0ba
...
@@ -34,7 +34,7 @@ MAXFTPCACHE = 10 # Trim the ftp cache beyond this size
...
@@ -34,7 +34,7 @@ MAXFTPCACHE = 10 # Trim the ftp cache beyond this size
# Helper for non-unix systems
# Helper for non-unix systems
if
os
.
name
==
'mac'
:
if
os
.
name
==
'mac'
:
from
macurl2path
import
url2pathname
,
pathname2url
from
macurl2path
import
url2pathname
,
pathname2url
elif
os
.
name
==
'nt'
:
elif
os
.
name
==
'nt'
:
from
nturl2path
import
url2pathname
,
pathname2url
from
nturl2path
import
url2pathname
,
pathname2url
else
:
else
:
def
url2pathname
(
pathname
):
def
url2pathname
(
pathname
):
...
@@ -64,9 +64,9 @@ def urlretrieve(url, filename=None):
...
@@ -64,9 +64,9 @@ def urlretrieve(url, filename=None):
if
not
_urlopener
:
if
not
_urlopener
:
_urlopener
=
FancyURLopener
()
_urlopener
=
FancyURLopener
()
if
filename
:
if
filename
:
return
_urlopener
.
retrieve
(
url
,
filename
)
return
_urlopener
.
retrieve
(
url
,
filename
)
else
:
else
:
return
_urlopener
.
retrieve
(
url
)
return
_urlopener
.
retrieve
(
url
)
def
urlcleanup
():
def
urlcleanup
():
if
_urlopener
:
if
_urlopener
:
_urlopener
.
cleanup
()
_urlopener
.
cleanup
()
...
@@ -123,7 +123,7 @@ class URLopener:
...
@@ -123,7 +123,7 @@ class URLopener:
pass
pass
del
self
.
__tempfiles
[:]
del
self
.
__tempfiles
[:]
if
self
.
tempcache
:
if
self
.
tempcache
:
self
.
tempcache
.
clear
()
self
.
tempcache
.
clear
()
# Add a header to be used by the HTTP interface only
# Add a header to be used by the HTTP interface only
# e.g. u.addheader('Accept', 'sound/basic')
# e.g. u.addheader('Accept', 'sound/basic')
...
@@ -147,7 +147,7 @@ class URLopener:
...
@@ -147,7 +147,7 @@ class URLopener:
url
=
(
host
,
fullurl
)
# Signal special case to open_*()
url
=
(
host
,
fullurl
)
# Signal special case to open_*()
name
=
'open_'
+
type
name
=
'open_'
+
type
if
'-'
in
name
:
if
'-'
in
name
:
# replace - with _
# replace - with _
name
=
string
.
join
(
string
.
split
(
name
,
'-'
),
'_'
)
name
=
string
.
join
(
string
.
split
(
name
,
'-'
),
'_'
)
if
not
hasattr
(
self
,
name
):
if
not
hasattr
(
self
,
name
):
if
data
is
None
:
if
data
is
None
:
...
@@ -185,9 +185,9 @@ class URLopener:
...
@@ -185,9 +185,9 @@ class URLopener:
fp
=
self
.
open
(
url
)
fp
=
self
.
open
(
url
)
headers
=
fp
.
info
()
headers
=
fp
.
info
()
if
not
filename
:
if
not
filename
:
import
tempfile
import
tempfile
filename
=
tempfile
.
mktemp
()
filename
=
tempfile
.
mktemp
()
self
.
__tempfiles
.
append
(
filename
)
self
.
__tempfiles
.
append
(
filename
)
result
=
filename
,
headers
result
=
filename
,
headers
if
self
.
tempcache
is
not
None
:
if
self
.
tempcache
is
not
None
:
self
.
tempcache
[
url
]
=
result
self
.
tempcache
[
url
]
=
result
...
@@ -217,13 +217,14 @@ class URLopener:
...
@@ -217,13 +217,14 @@ class URLopener:
urltype
,
rest
=
splittype
(
selector
)
urltype
,
rest
=
splittype
(
selector
)
user_passwd
=
None
user_passwd
=
None
if
string
.
lower
(
urltype
)
!=
'http'
:
if
string
.
lower
(
urltype
)
!=
'http'
:
realhost
=
None
realhost
=
None
else
:
else
:
realhost
,
rest
=
splithost
(
rest
)
realhost
,
rest
=
splithost
(
rest
)
user_passwd
,
realhost
=
splituser
(
realhost
)
user_passwd
,
realhost
=
splituser
(
realhost
)
if
user_passwd
:
if
user_passwd
:
selector
=
"
%
s://
%
s
%
s"
%
(
urltype
,
selector
=
"
%
s://
%
s
%
s"
%
(
urltype
,
realhost
,
rest
)
realhost
,
rest
)
#print "proxy via http:", host, selector
#print "proxy via http:", host, selector
if
not
host
:
raise
IOError
,
(
'http error'
,
'no host given'
)
if
not
host
:
raise
IOError
,
(
'http error'
,
'no host given'
)
if
user_passwd
:
if
user_passwd
:
...
@@ -289,10 +290,10 @@ class URLopener:
...
@@ -289,10 +290,10 @@ class URLopener:
# Use local file or FTP depending on form of URL
# Use local file or FTP depending on form of URL
def
open_file
(
self
,
url
):
def
open_file
(
self
,
url
):
if
url
[:
2
]
==
'//'
and
url
[
2
:
3
]
!=
'/'
:
if
url
[:
2
]
==
'//'
and
url
[
2
:
3
]
!=
'/'
:
return
self
.
open_ftp
(
url
)
return
self
.
open_ftp
(
url
)
else
:
else
:
return
self
.
open_local_file
(
url
)
return
self
.
open_local_file
(
url
)
# Use local file
# Use local file
def
open_local_file
(
self
,
url
):
def
open_local_file
(
self
,
url
):
...
@@ -404,7 +405,7 @@ class FancyURLopener(URLopener):
...
@@ -404,7 +405,7 @@ class FancyURLopener(URLopener):
# Default error handling -- don't raise an exception
# Default error handling -- don't raise an exception
def
http_error_default
(
self
,
url
,
fp
,
errcode
,
errmsg
,
headers
):
def
http_error_default
(
self
,
url
,
fp
,
errcode
,
errmsg
,
headers
):
return
addinfourl
(
fp
,
headers
,
"http:"
+
url
)
return
addinfourl
(
fp
,
headers
,
"http:"
+
url
)
# Error 302 -- relocated (temporarily)
# Error 302 -- relocated (temporarily)
def
http_error_302
(
self
,
url
,
fp
,
errcode
,
errmsg
,
headers
):
def
http_error_302
(
self
,
url
,
fp
,
errcode
,
errmsg
,
headers
):
...
@@ -432,7 +433,7 @@ class FancyURLopener(URLopener):
...
@@ -432,7 +433,7 @@ class FancyURLopener(URLopener):
match
=
re
.
match
(
match
=
re
.
match
(
'[
\t
]*([^
\t
]+)[
\t
]+realm="([^"]*)"'
,
stuff
)
'[
\t
]*([^
\t
]+)[
\t
]+realm="([^"]*)"'
,
stuff
)
if
match
:
if
match
:
scheme
,
realm
=
match
.
groups
()
scheme
,
realm
=
match
.
groups
()
if
string
.
lower
(
scheme
)
==
'basic'
:
if
string
.
lower
(
scheme
)
==
'basic'
:
return
self
.
retry_http_basic_auth
(
return
self
.
retry_http_basic_auth
(
url
,
realm
)
url
,
realm
)
...
@@ -734,10 +735,10 @@ _typeprog = None
...
@@ -734,10 +735,10 @@ _typeprog = None
def
splittype
(
url
):
def
splittype
(
url
):
global
_typeprog
global
_typeprog
if
_typeprog
is
None
:
if
_typeprog
is
None
:
import
re
import
re
_typeprog
=
re
.
compile
(
'^([^/:]+):'
)
_typeprog
=
re
.
compile
(
'^([^/:]+):'
)
match
=
_typeprog
.
match
(
url
)
match
=
_typeprog
.
match
(
url
)
if
match
:
if
match
:
scheme
=
match
.
group
(
1
)
scheme
=
match
.
group
(
1
)
return
scheme
,
url
[
len
(
scheme
)
+
1
:]
return
scheme
,
url
[
len
(
scheme
)
+
1
:]
...
@@ -747,8 +748,8 @@ _hostprog = None
...
@@ -747,8 +748,8 @@ _hostprog = None
def
splithost
(
url
):
def
splithost
(
url
):
global
_hostprog
global
_hostprog
if
_hostprog
is
None
:
if
_hostprog
is
None
:
import
re
import
re
_hostprog
=
re
.
compile
(
'^//([^/]+)(.*)$'
)
_hostprog
=
re
.
compile
(
'^//([^/]+)(.*)$'
)
match
=
_hostprog
.
match
(
url
)
match
=
_hostprog
.
match
(
url
)
if
match
:
return
match
.
group
(
1
,
2
)
if
match
:
return
match
.
group
(
1
,
2
)
...
@@ -758,8 +759,8 @@ _userprog = None
...
@@ -758,8 +759,8 @@ _userprog = None
def
splituser
(
host
):
def
splituser
(
host
):
global
_userprog
global
_userprog
if
_userprog
is
None
:
if
_userprog
is
None
:
import
re
import
re
_userprog
=
re
.
compile
(
'^([^@]*)@(.*)$'
)
_userprog
=
re
.
compile
(
'^([^@]*)@(.*)$'
)
match
=
_userprog
.
match
(
host
)
match
=
_userprog
.
match
(
host
)
if
match
:
return
match
.
group
(
1
,
2
)
if
match
:
return
match
.
group
(
1
,
2
)
...
@@ -769,8 +770,8 @@ _passwdprog = None
...
@@ -769,8 +770,8 @@ _passwdprog = None
def
splitpasswd
(
user
):
def
splitpasswd
(
user
):
global
_passwdprog
global
_passwdprog
if
_passwdprog
is
None
:
if
_passwdprog
is
None
:
import
re
import
re
_passwdprog
=
re
.
compile
(
'^([^:]*):(.*)$'
)
_passwdprog
=
re
.
compile
(
'^([^:]*):(.*)$'
)
match
=
_passwdprog
.
match
(
user
)
match
=
_passwdprog
.
match
(
user
)
if
match
:
return
match
.
group
(
1
,
2
)
if
match
:
return
match
.
group
(
1
,
2
)
...
@@ -780,8 +781,8 @@ _portprog = None
...
@@ -780,8 +781,8 @@ _portprog = None
def
splitport
(
host
):
def
splitport
(
host
):
global
_portprog
global
_portprog
if
_portprog
is
None
:
if
_portprog
is
None
:
import
re
import
re
_portprog
=
re
.
compile
(
'^(.*):([0-9]+)$'
)
_portprog
=
re
.
compile
(
'^(.*):([0-9]+)$'
)
match
=
_portprog
.
match
(
host
)
match
=
_portprog
.
match
(
host
)
if
match
:
return
match
.
group
(
1
,
2
)
if
match
:
return
match
.
group
(
1
,
2
)
...
@@ -795,26 +796,26 @@ _nportprog = None
...
@@ -795,26 +796,26 @@ _nportprog = None
def
splitnport
(
host
,
defport
=-
1
):
def
splitnport
(
host
,
defport
=-
1
):
global
_nportprog
global
_nportprog
if
_nportprog
is
None
:
if
_nportprog
is
None
:
import
re
import
re
_nportprog
=
re
.
compile
(
'^(.*):(.*)$'
)
_nportprog
=
re
.
compile
(
'^(.*):(.*)$'
)
match
=
_nportprog
.
match
(
host
)
match
=
_nportprog
.
match
(
host
)
if
match
:
if
match
:
host
,
port
=
match
.
group
(
1
,
2
)
host
,
port
=
match
.
group
(
1
,
2
)
try
:
try
:
if
not
port
:
raise
string
.
atoi_error
,
"no digits"
if
not
port
:
raise
string
.
atoi_error
,
"no digits"
nport
=
string
.
atoi
(
port
)
nport
=
string
.
atoi
(
port
)
except
string
.
atoi_error
:
except
string
.
atoi_error
:
nport
=
None
nport
=
None
return
host
,
nport
return
host
,
nport
return
host
,
defport
return
host
,
defport
_queryprog
=
None
_queryprog
=
None
def
splitquery
(
url
):
def
splitquery
(
url
):
global
_queryprog
global
_queryprog
if
_queryprog
is
None
:
if
_queryprog
is
None
:
import
re
import
re
_queryprog
=
re
.
compile
(
'^(.*)
\
?([^?]*)$'
)
_queryprog
=
re
.
compile
(
'^(.*)
\
?([^?]*)$'
)
match
=
_queryprog
.
match
(
url
)
match
=
_queryprog
.
match
(
url
)
if
match
:
return
match
.
group
(
1
,
2
)
if
match
:
return
match
.
group
(
1
,
2
)
...
@@ -824,9 +825,9 @@ _tagprog = None
...
@@ -824,9 +825,9 @@ _tagprog = None
def
splittag
(
url
):
def
splittag
(
url
):
global
_tagprog
global
_tagprog
if
_tagprog
is
None
:
if
_tagprog
is
None
:
import
re
import
re
_tagprog
=
re
.
compile
(
'^(.*)#([^#]*)$'
)
_tagprog
=
re
.
compile
(
'^(.*)#([^#]*)$'
)
match
=
_tagprog
.
match
(
url
)
match
=
_tagprog
.
match
(
url
)
if
match
:
return
match
.
group
(
1
,
2
)
if
match
:
return
match
.
group
(
1
,
2
)
return
url
,
None
return
url
,
None
...
@@ -839,10 +840,10 @@ _valueprog = None
...
@@ -839,10 +840,10 @@ _valueprog = None
def
splitvalue
(
attr
):
def
splitvalue
(
attr
):
global
_valueprog
global
_valueprog
if
_valueprog
is
None
:
if
_valueprog
is
None
:
import
re
import
re
_valueprog
=
re
.
compile
(
'^([^=]*)=(.*)$'
)
_valueprog
=
re
.
compile
(
'^([^=]*)=(.*)$'
)
match
=
_valueprog
.
match
(
attr
)
match
=
_valueprog
.
match
(
attr
)
if
match
:
return
match
.
group
(
1
,
2
)
if
match
:
return
match
.
group
(
1
,
2
)
return
attr
,
None
return
attr
,
None
...
@@ -855,9 +856,9 @@ _quoteprog = None
...
@@ -855,9 +856,9 @@ _quoteprog = None
def
unquote
(
s
):
def
unquote
(
s
):
global
_quoteprog
global
_quoteprog
if
_quoteprog
is
None
:
if
_quoteprog
is
None
:
import
re
import
re
_quoteprog
=
re
.
compile
(
'
%
[0-9a-fA-F][0-9a-fA-F]'
)
_quoteprog
=
re
.
compile
(
'
%
[0-9a-fA-F][0-9a-fA-F]'
)
i
=
0
i
=
0
n
=
len
(
s
)
n
=
len
(
s
)
res
=
[]
res
=
[]
...
@@ -872,10 +873,10 @@ def unquote(s):
...
@@ -872,10 +873,10 @@ def unquote(s):
return
string
.
joinfields
(
res
,
''
)
return
string
.
joinfields
(
res
,
''
)
def
unquote_plus
(
s
):
def
unquote_plus
(
s
):
if
'+'
in
s
:
if
'+'
in
s
:
# replace '+' with ' '
# replace '+' with ' '
s
=
string
.
join
(
string
.
split
(
s
,
'+'
),
' '
)
s
=
string
.
join
(
string
.
split
(
s
,
'+'
),
' '
)
return
unquote
(
s
)
return
unquote
(
s
)
always_safe
=
string
.
letters
+
string
.
digits
+
'_,.-'
always_safe
=
string
.
letters
+
string
.
digits
+
'_,.-'
def
quote
(
s
,
safe
=
'/'
):
def
quote
(
s
,
safe
=
'/'
):
...
@@ -889,12 +890,12 @@ def quote(s, safe = '/'):
...
@@ -889,12 +890,12 @@ def quote(s, safe = '/'):
return
string
.
joinfields
(
res
,
''
)
return
string
.
joinfields
(
res
,
''
)
def
quote_plus
(
s
,
safe
=
'/'
):
def
quote_plus
(
s
,
safe
=
'/'
):
if
' '
in
s
:
if
' '
in
s
:
# replace ' ' with '+'
# replace ' ' with '+'
s
=
string
.
join
(
string
.
split
(
s
,
' '
),
'+'
)
s
=
string
.
join
(
string
.
split
(
s
,
' '
),
'+'
)
return
quote
(
s
,
safe
+
'+'
)
return
quote
(
s
,
safe
+
'+'
)
else
:
else
:
return
quote
(
s
,
safe
)
return
quote
(
s
,
safe
)
# Proxy handling
# Proxy handling
...
@@ -959,8 +960,8 @@ def test():
...
@@ -959,8 +960,8 @@ def test():
data
=
fp
.
read
()
data
=
fp
.
read
()
del
fp
del
fp
if
'
\r
'
in
data
:
if
'
\r
'
in
data
:
table
=
string
.
maketrans
(
""
,
""
)
table
=
string
.
maketrans
(
""
,
""
)
data
=
string
.
translate
(
data
,
table
,
"
\r
"
)
data
=
string
.
translate
(
data
,
table
,
"
\r
"
)
print
data
print
data
fn
,
h
=
None
,
None
fn
,
h
=
None
,
None
print
'-'
*
40
print
'-'
*
40
...
...
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