Author: bugman Date: Fri Mar 8 16:09:49 2013 New Revision: 18709 URL: http://svn.gna.org/viewcvs/relax?rev=18709&view=rev Log: Added column number checks for the data input into lib.text.table.format_table(). Modified: trunk/lib/text/table.py Modified: trunk/lib/text/table.py URL: http://svn.gna.org/viewcvs/relax/trunk/lib/text/table.py?rev=18709&r1=18708&r2=18709&view=diff ============================================================================== --- trunk/lib/text/table.py (original) +++ trunk/lib/text/table.py Fri Mar 8 16:09:49 2013 @@ -28,6 +28,7 @@ # relax module imports. from check_types import is_float +from relax_errors import RelaxError # Special variables. @@ -220,6 +221,18 @@ if headings != None: num_head_rows = len(headings) + # Column number checks. + if custom_format != None and len(custom_format) != num_cols: + raise RelaxError("The number of columns is %s but the number of elements in custom_format is %s." % (num_cols, len(custom_format))) + if headings != None: + for i in range(num_head_rows): + if len(headings[i]) != num_cols: + raise RelaxError("The %s columns does not match the %s elements in the heading row %s." % (num_cols, len(headings[i]), headings[i])) + for i in range(num_rows): + if len(contents[i]) != num_cols: + raise RelaxError("The %s columns does not match the %s elements in the contents row %s." % (num_cols, len(contents[i]), contents[i])) + + # Deepcopy so that modifications to the data are not seen. if headings != None: headings = deepcopy(headings)