Skip to content
Browse files

Add IReader.size.

  • Loading branch information...
1 parent c7b5a41 commit f9b3b81f5dfce965cc8e01f16e9c241b9bed5680 @allenap committed
Showing with 17 additions and 0 deletions.
  1. +11 −0 tftp/
  2. +4 −0 tftp/test/
  3. +2 −0 tftp/test/
11 tftp/
@@ -62,6 +62,9 @@ def get_writer(file_name):
class IReader(interface.Interface):
"""An object, that performs reads on request of the TFTP protocol"""
+ size = interface.Attribute(
+ "The size of the file to be read, or C{None} if it's not known.")
def read(size):
"""Attempt to read C{size} number of bytes.
@@ -130,6 +133,14 @@ def __init__(self, file_path):
raise FileNotFound(self.file_path)
self.state = 'active'
+ @property
shylent added a note

To be honest, I would never make it a property. Why? Because it looks like attribute access, but it actually results in a filesystem hit (for the first time only, though, due to behaviour of t.p.filepath.FilePath.getsize). I would rather have it as a method.

Still, it is not that much of a problem, I think. More of a style thing.

@allenap Owner
allenap added a note

You're right. I've just hit a problem with having it as a property too: it may need to return a Deferred. I shall change this to be a function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ def size(self):
+ """
+ @see: L{IReader.size}
+ """
+ return self.file_path.getsize()
def read(self, size):
@see: L{}
4 tftp/test/
@@ -73,6 +73,10 @@ def test_read_existing_file(self):
"The file has been exhausted and should be in the closed state")
self.assertEqual(ostring, self.test_data)
+ def test_size(self):
+ r = FilesystemReader(self.temp_dir.child('foo'))
+ self.assertEqual(len(self.test_data), r.size)
def test_cancel(self):
r = FilesystemReader(self.temp_dir.child('foo'))
2 tftp/test/
@@ -54,6 +54,8 @@ def c(ign):
class FailingReader(object):
+ size = None
def read(self, size):
raise IOError('A failure')

0 comments on commit f9b3b81

Please sign in to comment.
Something went wrong with that request. Please try again.