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
56d1e3a5
Kaydet (Commit)
56d1e3a5
authored
Mar 14, 1997
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Added Fred Drake's netrc parser class.
üst
18aef3c1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
100 additions
and
0 deletions
+100
-0
ftplib.py
Lib/ftplib.py
+100
-0
No files found.
Lib/ftplib.py
Dosyayı görüntüle @
56d1e3a5
...
...
@@ -542,6 +542,106 @@ def ftpcp(source, sourcename, target, targetname = '', type = 'I'):
source
.
voidresp
()
target
.
voidresp
()
NoFileSpecified
=
"netrc.NoFileSpecified"
class
Netrc
:
__defuser
=
None
__defpasswd
=
None
__defacct
=
None
def
__init__
(
self
,
filename
=
None
):
if
not
filename
:
if
os
.
environ
.
has_key
(
"HOME"
):
filename
=
os
.
path
.
join
(
os
.
environ
[
"HOME"
],
".netrc"
)
else
:
raise
NoFileSpecified
,
"specify file to load or set $HOME"
self
.
__hosts
=
{}
self
.
__macros
=
{}
fp
=
open
(
filename
,
"r"
)
in_macro
=
0
while
1
:
line
=
fp
.
readline
()
if
not
line
:
break
if
in_macro
and
string
.
strip
(
line
):
macro_lines
.
append
(
line
)
continue
elif
in_macro
:
self
.
__macros
[
macro_name
]
=
tuple
(
macro_lines
)
in_macro
=
0
words
=
string
.
split
(
line
)
host
=
user
=
passwd
=
acct
=
None
default
=
0
i
=
0
while
i
<
len
(
words
):
w1
=
words
[
i
]
if
i
+
1
<
len
(
words
):
w2
=
words
[
i
+
1
]
else
:
w2
=
None
if
w1
==
'default'
:
default
=
1
elif
w1
==
'machine'
and
w2
:
host
=
string
.
lower
(
w2
)
i
=
i
+
1
elif
w1
==
'login'
and
w2
:
user
=
w2
i
=
i
+
1
elif
w1
==
'password'
and
w2
:
passwd
=
w2
i
=
i
+
1
elif
w1
==
'account'
and
w2
:
acct
=
w2
i
=
i
+
1
elif
w1
==
'macdef'
and
w2
:
macro_name
=
w2
macro_lines
=
[]
in_macro
=
1
break
i
=
i
+
1
if
default
:
self
.
__defuser
=
user
or
self
.
__defuser
self
.
__defpasswd
=
passwd
or
self
.
__defpasswd
self
.
__defacct
=
acct
or
self
.
__defacct
if
host
:
if
self
.
__hosts
.
has_key
(
host
):
ouser
,
opasswd
,
oacct
=
self
.
__hosts
[
host
]
user
=
user
or
ouser
passwd
=
passwd
or
opasswd
acct
=
acct
or
oacct
self
.
__hosts
[
host
]
=
user
,
passwd
,
acct
fp
.
close
()
def
get_hosts
(
self
):
"""Return a list of hosts mentioned in the .netrc file."""
return
self
.
__hosts
.
keys
()
def
get_account
(
self
,
host
):
"""Returns login information for the named host.
The return value is a triple containing userid, password, and the
accounting field.
"""
host
=
string
.
lower
(
host
)
user
,
passwd
,
acct
=
None
,
None
,
None
if
self
.
__hosts
.
has_key
(
host
):
user
,
passwd
,
acct
=
self
.
__hosts
[
host
]
user
=
user
or
self
.
__defuser
passwd
=
passwd
or
self
.
__defpasswd
acct
=
acct
or
self
.
__defacct
return
user
,
passwd
,
acct
def
get_macros
(
self
):
"""Return a list of all defined macro names."""
return
self
.
__macros
.
keys
()
def
get_macro
(
self
,
macro
):
"""Return a sequence of lines which define a named macro."""
return
self
.
__macros
[
macro
]
def
test
():
'''Test program.
Usage: ftp [-d] host [-l[dir]] [-d[dir]] [-p] [file] ...'''
...
...
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