# Path: nrcif/fields.py
# class TextField(CIFField):
#     '''Represents a CIF field simply stored as text'''
# 
#     py_type = str
# 
#     def __init__(self, name, width):
#         self.name = name
#         self.width = width
#         self.sql_type = "CHAR({})".format(width)
# 
# class IntegerField(CIFField):
#     '''Represents a CIF field simply stored as an integer'''
# 
#     sql_type = "INTEGER"
#     py_type = int
# 
#     def __init__(self, name, width, optional=False):
#         self.name = name
#         self.width = width
#         self.optional = optional
# 
#     def read(self, text):
#         if self.optional and text.isspace():
#             return None
#         else:
#             return int(text)
# 
# class VarTextField(CIFField):
#     '''Represents a CIF field simply stored as text'''
# 
#     py_type = str
# 
#     def __init__(self, name, width):
#         self.name = name
#         self.width = width
#         self.sql_type = "VARCHAR({})".format(width)


from nrcif.fields import TextField, IntegerField, VarTextField
import nrcif.mockdb
'''tsi_reader - Read ATOC TOC Specific Interchange times

This module reads data from a TSI file from ATOC containing additional
information on the interchange times between train companies at certain
TOCs (for example, where a particular company has its own set of
platforms at some distance from the others.'''



class TSI(object):
    '''A simple hander for TSI files.'''

    layout = [TextField("Station code", 3),
              TextField("Arriving train TOC", 2),
              TextField("Departing train TOC", 2),
              IntegerField("Minimum Interchange Time", 2),
              VarTextField("Comments", 100)]

    def __init__(self, cur):

        self.cur = cur

    def process(self, record):
        '''TSI files are in a simple CSV format with five columns. This
        function takes in a record and produces the appropriate SQL to insert
        the data into the database.'''

        fields = record.rstrip().split(",")
        if len(fields) != 5:
            raise ValueError("Line {} in the TSI file does not have "

# Path: nrcif/fields.py
# class TextField(CIFField):
#     '''Represents a CIF field simply stored as text'''
# 
#     py_type = str
# 
#     def __init__(self, name, width):
#         self.name = name
#         self.width = width
#         self.sql_type = "CHAR({})".format(width)
# 
# class IntegerField(CIFField):
#     '''Represents a CIF field simply stored as an integer'''
# 
#     sql_type = "INTEGER"
#     py_type = int
# 
#     def __init__(self, name, width, optional=False):
#         self.name = name
#         self.width = width
#         self.optional = optional
# 
#     def read(self, text):
#         if self.optional and text.isspace():
#             return None
#         else:
#             return int(text)
# 
# class VarTextField(CIFField):
#     '''Represents a CIF field simply stored as text'''
# 
#     py_type = str
# 
#     def __init__(self, name, width):
#         self.name = name
#         self.width = width
#         self.sql_type = "VARCHAR({})".format(width)


# Path: nrcif/tsi_reader.py
from nrcif.fields import TextField, IntegerField, VarTextField
import nrcif.mockdb

'''tsi_reader - Read ATOC TOC Specific Interchange times

This module reads data from a TSI file from ATOC containing additional
information on the interchange times between train companies at certain
TOCs (for example, where a particular company has its own set of
platforms at some distance from the others.'''



class TSI(object):
    '''A simple hander for TSI files.'''

    layout = [TextField("Station code", 3),
              TextField("Arriving train TOC", 2),
              TextField("Departing train TOC", 2),
              IntegerField("Minimum Interchange Time", 2),
              VarTextField("Comments", 100)]

    def __init__(self, cur):

        self.cur = cur

    def process(self, record):
        '''TSI files are in a simple CSV format with five columns. This
        function takes in a record and produces the appropriate SQL to insert
        the data into the database.'''

        fields = record.rstrip().split(",")
        if len(fields) != 5:
            raise ValueError("Line {} in the TSI file does not have "

                             "five fields".format(record))