本文整理匯總了Python中zim.fs.File.isimage方法的典型用法代碼示例。如果您正苦於以下問題:Python File.isimage方法的具體用法?Python File.isimage怎麽用?Python File.isimage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類zim.fs.File
的用法示例。
在下文中一共展示了File.isimage方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _link_tree
# 需要導入模塊: from zim.fs import File [as 別名]
# 或者: from zim.fs.File import isimage [as 別名]
def _link_tree(links, notebook, path):
# Convert a list of links (of any type) into a parsetree
#~ print 'LINKS: ', links
#~ print 'NOTEBOOK and PATH:', notebook, path
builder = TreeBuilder()
builder.start('zim-tree')
for i in range(len(links)):
if i > 0:
builder.data(' ')
link = links[i]
type = link_type(link)
isimage = False
if type == 'file':
try:
file = File(link)
isimage = file.isimage()
except:
pass
logger.debug('Pasting link: %s (type: %s, isimage: %s)', link, type, isimage)
if isimage:
src = notebook.relative_filepath(file, path) or file.uri
builder.start('img', {'src': src})
builder.end('img')
elif link.startswith('@'):
# FIXME - is this ever used ??
builder.start('tag', {'name': links[i][1:]})
builder.data(links[i])
builder.end('tag')
else:
if type == 'page':
href = Path(notebook.cleanup_pathname(link)) # Assume links are always absolute
link = notebook.relative_link(path, href) or link
elif type == 'file':
file = File(link) # Assume links are always URIs
link = notebook.relative_filepath(file, path) or file.uri
builder.start('link', {'href': link})
builder.data(link)
builder.end('link')
builder.end('zim-tree')
tree = ParseTree(builder.close())
tree.resolve_images(notebook, path)
tree.decode_urls()
return tree
示例2: testError
# 需要導入模塊: from zim.fs import File [as 別名]
# 或者: from zim.fs.File import isimage [as 別名]
def testError(self):
def creator_with_failure(*a):
raise ThumbnailCreatorFailure
def creator_with_error(*a):
raise ValueError
file = File('./data/zim.png')
self.assertTrue(file.exists())
self.assertTrue(file.isimage())
for creator in creator_with_failure, creator_with_error:
#~ print ">>", creator.__name__
queue = ThumbnailQueue(creator)
queue.queue_thumbnail_request(file, 64)
with tests.LoggingFilter('zim.plugins.attachmentbrowser', 'Exception'):
queue.start()
while not queue.queue_empty():
r = queue.get_ready_thumbnail()
self.assertIsNone(r[0], None)