Add missing tell()
method to GeneratorFile and add tests
This commit is contained in:
parent
1e49002458
commit
43e77a7a14
2 changed files with 36 additions and 0 deletions
|
@ -10,10 +10,16 @@ class GeneratorFile(object):
|
|||
self._generator = generator
|
||||
self._closed = False
|
||||
self._buf = ''
|
||||
self._position = 0
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
|
||||
def tell(self):
|
||||
"""Return the file's current position, like stdio's ftell()."""
|
||||
_complain_ifclosed(self._closed)
|
||||
return self._position
|
||||
|
||||
def next(self):
|
||||
"""A file object is its own iterator, for example iter(f) returns f
|
||||
(unless f is closed). When a file is used as an iterator, typically
|
||||
|
@ -62,8 +68,11 @@ class GeneratorFile(object):
|
|||
self._buf = ''
|
||||
returned = buf
|
||||
|
||||
self._position = self._position + len(returned)
|
||||
return returned
|
||||
|
||||
def seek(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def close(self):
|
||||
self._closed = True
|
||||
|
|
Reference in a new issue