def __init__(self, file_name, key_value_delimiters=('=',), comment_separators=('#',), key_delimiters=(',', ' '), section_name_surroundings=MappingProxyType({'[': ']'}), section_override_delimiters=('.',), unsavable_keys=('save',), key_value_append_delimiters=('+=',)): ClosableObject.__init__(self) self.__file_name = file_name if (os.path.isdir(self.__file_name)): self.__file_name = os.path.join(self.__file_name, '.coafile') self.__file = open(self.__file_name, 'w') self.__key_value_delimiters = key_value_delimiters self.__key_value_append_delimiters = key_value_append_delimiters self.__comment_separators = comment_separators self.__key_delimiters = key_delimiters self.__section_name_surroundings = section_name_surroundings self.__section_override_delimiters = section_override_delimiters self.__unsavable_keys = unsavable_keys self.__closed = False self.__key_delimiter = self.__key_delimiters[0] self.__key_value_delimiter = key_value_delimiters[0] self.__key_value_append_delimiter = key_value_append_delimiters[0] (self.__section_name_surrounding_beg, self.__section_name_surrounding_end) = ( tuple(self.__section_name_surroundings.items())[0])
def __init__(self, file_name, key_value_delimiters=('=', ), comment_seperators=('#', ), key_delimiters=(',', ' '), section_name_surroundings=None, section_override_delimiters=(".", ), unsavable_keys=("save", )): section_name_surroundings = section_name_surroundings or {"[": "]"} ClosableObject.__init__(self) self.__file_name = file_name self.__file = open(self.__file_name, "w") self.__key_value_delimiters = key_value_delimiters self.__comment_seperators = comment_seperators self.__key_delimiters = key_delimiters self.__section_name_surroundings = section_name_surroundings self.__section_override_delimiters = section_override_delimiters self.__unsavable_keys = unsavable_keys self.__wrote_newline = True self.__closed = False self.__key_delimiter = self.__key_delimiters[0] self.__key_value_delimiter = self.__key_value_delimiters[0] (self.__section_name_surrounding_beg, self.__section_name_surrounding_end) = (tuple( self.__section_name_surroundings.items())[0])
def __init__(self, file_name, key_value_delimiters=('=', ), comment_separators=('#', ), key_delimiters=(',', ' '), section_name_surroundings=MappingProxyType({'[': ']'}), section_override_delimiters=('.', ), unsavable_keys=('save', ), key_value_append_delimiters=('+=', )): ClosableObject.__init__(self) self.__file_name = file_name if (os.path.isdir(self.__file_name)): self.__file_name = os.path.join(self.__file_name, '.coafile') self.__file = open(self.__file_name, 'w') self.__key_value_delimiters = key_value_delimiters self.__key_value_append_delimiters = key_value_append_delimiters self.__comment_separators = comment_separators self.__key_delimiters = key_delimiters self.__section_name_surroundings = section_name_surroundings self.__section_override_delimiters = section_override_delimiters self.__unsavable_keys = unsavable_keys self.__closed = False self.__key_delimiter = self.__key_delimiters[0] self.__key_value_delimiter = key_value_delimiters[0] self.__key_value_append_delimiter = key_value_append_delimiters[0] (self.__section_name_surrounding_beg, self.__section_name_surrounding_end) = (tuple( self.__section_name_surroundings.items())[0])
def __init__(self, file_name, key_value_delimiters=('=',), comment_seperators=('#',), key_delimiters=(',', ' '), section_name_surroundings=None, section_override_delimiters=(".",), unsavable_keys=("save",)): section_name_surroundings = section_name_surroundings or {"[": "]"} ClosableObject.__init__(self) self.__file_name = file_name self.__file = open(self.__file_name, "w") self.__key_value_delimiters = key_value_delimiters self.__comment_seperators = comment_seperators self.__key_delimiters = key_delimiters self.__section_name_surroundings = section_name_surroundings self.__section_override_delimiters = section_override_delimiters self.__unsavable_keys = unsavable_keys self.__wrote_newline = True self.__closed = False self.__key_delimiter = self.__key_delimiters[0] self.__key_value_delimiter = self.__key_value_delimiters[0] (self.__section_name_surrounding_beg, self.__section_name_surrounding_end) = ( tuple(self.__section_name_surroundings.items())[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()
def __init__(self, user, password, hide_window=True, printer=PrimitiveLogPrinter(), ignore_big_queries=True): """ Creates a new database proxy. :param user: User name. :param password: Password. :param hide_window: Wether or not to show the browser window (showing might be useful for debugging.) :param printer: A PrimitiveLogPrinter which will be used for indicating actions and logging. :param ignore_big_queries: If set to True, queries resulting in more than 3000 results will be ignored. """ ClosableObject.__init__(self) # If an exception occurs later those members have to exist for _close() self.browser = None self.display = None self.tempdir = None # For (primitive) logging self.printer = printer self.ignore_big_queries = ignore_big_queries self.user = user self.password = password if hide_window: with self.printer.do_safe_action( 'Starting virtual display', "Browser window cannot be hidden. You might need to " "install Xvfb. Continuing with visible browser window."): self.display = Display(visible=0) self.display.start() self.tempdir = mkdtemp() self.browser = webdriver.Firefox(DirectDownloadProfile(self.tempdir)) # Retrieve token for this session with self.printer.do_safe_action('Authenticating at Nexis', reraise=True): self.authenticate() sleep(5) self.browser.find_element_by_xpath( '//a[@title="Profisuche"]').click() sleep(10 + random()*5) self.home_url = self.browser.current_url
def __init__(self, file_name, key_value_delimiter='=', 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.__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
def __init__(self, file_name, key_value_delimiter='=', 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.__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
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) self.assertFalse(self.uut._closed) close_objects(self.uut) self.assertTrue(self.uut._closed)
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 __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 subprocess.SubprocessError: # pragma: no cover print("Failed to execute eSpeak. An unknown error occurred. " "This is a bug. We are sorry for the inconvenience. " "Please contact the developers for assistance.") raise EnvironmentError
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
def setUp(self): self.uut = ClosableObject()