Navigation


Changeset 1506:2ab9d941bad5 in freeDiameter for contrib


Ignore:
Timestamp:
Apr 3, 2020, 3:04:13 PM (4 years ago)
Author:
Luke Mewburn <luke@mewburn.net>
Branch:
default
Phase:
public
Message:

csv_to_fd: improve validation error handling

File:
1 edited

Legend:

Unmodified
Added
Removed
  • contrib/tools/csv_to_fd

    r1498 r1506  
    22
    33"""
    4 Convert CSV files containing RADIUS or Diameter AVP tables
     4Convert 8 column CSV files containing RADIUS or Diameter AVP tables
    55into various formats.
    66
    77Format of the CSV files is one of:
    88- Row per 3GPP AVP tables:
    9     Name, Code, Section, DataType, Must, May, ShouldNot, MustNot [, extra]
     9    Name, Code, Section, DataType, Must, May, ShouldNot, MustNot
    1010    - Name:
    1111        AVP Name. String, validated as ALPHA *(ALPHA / DIGIT / "-")
     
    601601        with open(filename, 'r') as csvfile:
    602602            csvdata = csv.DictReader(csvfile, CSV_COLUMN_NAMES,
    603                                      restkey='extra_cells')
     603                                     restkey='extra_cells', restval='')
    604604            standard = ''
    605605            vendor = 0
     
    607607            for row in csvdata:
    608608                try:
     609                    if csvdata.restkey in row:
     610                        raise ValueError('Extra cells: {}'.format(
     611                            ','.join(row[csvdata.restkey])))
    609612                    if row['name'] in (None, '', 'Attribute Name'):
    610613                        continue
     
    641644                        # Process AVP
    642645                        avpproc.avp(avp)
    643                 except ValueError as e:
     646                except (TypeError, ValueError) as e:
    644647                    errors.append('CSV file "{}" line {}: {}\n'.format(
    645648                        filename, csvdata.line_num, e))
Note: See TracChangeset for help on using the changeset viewer.