本文整理汇总了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;未经允许,请勿转载。 |
请发表评论