Example #1
0
    def _add_urls(self, urllist):
        """
        Add recieved urllist to threadpool
        :param dict urllist: read from dictionary
        :raise KeyboardInterrupt
        :return: None
        """

        try:

            for url in urllist:
                if False is self.__is_ignored(url):
                    self.__pool.add(self.__http_request, url)
                else:
                    self.__catch_report_data('ignored', url)
                    tpl.warning(key='ignored_item',
                                current='{0:0{l}d}'.format(
                                    0,
                                    l=len(str(abs(
                                        self.__reader.total_lines)))),
                                total=self.__reader.total_lines,
                                item=helper.parse_url(url).path)
            self.__pool.join()
        except (SystemExit, KeyboardInterrupt):
            raise KeyboardInterrupt
Example #2
0
    def test_warning_exception(self):
        """ Tpl.warning() exception test """

        undefined = 'undefined'
        with self.assertRaises(TplError) as context:
            Tpl.warning(key=undefined)
        self.assertTrue(undefined in str(context.exception))
        self.assertTrue(TplError == context.expected)
Example #3
0
    def test_warning_exception(self):
        """ Tpl.warning() exception test """

        undefined = 'undefined'
        with self.assertRaises(TplError) as context:
            Tpl.warning(key=undefined)
        self.assertTrue(undefined in str(context.exception))
        self.assertTrue(TplError == context.expected)
Example #4
0
    def __init__(self, Config, total_lines):
        """
        Filter constructor
        :param Config: Config
        :param int total_lines: num lines in list
        """

        if Config.threads > Config.DEFAULT_MAX_THREADS or Config.threads > total_lines:

            max_threads = total_lines if Config.DEFAULT_MAX_THREADS > total_lines else Config.DEFAULT_MAX_THREADS
            tpl.warning(key='thread_limit',
                        threads=Config.threads,
                        max=max_threads)
            Config.set_threads(max_threads)
Example #5
0
    def _add_urls(self, urllist):
        """
        Add received urllist to threadpool
        :param dict urllist: read from dictionary
        :raise KeyboardInterrupt
        :return: None
        """

        try:

            for url in urllist:
                if False is self.__is_ignored(url):
                    self.__pool.add(self.__http_request, url)
                else:
                    self.__catch_report_data('ignored', url)
                    tpl.warning(
                        key='ignored_item',
                        current='{0:0{l}d}'.format(0, l=len(str(abs(self.__reader.total_lines)))),
                        total=self.__reader.total_lines,
                        item=helper.parse_url(url).path
                    )
            self.__pool.join()
        except (SystemExit, KeyboardInterrupt):
            raise KeyboardInterrupt
Example #6
0
    def test_warning(self):
        """ Tpl.warning() test """

        with patch('sys.stdout', new=StringIO()) as fakeOutput:
            Tpl.warning('test_warning')
            self.assertTrue('' in fakeOutput.getvalue().strip())
Example #7
0
    def test_warning(self):
        """ Tpl.warning() test """

        with patch('sys.stdout', new=StringIO()) as fakeOutput:
            Tpl.warning('test_warning')
            self.assertTrue('' in fakeOutput.getvalue().strip())