本文整理汇总了Python中MoinMoin.action.AttachFile.getAttachUrl方法的典型用法代码示例。如果您正苦于以下问题:Python AttachFile.getAttachUrl方法的具体用法?Python AttachFile.getAttachUrl怎么用?Python AttachFile.getAttachUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MoinMoin.action.AttachFile
的用法示例。
在下文中一共展示了AttachFile.getAttachUrl方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: visit_image
# 需要导入模块: from MoinMoin.action import AttachFile [as 别名]
# 或者: from MoinMoin.action.AttachFile import getAttachUrl [as 别名]
def visit_image(self, node):
"""
Need to intervene in the case of inline images. We need MoinMoin to
give us the actual src line to the image and then we can feed this
to the default html4css1 writer. NOTE: Since the writer can't "open"
this image the scale attribute doesn't work without directly
specifying the height or width (or both).
TODO: Need to handle figures similarly.
"""
uri = node['uri'].lstrip()
prefix = '' # assume no prefix
attach_name = uri
if ':' in uri:
prefix = uri.split(':', 1)[0]
attach_name = uri.split(':', 1)[1]
# if prefix isn't URL, try to display in page
if not prefix.lower() in ('file', 'http', 'https', 'ftp'):
if not AttachFile.exists(self.request, self.request.page.page_name, attach_name):
# Attachment doesn't exist, MoinMoin should process it
if prefix == '':
prefix = 'attachment:'
self.process_wiki_text("{{%s%s}}" % (prefix, attach_name))
self.wiki_text = self.fixup_wiki_formatting(self.wiki_text)
self.add_wiki_markup()
# Attachment exists, get a link to it.
# create the url
node['uri'] = AttachFile.getAttachUrl(self.request.page.page_name, attach_name, self.request, addts=1)
if not node.hasattr('alt'):
node['alt'] = node.get('name', uri)
html4css1.HTMLTranslator.visit_image(self, node)
示例2: attachment_link
# 需要导入模块: from MoinMoin.action import AttachFile [as 别名]
# 或者: from MoinMoin.action.AttachFile import getAttachUrl [as 别名]
def attachment_link(self, url, text, **kw):
_ = self.request.getText
pagename = self.page.page_name
target = AttachFile.getAttachUrl(pagename, url, self.request)
return (self.url(1, target, title="attachment:%s" % wikiutil.quoteWikinameURL(url)) +
self.text(text) +
self.url(0))
示例3: test_getAttachUrl
# 需要导入模块: from MoinMoin.action import AttachFile [as 别名]
# 或者: from MoinMoin.action.AttachFile import getAttachUrl [as 别名]
def test_getAttachUrl(self):
"""
Tests if AttachFile.getAttachUrl taints a filename
"""
filename = "<test2.txt>"
expect = "rename=_test2.txt_&"
result = AttachFile.getAttachUrl(self.pagename, filename, self.request, upload=True)
assert expect in result
示例4: attachment_drawing
# 需要导入模块: from MoinMoin.action import AttachFile [as 别名]
# 或者: from MoinMoin.action.AttachFile import getAttachUrl [as 别名]
def attachment_drawing(self, url, text, **kw):
_ = self.request.getText
pagename = self.page.page_name
image = url + u'.png'
fname = wikiutil.taintfilename(image)
fpath = AttachFile.getFilename(self.request, pagename, fname)
return self.image(
title="drawing:%s" % wikiutil.quoteWikinameURL(url),
src=AttachFile.getAttachUrl(pagename, image, self.request, addts=1))
示例5: attachment_link
# 需要导入模块: from MoinMoin.action import AttachFile [as 别名]
# 或者: from MoinMoin.action.AttachFile import getAttachUrl [as 别名]
def attachment_link(self, on, url=None, **kw):
assert on in (0, 1, False, True) # make sure we get called the new way, not like the 1.5 api was
# we do not output a "upload link" when outputting docbook
if on:
pagename, filename = AttachFile.absoluteName(url, self.page.page_name)
fname = wikiutil.taintfilename(filename)
target = AttachFile.getAttachUrl(pagename, filename, self.request)
return self.url(1, target, title="attachment:%s" % url)
else:
return self.url(0)
示例6: attachment_image
# 需要导入模块: from MoinMoin.action import AttachFile [as 别名]
# 或者: from MoinMoin.action.AttachFile import getAttachUrl [as 别名]
def attachment_image(self, url, **kw):
_ = self.request.getText
# we force the title here, needed later for html>wiki converter
kw['title'] = "attachment:%s" % wikiutil.quoteWikinameURL(url)
pagename = self.page.page_name
if '/' in url:
pagename, target = AttachFile.absoluteName(url, pagename)
url = url.split('/')[-1]
kw['src'] = AttachFile.getAttachUrl(pagename, url, self.request, addts=1)
return self.image(**kw)
示例7: attachment_image
# 需要导入模块: from MoinMoin.action import AttachFile [as 别名]
# 或者: from MoinMoin.action.AttachFile import getAttachUrl [as 别名]
def attachment_image(self, url, **kw):
_ = self.request.getText
pagename, filename = AttachFile.absoluteName(url, self.page.page_name)
fname = wikiutil.taintfilename(filename)
fpath = AttachFile.getFilename(self.request, pagename, fname)
if not os.path.exists(fpath):
return self.text("[attachment:%s]" % url)
else:
return self.image(
title="attachment:%s" % url,
src=AttachFile.getAttachUrl(pagename, filename,
self.request, addts=1))
示例8: attachment_link
# 需要导入模块: from MoinMoin.action import AttachFile [as 别名]
# 或者: from MoinMoin.action.AttachFile import getAttachUrl [as 别名]
def attachment_link(self, url, text, **kw):
_ = self.request.getText
pagename, filename = AttachFile.absoluteName(url, self.page.page_name)
fname = wikiutil.taintfilename(filename)
fpath = AttachFile.getFilename(self.request, pagename, fname)
target = AttachFile.getAttachUrl(pagename, filename, self.request)
if not os.path.exists(fpath):
return self.text("[attachment:%s]" % url)
else:
return (self.url(1, target, title="attachment:%s" % url) +
self.text(text) +
self.url(0))
示例9: attachment_link
# 需要导入模块: from MoinMoin.action import AttachFile [as 别名]
# 或者: from MoinMoin.action.AttachFile import getAttachUrl [as 别名]
def attachment_link(self, on, url=None, **kw):
assert on in (0, 1, False, True) # make sure we get called the new way, not like the 1.5 api was
_ = self.request.getText
querystr = kw.get('querystr', {})
assert isinstance(querystr, dict) # new in 1.6, only support dicts
if 'do' not in querystr:
querystr['do'] = 'view'
if on:
pagename = self.page.page_name
target = AttachFile.getAttachUrl(pagename, url, self.request, do=querystr['do'])
return self.url(on, target, title="attachment:%s" % wikiutil.quoteWikinameURL(url))
else:
return self.url(on)
示例10: attachment_drawing
# 需要导入模块: from MoinMoin.action import AttachFile [as 别名]
# 或者: from MoinMoin.action.AttachFile import getAttachUrl [as 别名]
def attachment_drawing(self, url, text, **kw):
_ = self.request.getText
pagename, filename = AttachFile.absoluteName(url, self.page.page_name)
fname = wikiutil.taintfilename(filename)
drawing = fname
fname = fname + ".png"
filename = filename + ".png"
fpath = AttachFile.getFilename(self.request, pagename, fname)
if not os.path.exists(fpath):
return self.text("{{drawing:%s}}" % url)
else:
src = AttachFile.getAttachUrl(pagename, filename, self.request, addts=1)
return self.image(alt=drawing, src=src, html_class="drawing")
示例11: attachment_drawing
# 需要导入模块: from MoinMoin.action import AttachFile [as 别名]
# 或者: from MoinMoin.action.AttachFile import getAttachUrl [as 别名]
def attachment_drawing(self, url, text, **kw):
_ = self.request.getText
# TODO: this 'text' argument is kind of superfluous, replace by using alt=... kw arg
if 'alt' not in kw or not kw['alt']:
kw['alt'] = text
# we force the title here, needed later for html>wiki converter
kw['title'] = "drawing:%s" % wikiutil.quoteWikinameURL(url)
pagename = self.page.page_name
if '/' in url:
pagename, target = AttachFile.absoluteName(url, pagename)
url = url.split('/')[-1]
url += '.png'
kw['src'] = AttachFile.getAttachUrl(pagename, url, self.request, addts=1)
return self.image(**kw)
示例12: render
# 需要导入模块: from MoinMoin.action import AttachFile [as 别名]
# 或者: from MoinMoin.action.AttachFile import getAttachUrl [as 别名]
def render(self):
_ = self.request.getText
pagename, attname = AttachFile.absoluteName(self.target, self.formatter.page.page_name)
attachment_fname = AttachFile.getFilename(self.request, pagename, attname)
if not os.path.exists(attachment_fname):
linktext = _('Upload new attachment "%(filename)s"')
return wikiutil.link_tag(self.request,
('%s?action=AttachFile&rename=%s' % (
wikiutil.quoteWikinameURL(pagename),
wikiutil.url_quote_plus(attname))),
linktext % {'filename': attname})
url = AttachFile.getAttachUrl(pagename, attname, self.request)
mime_type, enc = mimetypes.guess_type(attname)
if mime_type in ["application/x-shockwave-flash",
"application/x-dvi",
"application/postscript",
"application/pdf",
"application/ogg",
"application/vnd.visio",
"image/x-ms-bmp",
"image/svg+xml",
"image/tiff",
"image/x-photoshop",
"audio/mpeg",
"audio/midi",
"audio/x-wav",
"video/fli",
"video/mpeg",
"video/quicktime",
"video/x-msvideo",
"chemical/x-pdb",
"x-world/x-vrml",
]:
return self.embed(mime_type, url)
else:
msg = 'Not supported mimetype %(mimetype)s ' % {"mimetype": mime_type}
return "%s%s%s" % (self.macro.formatter.sysmsg(1),
self.macro.formatter.text(msg),
self.macro.formatter.sysmsg(0))
示例13: attachment_drawing
# 需要导入模块: from MoinMoin.action import AttachFile [as 别名]
# 或者: from MoinMoin.action.AttachFile import getAttachUrl [as 别名]
def attachment_drawing(self, url, text, **kw):
# This is called for displaying a clickable drawing image by text_html formatter.
# XXX text arg is unused!
_ = self.request.getText
pagename, drawing = AttachFile.absoluteName(url, self.page.page_name)
containername = wikiutil.taintfilename(drawing)
drawing_url = AttachFile.getAttachUrl(pagename, containername, self.request, do='modify')
ci = AttachFile.ContainerItem(self.request, pagename, containername)
if not ci.exists():
title = _('Create new drawing "%(filename)s (opens in new window)"') % {'filename': self.text(containername)}
img = self.icon('attachimg') # TODO: we need a new "drawimg" in similar grey style and size
css = 'nonexistent'
return self.url(1, drawing_url, css=css, title=title) + img + self.url(0)
title = _('Edit drawing %(filename)s (opens in new window)') % {'filename': self.text(containername)}
kw['src'] = src = ci.member_url('drawing.png')
kw['css'] = 'drawing'
try:
mapfile = ci.get('drawing.map')
map = mapfile.read()
mapfile.close()
map = map.decode(config.charset)
except (KeyError, IOError, OSError):
map = u''
if map:
# we have a image map. inline it and add a map ref to the img tag
# we have also to set a unique ID
mapid = u'ImageMapOf%s%s' % (self.request.uid_generator(pagename), drawing)
map = map.replace(u'%MAPNAME%', mapid)
# add alt and title tags to areas
map = re.sub(ur'href\s*=\s*"((?!%TWIKIDRAW%).+?)"', ur'href="\1" alt="\1" title="\1"', map)
map = map.replace(u'%TWIKIDRAW%"', u'%s" alt="%s" title="%s"' % (
wikiutil.escape(drawing_url, 1), title, title))
# unxml, because 4.01 concrete will not validate />
map = map.replace(u'/>', u'>')
title = _('Clickable drawing: %(filename)s') % {'filename': self.text(containername)}
if 'title' not in kw:
kw['title'] = title
if 'alt' not in kw:
kw['alt'] = kw['title']
kw['usemap'] = '#'+mapid
return self.url(1, drawing_url) + map + self.image(**kw) + self.url(0)
else:
if 'title' not in kw:
kw['title'] = title
if 'alt' not in kw:
kw['alt'] = kw['title']
return self.url(1, drawing_url) + self.image(**kw) + self.url(0)
示例14: get_attachment_dict
# 需要导入模块: from MoinMoin.action import AttachFile [as 别名]
# 或者: from MoinMoin.action.AttachFile import getAttachUrl [as 别名]
def get_attachment_dict(self, page_name):
""" Returns a dict of attachments
The structure of the dictionary is:
{ file_name : [file_size, get_url], ... }
@param page_name:
@rtype: attachments dictionary
@return: attachments dictionary
"""
attach_dir = AttachFile.getAttachDir(self.request, page_name)
files = AttachFile._get_files(self.request, page_name)
attachments = {}
for file in files:
fsize = float(os.stat(os.path.join(attach_dir,file).encode(config.charset))[6])
get_url = AttachFile.getAttachUrl(page_name, file, self.request, escaped=1)
attachments[file] = [fsize, get_url]
return attachments
示例15: attachment_image
# 需要导入模块: from MoinMoin.action import AttachFile [as 别名]
# 或者: from MoinMoin.action.AttachFile import getAttachUrl [as 别名]
def attachment_image(self, url, **kw):
"""
Figures out the absolute path to the image and then hands over to
the image function. Any title is also handed over, and an additional
title suggestion is made based on filename. The image function will
use the suggestion if no other text alternative is found.
If the file is not found, then a simple text will replace it.
"""
_ = self.request.getText
pagename, filename = AttachFile.absoluteName(url, self.page.page_name)
fname = wikiutil.taintfilename(filename)
fpath = AttachFile.getFilename(self.request, pagename, fname)
if not os.path.exists(fpath):
return self.text(u"[attachment:%s]" % url)
else:
return self.image(
src=AttachFile.getAttachUrl(pagename, filename, self.request, addts=1), attachment_title=url, **kw
)