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

Public Member Functions

def __init__
 
def init
 
def retrfile
 
def endtransfer
 
def close
 

Data Fields

 user
 
 passwd
 
 host
 
 port
 
 dirs
 
 busy
 
 ftp
 

Detailed Description

Class used by open_ftp() for cache of open FTP connections.

Definition at line 693 of file urllib.py.

Constructor & Destructor Documentation

def __init__ (   self,
  user,
  passwd,
  host,
  port,
  dirs 
)

Definition at line 696 of file urllib.py.

697  def __init__(self, user, passwd, host, port, dirs):
698  self.user = user
699  self.passwd = passwd
700  self.host = host
701  self.port = port
702  self.dirs = dirs
703  self.init()

Member Function Documentation

def close (   self)

Definition at line 759 of file urllib.py.

References ftpwrapper.endtransfer(), and urllib.ftperrors().

760  def close(self):
761  self.endtransfer()
762  try:
763  self.ftp.close()
764  except ftperrors():
765  pass
def endtransfer (   self)

Definition at line 750 of file urllib.py.

References ftpwrapper.busy, and urllib.ftperrors().

751  def endtransfer(self):
752  if not self.busy:
753  return
754  self.busy = 0
755  try:
756  self.ftp.voidresp()
757  except ftperrors():
758  pass
def init (   self)

Definition at line 704 of file urllib.py.

705  def init(self):
706  import ftplib
707  self.busy = 0
708  self.ftp = ftplib.FTP()
709  self.ftp.connect(self.host, self.port)
710  self.ftp.login(self.user, self.passwd)
711  for dir in self.dirs:
712  self.ftp.cwd(dir)
def retrfile (   self,
  file,
  type 
)

Definition at line 713 of file urllib.py.

References ftpwrapper.busy, ftpwrapper.endtransfer(), MyAI.init(), TrafficAI.init(), waitjump.init(), ai_escortpatrol.init(), Stats.init(), ftpwrapper.init(), and locale.str().

714  def retrfile(self, file, type):
715  import ftplib
716  self.endtransfer()
717  if type in ('d', 'D'): cmd = 'TYPE A'; isdir = 1
718  else: cmd = 'TYPE ' + type; isdir = 0
719  try:
720  self.ftp.voidcmd(cmd)
721  except ftplib.all_errors:
722  self.init()
723  self.ftp.voidcmd(cmd)
724  conn = None
725  if file and not isdir:
726  # Use nlst to see if the file exists at all
727  try:
728  self.ftp.nlst(file)
729  except ftplib.error_perm, reason:
730  raise IOError, ('ftp error', reason), sys.exc_info()[2]
731  # Restore the transfer mode!
732  self.ftp.voidcmd(cmd)
733  # Try to retrieve as a file
734  try:
735  cmd = 'RETR ' + file
736  conn = self.ftp.ntransfercmd(cmd)
737  except ftplib.error_perm, reason:
738  if str(reason)[:3] != '550':
739  raise IOError, ('ftp error', reason), sys.exc_info()[2]
740  if not conn:
741  # Set transfer mode to ASCII!
742  self.ftp.voidcmd('TYPE A')
743  # Try a directory listing
744  if file: cmd = 'LIST ' + file
745  else: cmd = 'LIST'
746  conn = self.ftp.ntransfercmd(cmd)
747  self.busy = 1
748  # Pass back both a suitably decorated object and a retrieval length
749  return (addclosehook(conn[0].makefile('rb'),
self.endtransfer), conn[1])

Field Documentation

busy

Definition at line 706 of file urllib.py.

dirs

Definition at line 701 of file urllib.py.

ftp

Definition at line 707 of file urllib.py.

host

Definition at line 699 of file urllib.py.

passwd

Definition at line 698 of file urllib.py.

port

Definition at line 700 of file urllib.py.

user

Definition at line 697 of file urllib.py.


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