'Open the file to be loaded, or materalize the template.
This method can set the state to be an ERROR state, so
avoid setting state after calling this method.'

def _setup_xfer(self):

    logging.info(('host    %s    requesting    %s' % (self.system.name, self.filename)))
    (self.filename, self.type) = self._remap_name(self.filename)
    logging.debug(('host    %s    getting    %s:    %s' % (self.system.name, self.filename, self.type)))
    if (self.type == 'template'):
        output = Popen([OPTIONS['file_cmd'], self.filename], stdout=PIPE, stderr=STDOUT, close_fds=True).communicate()[0]
        if (output.find('    text') >= 0):
            self.file = self._render_template()
            if self.file:
                self.block_count = 0
                self.file_size = len(self.file.data)
                return
            else:
                logging.debug('Template    failed    to    render.')
        else:
            logging.debug(('Not    rendering    binary    file    %s    (%s).' % (self.filename, output)))
    elif (self.type == 'hash_value'):
        self.file = RenderedFile(self.system.attrs[self.filename])
        self.block_count = 0
        self.file_size = len(self.file.data)
        return
    else:
        logging.debug('Relative    path')
    try:
        logging.debug(('starting    xfer    of    %s    to    %s' % (self.filename, self.remote_addr)))
        if (self.type == 'template'):
            self.file = open(self.filename, 'rb', 0)
        else:
            self.file = open(((OPTIONS['prefix'] + '/') + self.filename), 'rb', 0)
        self.block_count = 0
        self.file_size = os.fstat(self.file.fileno()).st_size
    except IOError:
        logging.debug(('%s    requested    %s:    file    not    found.' % (self.remote_addr, self.filename)))
        self.state = TFTP_OPCODE_ERROR
        self.error_code = 1
        self.error_str = 'No    such    file'
    return
