本文整理汇总了Python中urllib.ftpwrapper函数的典型用法代码示例。如果您正苦于以下问题:Python ftpwrapper函数的具体用法?Python ftpwrapper怎么用?Python ftpwrapper使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ftpwrapper函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: connect_ftp
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: connect_ftp
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]
示例3: connect_ftp
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]
示例4: open_ftp
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]
示例5: connect_ftp
def connect_ftp(self, user, passwd, host, port, dirs, timeout):
fw = ftpwrapper(user, passwd, host, port, dirs, timeout, persistent=False)
return fw
示例6:
"""An extensible library for opening URLs using a variety of protocols