Exemplo n.º 1
0
    def __set_default_server(self):
        server = None
        if(self.__config.get('type').lower() == 'smtp'):
            if any(self.__config.get('host').lower() in s for s in ['localhost', '127.0.0.1']):
                server = smtplib.SMTP(self.__config.get('host'))
            elif ( HelperMethods.string_is_not_empty(self.__config.get('host')) and HelperMethods.string_is_not_empty(self.__config.get('host')) ):
                # server = smtplib.SMTP(self.__config.get('host'),self.__config.get('port'))
                if ( HelperMethods.string_is_not_empty(self.__config.get('username')) and HelperMethods.string_is_not_empty(self.__config.get('password')) ):
                    # TODO make username/password/login type email sending work
                    raise NotImplementedError("Configuration with username and password isn\'t yet implemented and tested ")

                    server = smtplib.SMTP(self.__config.get('host'),self.__config.get('port'))
                    server.starttls()
                    # server.connect(self.__config.get('host'),self.__config.get('port'))
                    server.login(self.__config.get('username'), self.__config.get('password'))
                else:
                    server = smtplib.SMTP()
                    server.connect(self.__config.get('host'),self.__config.get('port'))
            else:
                raise NotImplementedError("This Email Configuration isn\'t supported.")
                pass

        self.__server=server
Exemplo n.º 2
0
    def execute_query(self, query = ""):
        """
        The function executes the given query and returns the cursor.

        :param query: The query that will be executed
        :type query: str
        :rtype :object - mysql.connector.cursor
        """
        cursor = None
        if HelperMethods.string_is_not_empty(query):
            cursor = self.connection.cursor()
            try:
                cursor.execute(query)
            except (DatabaseException, Exception) as e:
                # open space for possible error handling
                raise
        return cursor
Exemplo n.º 3
0
    def execute_query(self, query=""):
        """
        The function executes the given query and returns the cursor.

        :param query: The query that will be executed
        :type query: str
        :rtype :object - mysql.connector.cursor
        """
        cursor = None
        if HelperMethods.string_is_not_empty(query):
            cursor = self.connection.cursor()
            try:
                cursor.execute(query)
            except (DatabaseException, Exception) as e:
                # open space for possible error handling
                raise
        return cursor