• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python debug.log_time函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中qutebrowser.utils.debug.log_time函数的典型用法代码示例。如果您正苦于以下问题:Python log_time函数的具体用法?Python log_time怎么用?Python log_time使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了log_time函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _init_url_completion

def _init_url_completion():
    """Initialize the URL completion model."""
    log.completion.debug("Initializing URL completion.")
    with debug.log_time(log.completion, 'URL completion init'):
        model = _init_model(urlmodel.UrlCompletionModel,
                            dumb_sort=Qt.DescendingOrder)
        _instances[usertypes.Completion.url] = model
开发者ID:andor44,项目名称:qutebrowser,代码行数:7,代码来源:instances.py


示例2: action

 def action():
     with debug.log_time(log.init, 'Import old history file to sqlite'):
         try:
             self._read(path)
         except ValueError as ex:
             message.error('Failed to import history: {}'.format(ex))
         else:
             self._write_backup(path)
开发者ID:blyxxyz,项目名称:qutebrowser,代码行数:8,代码来源:history.py


示例3: _update_completion

    def _update_completion(self):
        """Check if completions are available and activate them."""
        if self._ignore_change:
            log.completion.debug("Ignoring completion update because "
                                 "ignore_change is True.")
            self._ignore_change = False
            return

        completion = self.parent()

        if self._cmd.prefix() != ':':
            # This is a search or gibberish, so we don't need to complete
            # anything (yet)
            # FIXME complete searches
            # https://github.com/qutebrowser/qutebrowser/issues/32
            completion.set_model(None)
            self._last_completion_func = None
            return

        before_cursor, pattern, after_cursor = self._partition()

        log.completion.debug("Updating completion: {} {} {}".format(
            before_cursor, pattern, after_cursor))

        pattern = pattern.strip("'\"")
        func = self._get_new_completion(before_cursor, pattern)

        if func is None:
            log.completion.debug('Clearing completion')
            completion.set_model(None)
            self._last_completion_func = None
            return

        if func != self._last_completion_func:
            self._last_completion_func = func
            args = (x for x in before_cursor[1:] if not x.startswith('-'))
            with debug.log_time(log.completion,
                    'Starting {} completion'.format(func.__name__)):
                info = CompletionInfo(config=config.instance,
                                      keyconf=config.key_instance)
                model = func(*args, info=info)
            with debug.log_time(log.completion, 'Set completion model'):
                completion.set_model(model)

        completion.set_pattern(pattern)
开发者ID:nanjekyejoannah,项目名称:qutebrowser,代码行数:45,代码来源:completer.py


示例4: test_logger

    def test_logger(self, caplog):
        """Test with an explicit logger instead of a name."""
        logger_name = 'qt-tests'

        with caplog.at_level(logging.DEBUG, logger_name):
            with debug.log_time(logging.getLogger(logger_name)):
                pass

        assert len(caplog.records) == 1
开发者ID:vyp,项目名称:qutebrowser,代码行数:9,代码来源:test_debug.py


示例5: removeRows

 def removeRows(self, row, _count, _parent=None):
     """Override QAbstractItemModel::removeRows to re-run sql query."""
     # re-run query to reload updated table
     with debug.log_time('sql', 'Re-running completion query post-delete'):
         self._query.run()
     self.setQuery(self._query.query)
     while self.rowCount() < row:
         self.fetchMore()
     return True
开发者ID:mehak,项目名称:qutebrowser,代码行数:9,代码来源:histcategory.py


示例6: set_pattern

 def set_pattern(self, pattern):
     """Set the pattern on the underlying model."""
     if not self.model():
         return
     self.pattern = pattern
     with debug.log_time(log.completion, 'Set pattern {}'.format(pattern)):
         self.model().set_pattern(pattern)
         self.selectionModel().clear()
         self._maybe_update_geometry()
         self._maybe_show()
开发者ID:The-Compiler,项目名称:qutebrowser,代码行数:10,代码来源:completionwidget.py


示例7: historyContains

    def historyContains(self, url_string):
        """Called by WebKit to determine if a URL is contained in the history.

        Args:
            url_string: The URL (as string) to check for.

        Return:
            True if the url is in the history, False otherwise.
        """
        with debug.log_time('sql', 'historyContains'):
            return url_string in self._history
开发者ID:Harrison97,项目名称:qutebrowser,代码行数:11,代码来源:webkithistory.py


示例8: action

 def action():
     with debug.log_time(log.init, 'Import old history file to sqlite'):
         try:
             self._read(path)
         except ValueError as ex:
             message.error('Failed to import history: {}'.format(ex))
         else:
             bakpath = path + '.bak'
             message.info('History import complete. Moving {} to {}'
                          .format(path, bakpath))
             os.rename(path, bakpath)
开发者ID:swalladge,项目名称:qutebrowser,代码行数:11,代码来源:history.py


示例9: _init_late_modules

