Exemplo n.º 1
0
 def test_1(self):
     is_type(str, "asf", "test_1")
     try:
         is_type(str, 1, "test_1")
         self.fail("No error")
     except ValueError:
         pass
Exemplo n.º 2
0
    def __load_modules(self):
        self.logger.info("Loading modules")
        self.listModules = []
        self.listCommandsWithDesc = []
        files = [os.path.splitext(f)[0] for f in os.listdir("modules")
                 if f.startswith("mod_") and f.endswith(".py") and f not in self.listExclusion]
        for file in files:
            try:
                modules = __import__("modules.%s" % file, globals(), locals(), fromlist=["*"])
                for module_name in [m for m in dir(modules)
                                    if m.startswith("Module") and not m.startswith("ModuleBase")]:
                    try:
                        self.logger.debug("Loading module %s", module_name)
                        module = getattr(modules, module_name)(self)
                        is_type(module_base.ModuleBase, module, module_name)
                        self.listModules.append(module)
                        self.listCommandsWithDesc.extend(module.get_commands())
                        self.logger.debug("Loaded module %s", module_name)
                    except:
                        self.logger.exception("Fail to load module %s", module_name, exc_info=True)
            except:
                self.logger.exception("Fail to load file %s", file, exc_info=True)

        self.listCommandsWithDesc.sort(key=lambda tup: tup[0])
        self.listCommands = tuple([tup[0] for tup in self.listCommandsWithDesc])
        self.logger.debug("listCommands %s", repr(self.listCommands))
        self.commandParser = CommandParser(self.listCommands)
Exemplo n.º 3
0
 def test_1(self):
     is_type(str, "asf", "test_1")
     try:
         is_type(str, 1, "test_1")
         self.fail("No error")
     except ValueError:
         pass
Exemplo n.º 4
0
 def test_2(self):
     is_type(int, 1, "test_2")
     try:
         is_type(int, "a", "test_2")
         self.fail("No error")
     except ValueError:
         pass
Exemplo n.º 5
0
 def test_2(self):
     is_type(int, 1, "test_2")
     try:
         is_type(int, "a", "test_2")
         self.fail("No error")
     except ValueError:
         pass
 def get_image(self, query_result):
     is_type(ImageQuery, query_result, query_result)
     try:
         i = query_result.next_index()
         search_url = self.URL % (query_result.query(), i)
         self.logger.info("search_url '%s'", search_url)
         response = requests.get(search_url)
         self.logger.debug("Response %s", response.text)
         obj_json = response.json()
         self.logger.debug("Json %s", obj_json)
         return obj_json["results"][0]["image"]
     except:
         self.logger.exception("Fail query '%s'", query_result.query(), exc_info=True)
         return False
Exemplo n.º 7
0
    def next(self, user, amount=1):
        is_type(dict, user, "user")
        is_type(int, amount, "amout")
        u = self.get_user(user)

        #clear old tiems
        now = datetime.now()
        u.items = list([i for i in u.items if now - i <= self.delta])

        if len(u.items) + amount > self.per_time_unit:
            raise LimitatorLimitted()
        else:
            for i in range(amount):
                u.items.append(now)
Exemplo n.º 8
0
 def get_image(self, query_result):
     is_type(ImageQuery, query_result, query_result)
     try:
         i = query_result.next_index()
         search_url = self.URL % (query_result.query(), i)
         self.logger.info("search_url '%s'", search_url)
         response = requests.get(search_url)
         self.logger.debug("Response %s", response.text)
         obj_json = response.json()
         self.logger.debug("Json %s", obj_json)
         return obj_json["results"][0]["image"]
     except:
         self.logger.exception("Fail query '%s'",
                               query_result.query(),
                               exc_info=True)
         return False
Exemplo n.º 9
0
 def __init__(self, per_time_unit, time_unit_seconds, per_user=False):
     is_type(int, per_time_unit, "per_time_unit")
     is_type(int, time_unit_seconds, "time_unit_seconds")
     is_type(int, per_user, "per_user")
     self.delta = timedelta(seconds=time_unit_seconds)
     self.per_time_unit = per_time_unit
     self.per_user = per_user
     self.users = None
     self.allUser = None
     self.clear()
Exemplo n.º 10
0
 def test_1(self):
     b = Bullshit()
     for i in range(self.N):
         s = next(b)
         is_type(str, s, "s")
Exemplo n.º 11
0
 def test_3(self):
     b = Bullshit()
     for i in range(self.N):
         s = b.__next__()
         is_type(str, s, "s")
Exemplo n.º 12
0
 def test_2(self):
     b = Bullshit()
     for i in range(self.N):
         s = b.next()
         is_type(str, s, "s")
Exemplo n.º 13
0
 def __init__(self, *args):
     [is_type(ILimitator, a, "args") for a in args]
     self.limitators = list(args)