Beispiel #1
0
def show(query, number_of_rows = None):
    """Actually sends the given query to the database and returns the resulting
    rows as a list. A wrapper around run_sql.
    If number_of_rows is None, then it checks config settings. For more
    information, see the documentation in the config module.
    """
    if query is None:
        raise ValueError("query cannot be None!")

    run_sql(query)
    # Fetch the correct number of rows
    if number_of_rows is None:
        # Nothing specified, consult config.
        if config.ROWS_TO_SHOW == config.ALL_ROWS:
            return cursor.fetchall()
        else:
            if util.is_integer(config.ROWS_TO_SHOW):
                fetched_rows = cursor.fetchmany(config.ROWS_TO_SHOW)
                return fetched_rows
            else:
                raise ValueError("number_of_rows (%d) is not an int!" % number_of_rows)
    else:
        if util.is_integer(number_of_rows):
            fetched_rows = cursor.fetchmany(int(number_of_rows))
            return fetched_rows
        else:
            raise ValueError("number_of_rows (%d) is not an int!" % number_of_rows)
Beispiel #2
0
 def test_is_integer(self):
     self.assertTrue(util.is_integer("4"))
     self.assertTrue(util.is_integer("-4"))
     self.assertTrue(util.is_integer("+4"))
     self.assertFalse(util.is_integer("4.5"))
     self.assertFalse(util.is_integer("-4.5"))
     self.assertFalse(util.is_integer("+4.5"))
     self.assertFalse(util.is_integer("gooogly moogly"))
     self.assertFalse(util.is_integer(None))
     self.assertFalse(util.is_integer(""))
 def state_searchforsubstitute(self):
     """Show the screen allowing the user
     to choose a substitute for a specific
     food.
     """
     self.dt.get_aliment(self.currentProduct)
     print(self.dt.this_aliment_stringed + "\n\n")
     self.dt.get_all_substitutes(self.currentProduct, self.currentCategory,
                                 self.dt.this_aliment[4])
     print(self.dt.all_substitutes_stringed)
     user_input = input(
         "Entrez le chiffre correspondant au substitut désiré, R pour retourner à l'écran précédent, ou Q pour quitter le programme\n"
     )
     if is_integer(user_input):
         if 1 <= int(user_input) <= len(self.dt.all_substitutes) + 1:
             self.currentSubstitute = self.dt.all_substitutes[
                 int(user_input) - 1]
             self.state = States.OnFoundSubstitute
         else:
             print("Nombre invalide ! Réessayez\n")
     else:
         if user_input.lower() == "q":
             self.state = States.Bye
         elif user_input.lower() == "r":
             self.state = States.SearchForAliment
         else:
             print("Commande invalide, réessayez!\n")
 def state_searchforaliment(self):
     """Show the screen allowing the user
     to choose a food from a category.
     """
     self.dt.get_all_aliments_from_category(self.currentCategory)
     print("Bienvenue dans la catégorie " + self.currentCategory + "\n")
     print(self.dt.all_aliments_from_category_stringed)
     user_input = input(
         "Entrez le chiffre correspondant au produit désiré, R pour retourner à l'écran précédent, ou Q pour quitter le programme\n"
     )
     if is_integer(user_input):
         if 1 <= int(user_input) <= len(
                 self.dt.all_aliments_from_category) + 1:
             self.currentProduct = self.dt.all_aliments_from_category[
                 int(user_input) - 1]
             self.state = States.SearchForSubstitute
         else:
             print("Nombre invalide ! Réessayez\n")
     else:
         if user_input.lower() == "q":
             self.state = States.Bye
         elif user_input.lower() == "r":
             self.state = States.SearchForCategory
         else:
             print("Commande invalide, réessayez!\n")
Beispiel #5
0
 def _check_type(self, value):
     type_ = self.__getitem__('Properties')['ReadingType']
     if type_ == 'long' and util.is_integer(value):
         return True
     elif type_ == 'double' and \
             isinstance(value, float):
         return True
     else:
         return False
Beispiel #6
0
 def _check_type(self, value):
     type_ = self.__getitem__('Properties')['ReadingType']
     if type_ == 'long' and util.is_integer(value):
         return True
     elif type_ == 'double' and \
             isinstance(value, float):
         return True
     else:
         return False
Beispiel #7
0
    def default(self, line):
        command, arg, line = self.parseline(line)

        if command == 'EOF':
            print()

        if command in self.aliases:
            return self.aliases[command](arg)
        elif util.is_integer(line):
            return self.do_mark(line)
        else:
            print(self.UNKNOWN_SYNTAX + line)
Beispiel #8
0
    def __call__(self, *args, **kwargs):
        allowed = False
        rv = None
        now = time.time()
        if (callable(self.ratelimit) and self.ratelimit()) or \
                (util.is_integer(self.ratelimit) and \
                     now - self.last_call > self.ratelimit):
            allowed = True
            if self.method_if_allowed:
                rv = self.method_if_allowed(*args, **kwargs)
            self.last_call = now
        elif self.method_if_disallowed:
            rv = self.method_if_disallowed(*args, **kwargs)

        return allowed, rv
 def state_searchforcategory(self):
     """Show the screen allowing the user
     to choose a category of food.
     """
     print("Voici les substituts mis à votre disposition:\n")
     print(self.dt.all_categories_stringed)
     user_input = input(
         "Entrez le chiffre correspondant à la catégorie désirée, R pour retourner à l'écran précédent, ou Q pour quitter le programme\n"
     )
     if is_integer(user_input):
         if 1 <= int(user_input) <= len(self.dt.all_categories) + 1:
             self.currentCategory = self.dt.all_categories[int(user_input) -
                                                           1]
             self.state = States.SearchForAliment
         else:
             print("Nombre invalide ! Réessayez\n")
     else:
         if user_input.lower() == "q":
             self.state = States.Bye
         elif user_input.lower() == "r":
             self.state = States.LaunchScreen
         else:
             print("Commande invalide, réessayez!\n")
 def state_lookatsubstitutes(self):
     """Show the screen listing every
     combination of food/substitute
     previously registered.
     """
     self.dt.update_my_associations()
     print(self.dt.all_associations_stringed)
     user_input = input(
         "Entrez le chiffre correspondant au substitut désiré, R pour retourner à l'écran précédent, ou Q pour quitter le programme\n"
     )
     if is_integer(user_input):
         if 1 <= int(user_input) <= len(self.dt.all_associations) + 1:
             self.currentAssociation = self.dt.all_associations[
                 int(user_input) - 1]
             self.state = States.LookAtOneSubstitute
         else:
             print("Nombre invalide ! Réessayez\n")
     else:
         if user_input.lower() == "q":
             self.state = States.Bye
         elif user_input.lower() == "r":
             self.state = States.LaunchScreen
         else:
             print("Commande invalide, réessayez!\n")
Beispiel #11
0
 def test_neg_integers( self ):
     self.assertFalse( util.is_integer( "1234" ) )
     self.assertFalse( util.is_integer( [1,2,3] ) )
Beispiel #12
0
 def test_positive_types( self ):
     self.assertTrue( util.is_string( "abcd" ) )
     self.assertTrue( util.is_boolean( True ) )
     self.assertTrue( util.is_integer( 1234 ) )
     self.assertTrue( util.is_list( [1,2,3,4]) )
     self.assertTrue( util.is_dict( {"foo":"bar"} ) )