Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
Netrc Class Reference

Public Member Functions

def __init__
 
def get_hosts
 
def get_account
 
def get_macros
 
def get_macro
 

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 655 of file ftplib.py.

Constructor & Destructor Documentation

def __init__ (   self,
  filename = None 
)

Definition at line 667 of file ftplib.py.

References Netrc.__defacct, Netrc.__defpasswd, Netrc.__defuser, Netrc.__hosts, Netrc.__macros, aifc.open(), and log_faction_ships.tuple.

668  def __init__(self, filename=None):
669  if not filename:
670  if os.environ.has_key("HOME"):
671  filename = os.path.join(os.environ["HOME"],
672  ".netrc")
673  else:
674  raise IOError, \
675  "specify file to load or set $HOME"
676  self.__hosts = {}
677  self.__macros = {}
678  fp = open(filename, "r")
679  in_macro = 0
680  while 1:
681  line = fp.readline()
682  if not line: break
683  if in_macro and line.strip():
684  macro_lines.append(line)
685  continue
686  elif in_macro:
687  self.__macros[macro_name] = tuple(macro_lines)
688  in_macro = 0
689  words = line.split()
690  host = user = passwd = acct = None
691  default = 0
692  i = 0
693  while i < len(words):
694  w1 = words[i]
695  if i+1 < len(words):
696  w2 = words[i + 1]
697  else:
698  w2 = None
699  if w1 == 'default':
700  default = 1
701  elif w1 == 'machine' and w2:
702  host = w2.lower()
703  i = i + 1
704  elif w1 == 'login' and w2:
705  user = w2
706  i = i + 1
707  elif w1 == 'password' and w2:
708  passwd = w2
709  i = i + 1
710  elif w1 == 'account' and w2:
711  acct = w2
712  i = i + 1
713  elif w1 == 'macdef' and w2:
714  macro_name = w2
715  macro_lines = []
716  in_macro = 1
717  break
718  i = i + 1
719  if default:
720  self.__defuser = user or self.__defuser
721  self.__defpasswd = passwd or self.__defpasswd
722  self.__defacct = acct or self.__defacct
723  if host:
724  if self.__hosts.has_key(host):
725  ouser, opasswd, oacct = \
726  self.__hosts[host]
727  user = user or ouser
728  passwd = passwd or opasswd
729  acct = acct or oacct
730  self.__hosts[host] = user, passwd, acct
731  fp.close()

Member Function Documentation

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.

Definition at line 736 of file ftplib.py.

References Netrc.__defacct, Netrc.__defpasswd, Netrc.__defuser, and Netrc.__hosts.

737  def get_account(self, host):
738  """Returns login information for the named host.
739 
740  The return value is a triple containing userid,
741  password, and the accounting field.
742 
743  """
744  host = host.lower()
745  user = passwd = acct = None
746  if self.__hosts.has_key(host):
747  user, passwd, acct = self.__hosts[host]
748  user = user or self.__defuser
749  passwd = passwd or self.__defpasswd
750  acct = acct or self.__defacct
751  return user, passwd, acct
def get_hosts (   self)
Return a list of hosts mentioned in the .netrc file.

Definition at line 732 of file ftplib.py.

733  def get_hosts(self):
734  """Return a list of hosts mentioned in the .netrc file."""
735  return self.__hosts.keys()
def get_macro (   self,
  macro 
)
Return a sequence of lines which define a named macro.

Definition at line 756 of file ftplib.py.

References Netrc.__macros.

757  def get_macro(self, macro):
758  """Return a sequence of lines which define a named macro."""
759  return self.__macros[macro]
760 
761 
def get_macros (   self)
Return a list of all defined macro names.

Definition at line 752 of file ftplib.py.

753  def get_macros(self):
754  """Return a list of all defined macro names."""
755  return self.__macros.keys()

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