Back to index

python3.2  3.2.2
Public Member Functions | Private Attributes | Static Private Attributes
ftplib.Netrc Class Reference

List of all members.

Public Member Functions

def __init__
def get_hosts
def get_account
def get_macros
def get_macro

Private Attributes

 __hosts
 __macros

Static Private Attributes

 __defuser = None
 __defpasswd = None
 __defacct = None

Detailed Description

Class to parse & provide access to 'netrc' format files.

See the netrc(4) man page for information on the file format.

WARNING: This class is obsolete -- use module netrc instead.

Definition at line 919 of file ftplib.py.


Constructor & Destructor Documentation

def ftplib.Netrc.__init__ (   self,
  filename = None 
)

Definition at line 931 of file ftplib.py.

00931 
00932     def __init__(self, filename=None):
00933         if filename is None:
00934             if "HOME" in os.environ:
00935                 filename = os.path.join(os.environ["HOME"],
00936                                         ".netrc")
00937             else:
00938                 raise IOError("specify file to load or set $HOME")
00939         self.__hosts = {}
00940         self.__macros = {}
00941         fp = open(filename, "r")
00942         in_macro = 0
00943         while 1:
00944             line = fp.readline()
00945             if not line: break
00946             if in_macro and line.strip():
00947                 macro_lines.append(line)
00948                 continue
00949             elif in_macro:
00950                 self.__macros[macro_name] = tuple(macro_lines)
00951                 in_macro = 0
00952             words = line.split()
00953             host = user = passwd = acct = None
00954             default = 0
00955             i = 0
00956             while i < len(words):
00957                 w1 = words[i]
00958                 if i+1 < len(words):
00959                     w2 = words[i + 1]
00960                 else:
00961                     w2 = None
00962                 if w1 == 'default':
00963                     default = 1
00964                 elif w1 == 'machine' and w2:
00965                     host = w2.lower()
00966                     i = i + 1
00967                 elif w1 == 'login' and w2:
00968                     user = w2
00969                     i = i + 1
00970                 elif w1 == 'password' and w2:
00971                     passwd = w2
00972                     i = i + 1
00973                 elif w1 == 'account' and w2:
00974                     acct = w2
00975                     i = i + 1
00976                 elif w1 == 'macdef' and w2:
00977                     macro_name = w2
00978                     macro_lines = []
00979                     in_macro = 1
00980                     break
00981                 i = i + 1
00982             if default:
00983                 self.__defuser = user or self.__defuser
00984                 self.__defpasswd = passwd or self.__defpasswd
00985                 self.__defacct = acct or self.__defacct
00986             if host:
00987                 if host in self.__hosts:
00988                     ouser, opasswd, oacct = \
00989                            self.__hosts[host]
00990                     user = user or ouser
00991                     passwd = passwd or opasswd
00992                     acct = acct or oacct
00993                 self.__hosts[host] = user, passwd, acct
00994         fp.close()

Here is the caller graph for this function:


Member Function Documentation

def ftplib.Netrc.get_account (   self,
  host 
)
Returns login information for the named host.

The return value is a triple containing userid,
password, and the accounting field.

Definition at line 999 of file ftplib.py.

00999 
01000     def get_account(self, host):
01001         """Returns login information for the named host.
01002 
01003         The return value is a triple containing userid,
01004         password, and the accounting field.
01005 
01006         """
01007         host = host.lower()
01008         user = passwd = acct = None
01009         if host in self.__hosts:
01010             user, passwd, acct = self.__hosts[host]
01011         user = user or self.__defuser
01012         passwd = passwd or self.__defpasswd
01013         acct = acct or self.__defacct
01014         return user, passwd, acct

def ftplib.Netrc.get_hosts (   self)
Return a list of hosts mentioned in the .netrc file.

Definition at line 995 of file ftplib.py.

00995 
00996     def get_hosts(self):
00997         """Return a list of hosts mentioned in the .netrc file."""
00998         return self.__hosts.keys()

def ftplib.Netrc.get_macro (   self,
  macro 
)
Return a sequence of lines which define a named macro.

Definition at line 1019 of file ftplib.py.

01019 
01020     def get_macro(self, macro):
01021         """Return a sequence of lines which define a named macro."""
01022         return self.__macros[macro]
01023 
01024 

def ftplib.Netrc.get_macros (   self)
Return a list of all defined macro names.

Definition at line 1015 of file ftplib.py.

01015 
01016     def get_macros(self):
01017         """Return a list of all defined macro names."""
01018         return self.__macros.keys()


Member Data Documentation

ftplib.Netrc.__defacct = None [static, private]

Definition at line 929 of file ftplib.py.

ftplib.Netrc.__defpasswd = None [static, private]

Definition at line 928 of file ftplib.py.

ftplib.Netrc.__defuser = None [static, private]

Definition at line 927 of file ftplib.py.

Definition at line 938 of file ftplib.py.

Definition at line 939 of file ftplib.py.


The documentation for this class was generated from the following file: