本文整理汇总了Python中trac.mimeview.api.Mimeview.to_unicode方法的典型用法代码示例。如果您正苦于以下问题:Python Mimeview.to_unicode方法的具体用法?Python Mimeview.to_unicode怎么用?Python Mimeview.to_unicode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trac.mimeview.api.Mimeview
的用法示例。
在下文中一共展示了Mimeview.to_unicode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_search_results
# 需要导入模块: from trac.mimeview.api import Mimeview [as 别名]
# 或者: from trac.mimeview.api.Mimeview import to_unicode [as 别名]
def get_search_results(self, req, query, filters):
if 'repo' not in filters:
return
for filename, reponame in self.search_backend.find_words(query):
repo = self.env.get_repository(reponame=reponame, authname=req.authname)
node = repo.get_node(filename)
if node.kind == Node.DIRECTORY:
yield (self.env.href.browser(reponame, filename),
"%s (in %s)" % (filename, reponame), change.date, change.author,
'Directory')
else:
found = 0
mimeview = Mimeview(self.env)
content = mimeview.to_unicode(node.get_content().read(), node.get_content_type())
for n, line in enumerate(content.splitlines()):
line = line.lower()
for q in query:
idx = line.find(q)
if idx != -1:
found = n + 1
break
if found:
break
change = repo.get_changeset(node.rev)
yield (self.env.href.browser(reponame, filename
) + (found and '#L%i' % found or ''
),
"%s (in %s)" % (filename, reponame), change.date, change.author,
shorten_result(content, query))