6.13.1.3. Disk File Input

This driver uses a filename in your local operating system's convention.
Start python section to interscript/drivers/sources/disk.py[1 /1 ]
     1: #line 184 "source_drivers.ipk"
     2: #---------------------------------------------------------
     3: # gets input from a named file
     4: from interscript.drivers.sources import source_open_error
     5: from interscript.drivers.sources.base import file_source
     6: from interscript.drivers.sources.base import eof
     7: import string
     8: import os
     9: 
    10: # this routine is a utility which loads data directly
    11: # from an operating system level file
    12: 
    13: def loadfile(filename):
    14:    "return a list of lines, trailing whitespace removed"
    15:    try:
    16:      f = open(filename)
    17:    except:
    18:      raise source_open_error,filename
    19:    data = f.readlines()
    20:    f.close()
    21:    for i in range(len(data)):
    22:      data[i]=string.rstrip(data[i])
    23:    return data
    24: 
    25: def parse_source_filename(filename, prefix):
    26:   pathlist = string.split(filename,'/')
    27:   if prefix == '':
    28:     prefix = os.getcwd()
    29:     if prefix[-1] != os.sep:
    30:       prefix = prefix + os.sep
    31:   directory = prefix + string.join(pathlist[:-1],os.sep)
    32:   if directory[-1] != os.sep:
    33:     directory = directory + os.sep
    34:   basename = pathlist[-1]
    35:   full_filename = directory + basename
    36:   return pathlist, basename, directory, full_filename
    37: 
    38: class named_file_source(file_source):
    39:   def __init__(self,pass_frame,filename, prefix='', encoding='utf8', **kwds):
    40:     apply(file_source.__init__,(self,encoding), kwds)
    41:     self.iflist_index = len(pass_frame.iflist)
    42:     pass_frame.iflist.append([filename,0])
    43:     self.name = filename
    44:     self.pass_frame = pass_frame
    45:     self.process = pass_frame.process
    46:     if 'sources' in self.process.trace:
    47:       self.process.acquire_object(self, 'NAMED FILE SOURCE '+self.name+' ['+encoding+']')
    48: 
    49:     pathlist, self.basename, self.directory, self.filename =\
    50:       parse_source_filename(filename, prefix)
    51: 
    52:     try:
    53:       self.file = open(self.filename,'r')
    54:       self.closed = 0
    55:     except:
    56:       raise source_open_error,filename
    57: 
    58:   def __del__(self):
    59:     file_source.__del__(self)
    60:     self.pass_frame.iflist[self.iflist_index][1]=self.lines_read
    61:     if 'sources' in self.process.trace:
    62:       self.process.release_object(self)
    63: 
End python section to interscript/drivers/sources/disk.py[1]