@@ -10,22 +10,23 @@ class FileHandler(object):
1010
1111 :cvar string infile: name of the input file to be processed.
1212 :cvar string outfile: name of the output file where to write in.
13- :cvar string extension: extension of the input/output files. It is specific for each
13+ :cvar list extensions: extensions of the input/output files. It is specific for each
1414 subclass.
1515 """
1616
1717 def __init__ (self ):
1818 self .infile = None
1919 self .outfile = None
20- self .extension = None
20+ self .extensions = []
2121
2222 def parse (self , * args ):
2323 """
2424 Abstract method to parse a specific file.
2525
2626 Not implemented, it has to be implemented in subclasses.
2727 """
28- raise NotImplementedError ("Subclass must implement abstract method " \
28+ raise NotImplementedError (
29+ "Subclass must implement abstract method " \
2930 + self .__class__ .__name__ + ".parse" )
3031
3132 def write (self , * args ):
@@ -34,21 +35,22 @@ def write(self, *args):
3435
3536 Not implemented, it has to be implemented in subclasses.
3637 """
37- raise NotImplementedError ("Subclass must implement abstract method " \
38- + self .__class__ .__name__ + ".write" )
38+ raise NotImplementedError (
39+ "Subclass must implement abstract method " \
40+ + self .__class__ .__name__ + ".write" )
3941
4042 def _check_extension (self , filename ):
4143 """
42- This private method checks if the given `filename` has the proper `extension` set
44+ This private class method checks if the given `filename` has the proper `extension` set
4345 in the child class. If not it raises a ValueError.
4446
4547 :param string filename: file to check.
4648 """
4749 __ , file_ext = os .path .splitext (filename )
48- if not file_ext in self .extension :
50+ if file_ext not in self .extensions :
4951 raise ValueError (
5052 'The input file does not have the proper extension. \
51- It is {0!s}, instead of {1!s}.' .format (file_ext , self .extension )
53+ It is {0!s}, instead of {1!s}.' .format (file_ext , self .extensions )
5254 )
5355
5456 @staticmethod
@@ -63,16 +65,14 @@ def _check_filename_type(filename):
6365 'The given filename ({0!s}) must be a string' .format (filename )
6466 )
6567
66- @staticmethod
67- def _check_infile_instantiation (infile ):
68+ def _check_infile_instantiation (self ):
6869 """
69- This private static method checks if the input file ` infile` is instantiated. If not it means
70- that nobody called the parse method, i.e. `self.infile` is None. If the check fails
70+ This private method checks if `self. infile` is instantiated. If not it means
71+ that nobody called the parse method and `self.infile` is None. If the check fails
7172 it raises a RuntimeError.
7273
73- :param string infile: file to check.
7474 """
75- if not infile :
75+ if not self . infile :
7676 raise RuntimeError (
7777 "You can not write a file without having parsed one."
7878 )
0 commit comments