예제 #1
0
 def connect_ftp(self, user, passwd, host, port, dirs, timeout):
     try:
         fw = ftpwrapper(user, passwd, host, port, dirs, timeout)
     except TypeError:
         # Python < 2.6, no per-connection timeout support
         fw = ftpwrapper(user, passwd, host, port, dirs)
     ##        fw.ftp.set_debuglevel(1)
     return fw
예제 #2
0
    def connect_ftp(self, user, passwd, host, port, dirs, timeout):
        try:
            fw = ftpwrapper(user, passwd, host, port, dirs, timeout)
        except TypeError:
            # Python < 2.6, no per-connection timeout support
            fw = ftpwrapper(user, passwd, host, port, dirs)
##        fw.ftp.set_debuglevel(1)
        return fw
예제 #3
0
 def connect_ftp(self, user, passwd, host, port, dirs):
     key = user, host, port, '/'.join(dirs)
     if key in self.cache:
         self.timeout[key] = time.time() + self.delay
     else:
         self.cache[key] = ftpwrapper(user, passwd, host, port, dirs)
         self.timeout[key] = time.time() + self.delay
     self.check_cache()
     return self.cache[key]
예제 #4
0
 def connect_ftp(self, user, passwd, host, port, dirs):
     key = user, host, port, '/'.join(dirs)
     if key in self.cache:
         self.timeout[key] = time.time() + self.delay
     else:
         self.cache[key] = ftpwrapper(user, passwd, host, port, dirs)
         self.timeout[key] = time.time() + self.delay
     self.check_cache()
     return self.cache[key]
예제 #5
0
 def connect_ftp(self, user, passwd, host, port, dirs, timeout):
     fw = ftpwrapper(user,
                     passwd,
                     host,
                     port,
                     dirs,
                     timeout,
                     persistent=False)
     return fw
예제 #6
0
 def connect_ftp(self, user, passwd, host, port, dirs):
     key = user, passwd, host, port
     if self.cache.has_key(key):
         self.timeout[key] = time.time() + self.delay
     else:
         self.cache[key] = ftpwrapper(user, passwd, host, port, dirs)
         self.timeout[key] = time.time() + self.delay
     self.check_cache()
     return self.cache[key]
예제 #7
0
파일: cdurllib.py 프로젝트: AZed/uvcdat
 def open_ftp(self, url):
     host, path = urllib.splithost(url)
     if not host: raise IOError, ('ftp error', 'no host given')
     host, port = urllib.splitport(host)
     user, host = urllib.splituser(host)
     # if user: user, passwd = splitpasswd(user)
     if user: passwd = getpass.getpass()
     else: passwd = None
     host = urllib.unquote(host)
     user = urllib.unquote(user or '')
     passwd = urllib.unquote(passwd or '')
     host = socket.gethostbyname(host)
     if not port:
         import ftplib
         port = ftplib.FTP_PORT
     else:
         port = int(port)
     path, attrs = urllib.splitattr(path)
     path = urllib.unquote(path)
     dirs = string.splitfields(path, '/')
     dirs, file = dirs[:-1], dirs[-1]
     if dirs and not dirs[0]: dirs = dirs[1:]
     key = (user, host, port, string.joinfields(dirs, '/'))
     # XXX thread unsafe!
     if len(self.ftpcache) > MAXFTPCACHE:
         # Prune the cache, rather arbitrarily
         for k in self.ftpcache.keys():
             if k != key:
                 v = self.ftpcache[k]
                 del self.ftpcache[k]
                 v.close()
     try:
         if not self.ftpcache.has_key(key):
             print 'Creating ftpwrapper: ',user,host,port,dirs
             self.ftpcache[key] = \
                 urllib.ftpwrapper(user, passwd, host, port, dirs)
         if not file: type = 'D'
         else: type = 'I'
         for attr in attrs:
             attr, value = urllib.splitvalue(attr)
             if string.lower(attr) == 'type' and \
                value in ('a', 'A', 'i', 'I', 'd', 'D'):
                 type = string.upper(value)
         (fp, retrlen) = self.ftpcache[key].retrfile(file, type)
         if retrlen is not None and retrlen >= 0:
             import mimetools, StringIO
             headers = mimetools.Message(StringIO.StringIO(
                 'Content-Length: %d\n' % retrlen))
         else:
             headers = noheaders()
         return urllib.addinfourl(fp, headers, "ftp:" + url)
     except urllib.ftperrors(), msg:
         raise IOError, ('ftp error', msg), sys.exc_info()[2]
예제 #8
0
 def open_ftp(self, url):
     host, path = urllib.splithost(url)
     if not host: raise IOError, ('ftp error', 'no host given')
     host, port = urllib.splitport(host)
     user, host = urllib.splituser(host)
     # if user: user, passwd = splitpasswd(user)
     if user: passwd = getpass.getpass()
     else: passwd = None
     host = urllib.unquote(host)
     user = urllib.unquote(user or '')
     passwd = urllib.unquote(passwd or '')
     host = socket.gethostbyname(host)
     if not port:
         import ftplib
         port = ftplib.FTP_PORT
     else:
         port = int(port)
     path, attrs = urllib.splitattr(path)
     path = urllib.unquote(path)
     dirs = string.splitfields(path, '/')
     dirs, file = dirs[:-1], dirs[-1]
     if dirs and not dirs[0]: dirs = dirs[1:]
     key = (user, host, port, string.joinfields(dirs, '/'))
     # XXX thread unsafe!
     if len(self.ftpcache) > MAXFTPCACHE:
         # Prune the cache, rather arbitrarily
         for k in self.ftpcache.keys():
             if k != key:
                 v = self.ftpcache[k]
                 del self.ftpcache[k]
                 v.close()
     try:
         if not self.ftpcache.has_key(key):
             print 'Creating ftpwrapper: ', user, host, port, dirs
             self.ftpcache[key] = \
                 urllib.ftpwrapper(user, passwd, host, port, dirs)
         if not file: type = 'D'
         else: type = 'I'
         for attr in attrs:
             attr, value = urllib.splitvalue(attr)
             if string.lower(attr) == 'type' and \
                value in ('a', 'A', 'i', 'I', 'd', 'D'):
                 type = string.upper(value)
         (fp, retrlen) = self.ftpcache[key].retrfile(file, type)
         if retrlen is not None and retrlen >= 0:
             import mimetools, StringIO
             headers = mimetools.Message(
                 StringIO.StringIO('Content-Length: %d\n' % retrlen))
         else:
             headers = noheaders()
         return urllib.addinfourl(fp, headers, "ftp:" + url)
     except urllib.ftperrors(), msg:
         raise IOError, ('ftp error', msg), sys.exc_info()[2]
예제 #9
0
    def connect_ftp(self, user, passwd, host, port, dirs):
        fw = ftpwrapper(user, passwd, host, port, dirs)
##        fw.ftp.set_debuglevel(1)
        return fw
예제 #10
0
 def connect_ftp(self, user, passwd, host, port, dirs):
     fw = ftpwrapper(user, passwd, host, port, dirs)
     ##        fw.ftp.set_debuglevel(1)
     return fw
예제 #11
0
파일: urllib2.py 프로젝트: mcyril/ravel-ftn
"""An extensible library for opening URLs using a variety of protocols
예제 #12
0
 def connect_ftp(self, user, passwd, host, port, dirs, timeout):
     fw = ftpwrapper(user, passwd, host, port, dirs, timeout, persistent=False)
     return fw
예제 #13
0
파일: urllib2.py 프로젝트: mcyril/ravel-ftn
"""An extensible library for opening URLs using a variety of protocols