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
e8ea21b0
Kaydet (Commit)
e8ea21b0
authored
Ara 21, 1995
tarafından
Jack Jansen
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Added pathname2url and url2pathname methods (only correct for unix and
mac, so far)
üst
b6789751
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
7 deletions
+32
-7
urllib.py
Lib/urllib.py
+32
-7
No files found.
Lib/urllib.py
Dosyayı görüntüle @
e8ea21b0
...
...
@@ -20,22 +20,47 @@ import regex
import
os
__version__
=
'1.2'
__version__
=
'1.2'
# XXXX Should I update this number? -- jack
# Helper for non-unix systems
if
os
.
name
==
'mac'
:
def
_fixpath
(
pathname
):
def
url2pathname
(
pathname
):
"Convert /-delimited pathname to mac pathname"
#
# XXXX The .. handling should be fixed...
#
tp
=
splittype
(
pathname
)[
0
]
if
tp
and
tp
<>
'file'
:
raise
RuntimeError
,
'Cannot convert non-local URL to pathname'
components
=
string
.
split
(
pathname
,
'/'
)
if
'..'
in
components
or
'.'
in
components
or
''
in
components
[
1
:
-
1
]:
raise
RuntimeError
,
'Cannot convert URL containing ., .. or // to pathname'
if
not
components
[
0
]:
# Absolute unix path, don't start with colon
return
string
.
join
(
components
[
1
:],
':'
)
else
:
# relative unix path, start with colon
return
':'
+
string
.
join
(
components
,
':'
)
def
pathname2url
(
pathname
):
"convert mac pathname to /-delimited pathname"
if
'/'
in
pathname
:
raise
RuntimeError
,
"Cannot convert pathname containing slashes"
components
=
string
.
split
(
pathname
,
':'
)
if
''
in
components
[
1
:
-
1
]:
raise
RuntimeError
,
"Cannot convert pathname containing ::"
# Truncate names longer than 31 bytes
components
=
map
(
lambda
x
:
x
[:
31
],
components
)
if
os
.
path
.
isabs
(
pathname
):
return
'/'
+
string
.
join
(
components
,
'/'
)
else
:
return
string
.
join
(
components
,
'/'
)
else
:
def
_fixpath
(
pathname
):
def
url2pathname
(
pathname
):
return
pathname
def
pathname2url
(
pathname
):
return
pathname
# This really consists of two pieces:
# (1) a class which handles opening of all sorts of URLs
...
...
@@ -144,7 +169,7 @@ class URLopener:
try
:
fp
=
self
.
open_local_file
(
url1
)
del
fp
return
splithost
(
url1
)[
1
]
,
None
return
url2pathname
(
splithost
(
url1
)[
1
])
,
None
except
IOError
,
msg
:
pass
fp
=
self
.
open
(
url
)
...
...
@@ -238,12 +263,12 @@ class URLopener:
# Use local file
def
open_local_file
(
self
,
url
):
host
,
file
=
splithost
(
url
)
if
not
host
:
return
addinfo
(
open
(
_fixpath
(
file
),
'r'
),
noheaders
())
if
not
host
:
return
addinfo
(
open
(
url2pathname
(
file
),
'r'
),
noheaders
())
host
,
port
=
splitport
(
host
)
if
not
port
and
socket
.
gethostbyname
(
host
)
in
(
localhost
(),
thishost
()):
file
=
unquote
(
file
)
return
addinfo
(
open
(
_fixpath
(
file
),
'r'
),
noheaders
())
return
addinfo
(
open
(
url2pathname
(
file
),
'r'
),
noheaders
())
raise
IOError
,
(
'local file error'
,
'not on local host'
)
# Use FTP protocol
...
...
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