Exemple #1
0
    def __init__(self, filename, indentation_per_tag=2, indentation=0):
        ClosableObject.__init__(self)

        self.indentation_per_tag = indentation_per_tag
        self.indentation = indentation
        self.file = None
        self.filename = filename

        if not isinstance(filename, str):
            raise TypeError("filename must be a string")

        self.file = open(filename, 'w+')
        self.__write_header()
Exemple #2
0
    def __init__(self, filename):
        """
        Creates a new FilePrinter. If the directory of the given file doesn't
        exist or if there's any access problems, an exception will be thrown.

        :param filename: the name of the file to put the data into (string).
        """
        Printer.__init__(self)
        ClosableObject.__init__(self)
        self.file = None
        if not isinstance(filename, str):
            raise TypeError("filename must be a string.")

        self.file = open(filename, 'a+')
class ClosableObjectTest(unittest.TestCase):
    def setUp(self):
        self.uut = ClosableObject()

    def test_closing(self):
        self.assertFalse(self.uut._closed)
        self.uut.close()
        self.assertTrue(self.uut._closed)
        self.uut.close()
        self.assertTrue(self.uut._closed)

    def test_close_objects(self):
        close_objects(None, 5)
        close_objects(self.uut)
        self.assertTrue(self.uut._closed)
Exemple #4
0
 def __init__(self,
              file_name,
              key_value_delimiter='=',
              comment_seperators=('#', ';', '//'),
              key_delimiter=',',
              section_name_surrounding_beg='[',
              section_name_surrounding_end="]",
              unsavable_keys=("save",)):
     ClosableObject.__init__(self)
     self.__file_name = file_name
     self.__file = open(self.__file_name, "w")
     self.__key_value_delimiter = key_value_delimiter
     self.__comment_seperators = comment_seperators
     self.__key_delimiter = key_delimiter
     self.__section_name_surrounding_beg = section_name_surrounding_beg
     self.__section_name_surrounding_end = section_name_surrounding_end
     self.__unsavable_keys = unsavable_keys
     self.__wrote_newline = True
     self.__closed = False
Exemple #5
0
    def __init__(self):
        """
        Raises EnvironmentError if VoiceOutput is impossible.
        """
        Printer.__init__(self)
        ClosableObject.__init__(self)
        # TODO retrieve language from get_locale and select appropriate voice

        try:
            self.espeak = subprocess.Popen(["espeak"], stdin=subprocess.PIPE)
        except OSError:  # pragma: no cover
            print(
                _(
                    "eSpeak doesn't seem to be installed. You cannot use the "
                    "voice output feature without eSpeak. It can be downloaded"
                    " from http://espeak.sourceforge.net/ or installed via "
                    "your usual package repositories."
                )
            )
            raise EnvironmentError
        except:  # pragma: no cover
            print(_("Failed to execute eSpeak. An unknown error occurred."), Constants.THIS_IS_A_BUG)
            raise EnvironmentError
 def setUp(self):
     self.uut = ClosableObject()