Package CHEM :: Package Common :: Module IteratorFactory :: Class FileFactory
[hide private]
[frames] | no frames]

Class FileFactory



IteratorFactory --+
                  |
                 FileFactory

Concrete implementation of an IteratorFactory that can produce a fresh file cursor iterator over a file multiple times. This requires a reference to the filename so that a fresh "open" operation can be called on it each time.

If the filename represents stdin ("-"), then this approach will not work and requires a temporary file to be created.

Instance Methods [hide private]
 
__init__(self, aFile)
Constructor, taking the filename or file object to create iterators for.
 
__del__(self)
Destructor.
 
__iter__(self)
Primary abstract method where, that returns an iterator useable in a "for item in iterator:" construct.
Class Variables [hide private]
  fd = <CHEM.DB.rdb.search.NameRxnPatternMatchingModel.SearchSen...
Name of the file to open iterators for
  filename = <CHEM.DB.rdb.search.NameRxnPatternMatchingModel.Sea...
Flag indicating whether a temp file was used
  usedTempFile = False
Method Details [hide private]

__init__(self, aFile)
(Constructor)

 
Constructor, taking the filename or file object to create iterators for. If a string filename is given, then just use that directly. Otherwise, if a file object is given, or the filename specifies stdin, then a temporary file copy will be created.

__del__(self)
(Destructor)

 
Destructor. If a temp file was created, then delete it.

__iter__(self)

 
Primary abstract method where, that returns
an iterator useable in a "for item in iterator:" construct.
Based on the "iterable" interface, so no explicit function
call is needed.  If you want to though, you could do something like

factory = FileFactory(filename);
for item in iter(factory):
    print item;

or just

for item in factory:
    print item;

Overrides: IteratorFactory.__iter__
(inherited documentation)

Class Variable Details [hide private]

fd

Name of the file to open iterators for
Value:
None

filename

Flag indicating whether a temp file was used
Value:
None