<commit_before>import boto
import csv
import os
from dataactcore.utils.statusCode import StatusCode
from dataactcore.utils.responseException import ResponseException
from dataactvalidator.filestreaming.csvAbstractReader import CsvAbstractReader
from dataactvalidator.validation_handlers.validationError import ValidationError
from dataactvalidator.filestreaming.fieldCleaner import FieldCleaner

class CsvLocalReader(CsvAbstractReader):


    def openFile(self,bucket,filename,csvSchema,bucketName,errorFilename):
        """open file if it exists"""
        self.filename = filename
        self.isLocal = True
        try:
            self.file = open(filename,"r")
        except :
            raise ValueError("".join(["Filename provided not found : ",str(self.filename)]))
        super(CsvLocalReader,self).openFile(bucket,filename,csvSchema,bucketName,errorFilename)

    def close(self):
        """Closes file if it exists """
        if(self.file != None) :
            self.file.close()

    def _getFileSize(self):
        """
        Gets the size of the file
        """
        return os.path.getsize(self.filename)

    def _getNextPacket(self):
        """
        Gets the next packet from the file returns true if successful
        """
        packet  = self.file.read(CsvAbstractReader.BUFFER_SIZE).decode('utf-8')
        success = True
        if(packet == ""):
            success = False
        return success,packet<commit_msg>Fixed handling of closing a non-open file<commit_after>import boto
import csv
import os
from dataactcore.utils.statusCode import StatusCode
from dataactcore.utils.responseException import ResponseException
from dataactvalidator.filestreaming.csvAbstractReader import CsvAbstractReader
from dataactvalidator.validation_handlers.validationError import ValidationError
from dataactvalidator.filestreaming.fieldCleaner import FieldCleaner

class CsvLocalReader(CsvAbstractReader):


    def openFile(self,bucket,filename,csvSchema,bucketName,errorFilename):
        """open file if it exists"""
        self.filename = filename
        self.isLocal = True
        try:
            self.file = open(filename,"r")
        except :
            raise ValueError("".join(["Filename provided not found : ",str(self.filename)]))
        super(CsvLocalReader,self).openFile(bucket,filename,csvSchema,bucketName,errorFilename)

    def close(self):
        """Closes file if it exists """
        try:
            self.file.close()
        except AttributeError:
            # File does not exist, and so does not need to be closed
            pass

    def _getFileSize(self):
        """
        Gets the size of the file
        """
        return os.path.getsize(self.filename)

    def _getNextPacket(self):
        """
        Gets the next packet from the file returns true if successful
        """
        packet  = self.file.read(CsvAbstractReader.BUFFER_SIZE).decode('utf-8')
        success = True
        if(packet == ""):
            success = False
        return success,packet
{'fraction_non_alphanumeric': 0.08734344100197759, 'fraction_numerical': 0.0006591957811470006, 'mean_word_length': 2.9518229166666665, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6073917', 'n_tokens_mistral': 793, 'n_tokens_neox': 790, 'n_words': 203}