Exemplo n.º 1
0
    def debug_request_uri(self, status, request_uri, **kwargs):
        """
        Debug request_uri
        :param str status: response status
        :param str request_uri: http request uri
        :param mixed kwargs:
        :return: bool
        """

        percentage = tpl.line(
            msg=helper.percent(kwargs.get('items_size', 0), kwargs.get('total_size', 1)),
            color='cyan')
        total_len = len(str(abs(kwargs.get('total_size', 1))))

        if self.__cfg.DEFAULT_SCAN is self.__cfg.scan:
            urlpath = helper.parse_url(request_uri).path
        else:
            urlpath = request_uri
        
        if status in ['success', 'file', 'indexof', 'certificat', 'auth']:
            request_uri = tpl.line(key=status, color='green', url=urlpath)
        elif status in ['bad', 'forbidden']:
            request_uri = tpl.line(key='forbidden', color='yellow', url=urlpath)
        elif status in ['redirect']:
            request_uri = tpl.line(key='redirect', color='blue', url=urlpath,
                                   rurl=kwargs.get('redirect_uri'))

        self.__clear = True if self.__catched else False

        if status in ['success', 'file', 'bad', 'forbidden', 'redirect', 'indexof', 'certificat', 'auth']:

            sys.writels("", flush=True)
            tpl.info(key='get_item',
                     clear=self.__clear,
                     percent=percentage,
                     current='{0:0{l}d}'.format(kwargs.get('items_size', 0), l=total_len),
                     total=kwargs.get('total_size', 1),
                     item=request_uri,
                     size=kwargs.get('content_size')
                     )
            self.__catched = True
        else:
            tpl.line_log(key='get_item',
                         percent=percentage,
                         current='{0:0{l}d}'.format(kwargs.get('items_size', 0), l=total_len),
                         total=kwargs.get('total_size', 1),
                         item=request_uri,
                         size=kwargs.get('content_size'),
                         )
            self.__catched = False
            if kwargs.get('items_size', 0) is kwargs.get('total_size', 1):
                sys.writels("", flush=True)

        return True
Exemplo n.º 2
0
    def info(msg='', key='', clear=False, **args):
        """
        Info log message
        :param str msg: text message
        :param str key: message key for template
        :param mixed args: additional arguments
        :param bool clear: clear prev line
        :raise TplError
        :return: None
        """

        msg = str(msg)

        try:
            if key:
                msg = Tpl.__format_message(key, args=args)
            if True is clear:
                sys.writels("")
            logger.log('info').info(msg)
        except (AttributeError, TplError) as error:
            raise TplError(error)
Exemplo n.º 3
0
    def info(msg='', key='', clear=False, **args):
        """
        Info log message
        :param str msg: text message
        :param str key: message key for template
        :param mixed args: additional arguments
        :param bool clear: clear prev line
        :raise TplError
        :return: None
        """

        msg = str(msg)

        try:
            if key:
                msg = Tpl.__format_message(key, args=args)
            if True is clear:
                sys.writels("")
            logger.log('info').info(msg)
        except (AttributeError, TplError) as error:
            raise TplError(error)
Exemplo n.º 4
0
    def line_log(msg='', key='', status='info', write=True, **args):
        """
        Stored colored log line to variable
        :param str msg: text message
        :param str key: message key for template
        :param str status: log status
        :param bool write: write immediatelly
        :param mixed args: additional arguments
        :raise TplError
        :return: None
        """

        try:
            if key:
                msg = Tpl.__format_message(key, args=args)
                msg = logger.inline(msg=msg, status=status)
            if True is write:
                sys.writels(msg)
            else:
                return msg
        except (AttributeError, TplError) as error:
            raise TplError(error)
Exemplo n.º 5
0
    def line_log(msg='', key='', status='info', write=True, **args):
        """
        Stored colored log line to variable
        :param str msg: text message
        :param str key: message key for template
        :param str status: log status
        :param bool write: write immediatelly
        :param mixed args: additional arguments
        :raise TplError
        :return: None
        """

        try:
            if key:
                msg = Tpl.__format_message(key, args=args)
                msg = logger.inline(msg=msg, status=status)
            if True is write:
                sys.writels(msg)
            else:
                return msg
        except (AttributeError, TplError) as error:
            raise TplError(error)