def _init_late_modules(args):
    """Initialize modules which can be inited after the window is shown."""
    log.init.debug("Reading web history...")
    reader = objreg.get("web-history").async_read()
    with debug.log_time(log.init, "Reading history"):
        while True:
            QApplication.processEvents()
            try:
                next(reader)
            except StopIteration:
                break
            except (OSError, UnicodeDecodeError) as e:
                error.handle_fatal_exc(e, args, "Error while initializing!", pre_text="Error while initializing")
                sys.exit(usertypes.Exit.err_init)
开发者ID:Link-Satonaka,项目名称:qutebrowser,代码行数:14,代码来源:app.py


示例10: set_pattern

    def set_pattern(self, pattern):
        """Set the pattern used to filter results.

        Args:
            pattern: string pattern to filter by.
        """
        # escape to treat a user input % or _ as a literal, not a wildcard
        pattern = pattern.replace('%', '\\%')
        pattern = pattern.replace('_', '\\_')
        words = ['%{}%'.format(w) for w in pattern.split(' ')]

        # build a where clause to match all of the words in any order
        # given the search term "a b", the WHERE clause would be:
        # (url LIKE '%a%' OR title LIKE '%a%') AND
        # (url LIKE '%b%' OR title LIKE '%b%')
        where_clause = ' AND '.join(
            "(url LIKE :{val} escape '\\' OR title LIKE :{val} escape '\\')"
            .format(val=i) for i in range(len(words)))

        # replace ' in timestamp-format to avoid breaking the query
        timestamp_format = config.val.completion.timestamp_format or ''
        timefmt = ("strftime('{}', last_atime, 'unixepoch', 'localtime')"
                   .format(timestamp_format.replace("'", "`")))

        try:
            if (not self._query or
                    len(words) != len(self._query.bound_values())):
                # if the number of words changed, we need to generate a new
                # query otherwise, we can reuse the prepared query for
                # performance
                self._query = sql.Query(' '.join([
                    "SELECT url, title, {}".format(timefmt),
                    "FROM CompletionHistory",
                    # the incoming pattern will have literal % and _ escaped we
                    # need to tell SQL to treat '\' as an escape character
                    'WHERE ({})'.format(where_clause),
                    self._atime_expr(),
                    "ORDER BY last_atime DESC",
                ]), forward_only=False)

            with debug.log_time('sql', 'Running completion query'):
                self._query.run(**{
                    str(i): w for i, w in enumerate(words)})
        except sql.KnownError as e:
            # Sometimes, the query we built up was invalid, for example,
            # due to a large amount of words.
            # Also catches failures in the DB we can't solve.
            message.error("Error with SQL query: {}".format(e.text()))
            return
        self.setQuery(self._query.query)
开发者ID:The-Compiler,项目名称:qutebrowser,代码行数:50,代码来源:histcategory.py


示例11: test_duration

    def test_duration(self, caplog):
        logger_name = 'qt-tests'

        with caplog.at_level(logging.DEBUG, logger_name):
            with debug.log_time(logger_name, action='foobar'):
                time.sleep(0.1)

            assert len(caplog.records) == 1

            pattern = re.compile(r'^Foobar took ([\d.]*) seconds\.$')
            match = pattern.match(caplog.records[0].msg)
            assert match

            duration = float(match.group(1))
            assert 0 < duration < 30
开发者ID:vyp,项目名称:qutebrowser,代码行数:15,代码来源:test_debug.py


示例12: set_pattern

    def set_pattern(self, val):
        """Setter for pattern.

        Invalidates the filter and re-sorts the model.

        Args:
            val: The value to set.
        """
        with debug.log_time(log.completion, 'Setting filter pattern'):
            self.pattern = val
            val = re.escape(val)
            val = val.replace(r'\ ', r'.*')
            self.pattern_re = re.compile(val, re.IGNORECASE)
            self.invalidate()
            sortcol = 0
            self.sort(sortcol)
开发者ID:addictedtoflames,项目名称:qutebrowser,代码行数:16,代码来源:sortfilter.py


示例13: test_duration

    def test_duration(self, caplog):
        logger_name = "qt-tests"

        with caplog.atLevel(logging.DEBUG, logger_name):
            with debug.log_time(logger_name, action="foobar"):
                time.sleep(0.1)

            records = caplog.records()
            assert len(records) == 1

            pattern = re.compile(r"^Foobar took ([\d.]*) seconds\.$")
            match = pattern.match(records[0].msg)
            assert match

            duration = float(match.group(1))
            assert 0 < duration < 30
开发者ID:Kingdread,项目名称:qutebrowser,代码行数:16,代码来源:test_debug.py


示例14: set_pattern

    def set_pattern(self, val):
        """Setter for pattern.

        Invalidates the filter and re-sorts the model.

        Args:
            val: The value to set.
        """
        with debug.log_time(log.completion, "Setting filter pattern"):
            # empty value clears cache (not necessary for correctness, but
            # helps with keeping memory requirements relatively low)
            if not val:
                self.srcmodel.filtered_out_cache = {}
            self.pattern = val
            self.invalidate()
            sortcol = 0
            self.sort(sortcol)
开发者ID:lahwaacz,项目名称:qutebrowser,代码行数:17,代码来源:sortfilter.py


