mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-03-10 22:43:52 +00:00
Rename 'ShortReadOnlySFTPFile.async' to '.async_' for compatibility with Python 3.7 and later.
This commit is contained in:
parent
c48548a7ca
commit
480bec6d0d
@ -559,7 +559,7 @@ class ShortReadOnlySFTPFile(PrefixingLogMixin):
|
|||||||
"""I represent a file handle to a particular file on an SFTP connection.
|
"""I represent a file handle to a particular file on an SFTP connection.
|
||||||
I am used only for short immutable files opened in read-only mode.
|
I am used only for short immutable files opened in read-only mode.
|
||||||
When I am created, the file contents start to be downloaded to memory.
|
When I am created, the file contents start to be downloaded to memory.
|
||||||
self.async is used to delay read requests until the download has finished."""
|
self.async_ is used to delay read requests until the download has finished."""
|
||||||
|
|
||||||
def __init__(self, userpath, filenode, metadata):
|
def __init__(self, userpath, filenode, metadata):
|
||||||
PrefixingLogMixin.__init__(self, facility="tahoe.sftp", prefix=userpath)
|
PrefixingLogMixin.__init__(self, facility="tahoe.sftp", prefix=userpath)
|
||||||
@ -569,7 +569,7 @@ class ShortReadOnlySFTPFile(PrefixingLogMixin):
|
|||||||
userpath=userpath, filenode=filenode)
|
userpath=userpath, filenode=filenode)
|
||||||
self.filenode = filenode
|
self.filenode = filenode
|
||||||
self.metadata = metadata
|
self.metadata = metadata
|
||||||
self.async = download_to_data(filenode)
|
self.async_ = download_to_data(filenode)
|
||||||
self.closed = False
|
self.closed = False
|
||||||
|
|
||||||
def readChunk(self, offset, length):
|
def readChunk(self, offset, length):
|
||||||
@ -598,7 +598,7 @@ class ShortReadOnlySFTPFile(PrefixingLogMixin):
|
|||||||
else:
|
else:
|
||||||
eventually_callback(d)(data[offset:offset+length]) # truncated if offset+length > len(data)
|
eventually_callback(d)(data[offset:offset+length]) # truncated if offset+length > len(data)
|
||||||
return data
|
return data
|
||||||
self.async.addCallbacks(_read, eventually_errback(d))
|
self.async_.addCallbacks(_read, eventually_errback(d))
|
||||||
d.addBoth(_convert_error, request)
|
d.addBoth(_convert_error, request)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
@ -639,7 +639,7 @@ class GeneralSFTPFile(PrefixingLogMixin):
|
|||||||
storing the file contents. In order to allow write requests to be satisfied
|
storing the file contents. In order to allow write requests to be satisfied
|
||||||
immediately, there is effectively a FIFO queue between requests made to this
|
immediately, there is effectively a FIFO queue between requests made to this
|
||||||
file handle, and requests to my OverwriteableFileConsumer. This queue is
|
file handle, and requests to my OverwriteableFileConsumer. This queue is
|
||||||
implemented by the callback chain of self.async.
|
implemented by the callback chain of self.async_.
|
||||||
|
|
||||||
When first constructed, I am in an 'unopened' state that causes most
|
When first constructed, I am in an 'unopened' state that causes most
|
||||||
operations to be delayed until 'open' is called."""
|
operations to be delayed until 'open' is called."""
|
||||||
@ -654,7 +654,7 @@ class GeneralSFTPFile(PrefixingLogMixin):
|
|||||||
self.flags = flags
|
self.flags = flags
|
||||||
self.close_notify = close_notify
|
self.close_notify = close_notify
|
||||||
self.convergence = convergence
|
self.convergence = convergence
|
||||||
self.async = defer.Deferred()
|
self.async_ = defer.Deferred()
|
||||||
# Creating or truncating the file is a change, but if FXF_EXCL is set, a zero-length file has already been created.
|
# Creating or truncating the file is a change, but if FXF_EXCL is set, a zero-length file has already been created.
|
||||||
self.has_changed = (flags & (FXF_CREAT | FXF_TRUNC)) and not (flags & FXF_EXCL)
|
self.has_changed = (flags & (FXF_CREAT | FXF_TRUNC)) and not (flags & FXF_EXCL)
|
||||||
self.closed = False
|
self.closed = False
|
||||||
@ -664,7 +664,7 @@ class GeneralSFTPFile(PrefixingLogMixin):
|
|||||||
self.filenode = None
|
self.filenode = None
|
||||||
self.metadata = None
|
self.metadata = None
|
||||||
|
|
||||||
# self.consumer should only be relied on in callbacks for self.async, since it might
|
# self.consumer should only be relied on in callbacks for self.async_, since it might
|
||||||
# not be set before then.
|
# not be set before then.
|
||||||
self.consumer = None
|
self.consumer = None
|
||||||
|
|
||||||
@ -691,7 +691,7 @@ class GeneralSFTPFile(PrefixingLogMixin):
|
|||||||
self.consumer = OverwriteableFileConsumer(0, tempfile_maker)
|
self.consumer = OverwriteableFileConsumer(0, tempfile_maker)
|
||||||
self.consumer.download_done("download not needed")
|
self.consumer.download_done("download not needed")
|
||||||
else:
|
else:
|
||||||
self.async.addCallback(lambda ignored: filenode.get_best_readable_version())
|
self.async_.addCallback(lambda ignored: filenode.get_best_readable_version())
|
||||||
|
|
||||||
def _read(version):
|
def _read(version):
|
||||||
if noisy: self.log("_read", level=NOISY)
|
if noisy: self.log("_read", level=NOISY)
|
||||||
@ -707,9 +707,9 @@ class GeneralSFTPFile(PrefixingLogMixin):
|
|||||||
self.consumer.download_done(res)
|
self.consumer.download_done(res)
|
||||||
d.addBoth(_finished)
|
d.addBoth(_finished)
|
||||||
# It is correct to drop d here.
|
# It is correct to drop d here.
|
||||||
self.async.addCallback(_read)
|
self.async_.addCallback(_read)
|
||||||
|
|
||||||
eventually_callback(self.async)(None)
|
eventually_callback(self.async_)(None)
|
||||||
|
|
||||||
if noisy: self.log("open done", level=NOISY)
|
if noisy: self.log("open done", level=NOISY)
|
||||||
return self
|
return self
|
||||||
@ -739,7 +739,7 @@ class GeneralSFTPFile(PrefixingLogMixin):
|
|||||||
self.log(".sync()", level=OPERATIONAL)
|
self.log(".sync()", level=OPERATIONAL)
|
||||||
|
|
||||||
d = defer.Deferred()
|
d = defer.Deferred()
|
||||||
self.async.addBoth(eventually_callback(d))
|
self.async_.addBoth(eventually_callback(d))
|
||||||
def _done(res):
|
def _done(res):
|
||||||
if noisy: self.log("_done(%r) in .sync()" % (res,), level=NOISY)
|
if noisy: self.log("_done(%r) in .sync()" % (res,), level=NOISY)
|
||||||
return res
|
return res
|
||||||
@ -765,7 +765,7 @@ class GeneralSFTPFile(PrefixingLogMixin):
|
|||||||
d2.addBoth(eventually_callback(d))
|
d2.addBoth(eventually_callback(d))
|
||||||
# It is correct to drop d2 here.
|
# It is correct to drop d2 here.
|
||||||
return None
|
return None
|
||||||
self.async.addCallbacks(_read, eventually_errback(d))
|
self.async_.addCallbacks(_read, eventually_errback(d))
|
||||||
d.addBoth(_convert_error, request)
|
d.addBoth(_convert_error, request)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
@ -802,8 +802,8 @@ class GeneralSFTPFile(PrefixingLogMixin):
|
|||||||
self.consumer.overwrite(write_offset, data)
|
self.consumer.overwrite(write_offset, data)
|
||||||
if noisy: self.log("overwrite done", level=NOISY)
|
if noisy: self.log("overwrite done", level=NOISY)
|
||||||
return None
|
return None
|
||||||
self.async.addCallback(_write)
|
self.async_.addCallback(_write)
|
||||||
# don't addErrback to self.async, just allow subsequent async ops to fail.
|
# don't addErrback to self.async_, just allow subsequent async ops to fail.
|
||||||
return defer.succeed(None)
|
return defer.succeed(None)
|
||||||
|
|
||||||
def _do_close(self, res, d=None):
|
def _do_close(self, res, d=None):
|
||||||
@ -812,7 +812,7 @@ class GeneralSFTPFile(PrefixingLogMixin):
|
|||||||
if self.consumer:
|
if self.consumer:
|
||||||
status = self.consumer.close()
|
status = self.consumer.close()
|
||||||
|
|
||||||
# We must close_notify before re-firing self.async.
|
# We must close_notify before re-firing self.async_.
|
||||||
if self.close_notify:
|
if self.close_notify:
|
||||||
self.close_notify(self.userpath, self.parent, self.childname, self)
|
self.close_notify(self.userpath, self.parent, self.childname, self)
|
||||||
|
|
||||||
@ -841,7 +841,7 @@ class GeneralSFTPFile(PrefixingLogMixin):
|
|||||||
# download.) Any reads that depended on file content that could not be downloaded
|
# download.) Any reads that depended on file content that could not be downloaded
|
||||||
# will have failed. It is important that we don't close the consumer until
|
# will have failed. It is important that we don't close the consumer until
|
||||||
# previous read operations have completed.
|
# previous read operations have completed.
|
||||||
self.async.addBoth(self._do_close)
|
self.async_.addBoth(self._do_close)
|
||||||
return defer.succeed(None)
|
return defer.succeed(None)
|
||||||
|
|
||||||
# We must capture the abandoned, parent, and childname variables synchronously
|
# We must capture the abandoned, parent, and childname variables synchronously
|
||||||
@ -875,16 +875,16 @@ class GeneralSFTPFile(PrefixingLogMixin):
|
|||||||
return d2
|
return d2
|
||||||
|
|
||||||
# If the file has been abandoned, we don't want the close operation to get "stuck",
|
# If the file has been abandoned, we don't want the close operation to get "stuck",
|
||||||
# even if self.async fails to re-fire. Completing the close independently of self.async
|
# even if self.async_ fails to re-fire. Completing the close independently of self.async_
|
||||||
# in that case should ensure that dropping an ssh connection is sufficient to abandon
|
# in that case should ensure that dropping an ssh connection is sufficient to abandon
|
||||||
# any heisenfiles that were not explicitly closed in that connection.
|
# any heisenfiles that were not explicitly closed in that connection.
|
||||||
if abandoned or not has_changed:
|
if abandoned or not has_changed:
|
||||||
d = defer.succeed(None)
|
d = defer.succeed(None)
|
||||||
self.async.addBoth(self._do_close)
|
self.async_.addBoth(self._do_close)
|
||||||
else:
|
else:
|
||||||
d = defer.Deferred()
|
d = defer.Deferred()
|
||||||
self.async.addCallback(_commit)
|
self.async_.addCallback(_commit)
|
||||||
self.async.addBoth(self._do_close, d)
|
self.async_.addBoth(self._do_close, d)
|
||||||
d.addBoth(_convert_error, request)
|
d.addBoth(_convert_error, request)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
@ -908,7 +908,7 @@ class GeneralSFTPFile(PrefixingLogMixin):
|
|||||||
attrs = _populate_attrs(self.filenode, self.metadata, size=self.consumer.get_current_size())
|
attrs = _populate_attrs(self.filenode, self.metadata, size=self.consumer.get_current_size())
|
||||||
eventually_callback(d)(attrs)
|
eventually_callback(d)(attrs)
|
||||||
return None
|
return None
|
||||||
self.async.addCallbacks(_get, eventually_errback(d))
|
self.async_.addCallbacks(_get, eventually_errback(d))
|
||||||
d.addBoth(_convert_error, request)
|
d.addBoth(_convert_error, request)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
@ -946,7 +946,7 @@ class GeneralSFTPFile(PrefixingLogMixin):
|
|||||||
self.consumer.set_current_size(size)
|
self.consumer.set_current_size(size)
|
||||||
eventually_callback(d)(None)
|
eventually_callback(d)(None)
|
||||||
return None
|
return None
|
||||||
self.async.addCallbacks(_set, eventually_errback(d))
|
self.async_.addCallbacks(_set, eventually_errback(d))
|
||||||
d.addBoth(_convert_error, request)
|
d.addBoth(_convert_error, request)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user