本文整理汇总了Python中tempfile.SpooledTemporaryFile.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python SpooledTemporaryFile.__init__方法的具体用法?Python SpooledTemporaryFile.__init__怎么用?Python SpooledTemporaryFile.__init__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tempfile.SpooledTemporaryFile
的用法示例。
在下文中一共展示了SpooledTemporaryFile.__init__方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from tempfile import SpooledTemporaryFile [as 别名]
# 或者: from tempfile.SpooledTemporaryFile import __init__ [as 别名]
def __init__(self, path, filename, fs, max_size=WRITE_BUFFER_SIZE):
"""We need the path so we can write the buffered file to the API"""
SpooledTemporaryFile.__init__(self, max_size=max_size) # old-style!
self.path = path
self.filename = filename
self.fs = fs
self.fullpath = ''
try:
self.fullpath = self.create_file()
except RequestError, e:
SpooledTemporaryFile.close(self)
raise FilesystemError(str(e))
示例2: __init__
# 需要导入模块: from tempfile import SpooledTemporaryFile [as 别名]
# 或者: from tempfile.SpooledTemporaryFile import __init__ [as 别名]
def __init__(self, filepath, mode='rtc'):
"""filepath: the path of the distant file
mode: take the same argument as mode argument of the global
open() + optional flag c (which mean store in cache).
"""
self.mode = mode
self.filepath = filepath
host, port = utils.get_host_port(_config['nameserver'])
self.srv = utils.get_server(filepath, host, port)
if self.srv is None:
raise DFSIOError('Impossible to find a server that serve %s.'
% filepath)
self.last_modified = None
SpooledTemporaryFile.__init__(self, _config['max_size'], mode.replace('c', ''))
host, port = utils.get_host_port(_config['lockserver'])
if utils.is_locked(filepath, host, port):
raise DFSIOError('The file %s is locked.' % filepath)
if 'w' not in mode:
host, port = utils.get_host_port(self.srv)
with closing(HTTPConnection(host, port)) as con:
con.request('GET', filepath)
response = con.getresponse()
self.last_modified = response.getheader('Last-Modified')
status = response.status
if status not in (200, 204):
raise DFSIOError('Error (%d) while opening file.' % status)
if status != 204:
self.write(response.read())
if 'r' in mode:
self.seek(0)
self.lock_id = None
if 'a' in mode or 'w' in mode:
# automatically gets a lock if we're in write/append mode
host, port = utils.get_host_port(_config['lockserver'])
self.lock_id = int(utils.get_lock(filepath, host, port))
if 'c' in mode:
File._cache[filepath] = self
示例3: __init__
# 需要导入模块: from tempfile import SpooledTemporaryFile [as 别名]
# 或者: from tempfile.SpooledTemporaryFile import __init__ [as 别名]
def __init__(self, file_obj, max_size=50*1024*1024):
self._file_obj = file_obj
SpooledTemporaryFile.__init__(self, max_size)
示例4: __init__
# 需要导入模块: from tempfile import SpooledTemporaryFile [as 别名]
# 或者: from tempfile.SpooledTemporaryFile import __init__ [as 别名]
def __init__(self, threshold=10 * 1024 * 1024, **kw):
# STF uses >, the old ATF used >= for the max_size check
SpooledTemporaryFile.__init__(self, max_size=threshold - 1, **kw)