示例15: test_log_time

def test_log_time(caplog):
    """Test if log_time logs properly."""
    logger_name = 'qt-tests'

    with caplog.atLevel(logging.DEBUG, logger=logger_name):
        with debug.log_time(logging.getLogger(logger_name), action='foobar'):
            time.sleep(0.1)

        records = caplog.records()
        assert len(records) == 1

        pattern = re.compile(r'^Foobar took ([\d.]*) seconds\.$')
        match = pattern.match(records[0].msg)
        assert match

        duration = float(match.group(1))
        assert 0.08 <= duration <= 0.12
开发者ID:baskervald,项目名称:qutebrowser,代码行数:17,代码来源:test_log_time.py


示例16: set_pattern

    def set_pattern(self, val):
        """Setter for pattern.

        Invalidates the filter and re-sorts the model.

        If the current completion model overrides sort(), it is used.
        If not, the default implementation in QCompletionFilterModel is called.

        Args:
            val: The value to set.
        """
        with debug.log_time(log.completion, 'Setting filter pattern'):
            self.pattern = val
            self.invalidateFilter()
            sortcol = 0
            try:
                self.srcmodel.sort(sortcol)
            except NotImplementedError:
                self.sort(sortcol)
            self.invalidate()
开发者ID:B0073D,项目名称:qutebrowser,代码行数:20,代码来源:sortfilter.py


示例17: set_pattern

    def set_pattern(self, pattern):
        """Set the pattern used to filter results.

        Args:
            pattern: string pattern to filter by.
        """
        # escape to treat a user input % or _ as a literal, not a wildcard
        pattern = pattern.replace('%', '\\%')
        pattern = pattern.replace('_', '\\_')
        words = ['%{}%'.format(w) for w in pattern.split(' ')]

        # build a where clause to match all of the words in any order
        # given the search term "a b", the WHERE clause would be:
        # ((url || ' ' || title) LIKE '%a%') AND
        # ((url || ' ' || title) LIKE '%b%')
        where_clause = ' AND '.join(
            "(url || ' ' || title) LIKE :{} escape '\\'".format(i)
            for i in range(len(words)))

        # replace ' in timestamp-format to avoid breaking the query
        timestamp_format = config.val.completion.timestamp_format or ''
        timefmt = ("strftime('{}', last_atime, 'unixepoch', 'localtime')"
                   .format(timestamp_format.replace("'", "`")))

        if not self._query or len(words) != len(self._query.bound_values()):
            # if the number of words changed, we need to generate a new query
            # otherwise, we can reuse the prepared query for performance
            self._query = sql.Query(' '.join([
                "SELECT url, title, {}".format(timefmt),
                "FROM CompletionHistory",
                # the incoming pattern will have literal % and _ escaped
                # we need to tell sql to treat '\' as an escape character
                'WHERE ({})'.format(where_clause),
                self._atime_expr(),
                "ORDER BY last_atime DESC",
            ]), forward_only=False)

        with debug.log_time('sql', 'Running completion query'):
            self._query.run(**{
                str(i): w for i, w in enumerate(words)})
        self.setQuery(self._query.query)
开发者ID:mehak,项目名称:qutebrowser,代码行数:41,代码来源:histcategory.py


示例18: set_pattern

    def set_pattern(self, val):
        """Setter for pattern.

        Invalidates the filter and re-sorts the model.

        If the current completion model overrides sort(), it is used.
        If not, the default implementation in QCompletionFilterModel is called.

        Args:
            val: The value to set.
        """
        with debug.log_time(log.completion, 'Setting filter pattern'):
            self.pattern = val
            val = re.escape(val)
            val = val.replace(r'\ ', r'.*')
            self.pattern_re = re.compile(val, re.IGNORECASE)
            self.invalidateFilter()
            sortcol = 0
            if hasattr(self.srcmodel, 'sort'):
                self.srcmodel.sort(sortcol)
            else:
                self.sort(sortcol)
            self.invalidate()
开发者ID:krobelus,项目名称:qutebrowser,代码行数:23,代码来源:sortfilter.py


示例19: _init_tab_completion

def _init_tab_completion():
    """Initialize the tab completion model."""
    log.completion.debug("Initializing tab completion.")
    with debug.log_time(log.completion, 'tab completion init'):
        model = miscmodels.TabCompletionModel()
        _instances[usertypes.Completion.tab] = model
开发者ID:Dietr1ch,项目名称:qutebrowser,代码行数:6,代码来源:instances.py


示例20: _init_url_completion

def _init_url_completion():
    """Initialize the URL completion model."""
    log.completion.debug("Initializing URL completion.")
    with debug.log_time(log.completion, 'URL completion init'):
        model = urlmodel.UrlCompletionModel()
        _instances[usertypes.Completion.url] = model
开发者ID:Dietr1ch,项目名称:qutebrowser,代码行数:6,代码来源:instances.py



注:本文中的qutebrowser.utils.debug.log_time函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python debug.qenum_key函数代码示例发布时间:2022-05-26
下一篇:
Python debug.get_all_objects函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap