本文整理汇总了Python中MoinMoin.action.AttachFile.absoluteName方法的典型用法代码示例。如果您正苦于以下问题:Python AttachFile.absoluteName方法的具体用法?Python AttachFile.absoluteName怎么用?Python AttachFile.absoluteName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MoinMoin.action.AttachFile
的用法示例。
在下文中一共展示了AttachFile.absoluteName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: attachment_inlined
# 需要导入模块: from MoinMoin.action import AttachFile [as 别名]
# 或者: from MoinMoin.action.AttachFile import absoluteName [as 别名]
def attachment_inlined(self, url, text, **kw):
from MoinMoin.action import AttachFile
import os
_ = self.request.getText
pagename, filename = AttachFile.absoluteName(url, self.page.page_name)
fname = wikiutil.taintfilename(filename)
fpath = AttachFile.getFilename(self.request, pagename, fname)
ext = os.path.splitext(filename)[1]
Parser = wikiutil.getParserForExtension(self.request.cfg, ext)
if Parser is not None:
try:
content = file(fpath, "r").read()
# Try to decode text. It might return junk, but we don't
# have enough information with attachments.
content = wikiutil.decodeUnknownInput(content)
colorizer = Parser(content, self.request, filename=filename)
colorizer.format(self)
except IOError:
pass
self.attachment_link(1, url)
self.text(text)
self.attachment_link(0)
return ""
示例2: attachment
# 需要导入模块: from MoinMoin.action import AttachFile [as 别名]
# 或者: from MoinMoin.action.AttachFile import absoluteName [as 别名]
def attachment(self, target_and_text, **kw):
""" This gets called on attachment URLs """
_ = self._
scheme, fname, text = wikiutil160a.split_wiki(target_and_text)
pagename, fname = AttachFile.absoluteName(fname, self.pagename)
from_this_page = pagename == self.pagename
fname = self._replace(('FILE', pagename, fname))
#fname = wikiutil.url_unquote(fname)
#fname = self._replace(('FILE', pagename, fname))
pagename = self._replace(('PAGE', pagename))
if from_this_page:
name = fname
else:
name = "%s/%s" % (pagename, fname)
fn_txt = name
if text:
fn_txt += '|' + text
if scheme == 'drawing':
return "{{drawing:%s}}" % fn_txt
# check for image, and possibly return IMG tag (images are always inlined)
if not kw.get('pretty_url', 0) and wikiutil.isPicture(fname):
return "{{attachment:%s}}" % fn_txt
# inline the attachment
if scheme == 'inline':
return '{{attachment:%s}}' % fn_txt
return '[[attachment:%s]]' % fn_txt
示例3: attachment_link
# 需要导入模块: from MoinMoin.action import AttachFile [as 别名]
# 或者: from MoinMoin.action.AttachFile import absoluteName [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)
示例4: attachment_image
# 需要导入模块: from MoinMoin.action import AttachFile [as 别名]
# 或者: from MoinMoin.action.AttachFile import absoluteName [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)
示例5: attachment_link
# 需要导入模块: from MoinMoin.action import AttachFile [as 别名]
# 或者: from MoinMoin.action.AttachFile import absoluteName [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))
示例6: attachment_image
# 需要导入模块: from MoinMoin.action import AttachFile [as 别名]
# 或者: from MoinMoin.action.AttachFile import absoluteName [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))
示例7: attachment_drawing
# 需要导入模块: from MoinMoin.action import AttachFile [as 别名]
# 或者: from MoinMoin.action.AttachFile import absoluteName [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")
示例8: attachment_drawing
# 需要导入模块: from MoinMoin.action import AttachFile [as 别名]
# 或者: from MoinMoin.action.AttachFile import absoluteName [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)
示例9: attachment_drawing
# 需要导入模块: from MoinMoin.action import AttachFile [as 别名]
# 或者: from MoinMoin.action.AttachFile import absoluteName [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)
示例10: render
# 需要导入模块: from MoinMoin.action import AttachFile [as 别名]
# 或者: from MoinMoin.action.AttachFile import absoluteName [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))
示例11: attachment_image
# 需要导入模块: from MoinMoin.action import AttachFile [as 别名]
# 或者: from MoinMoin.action.AttachFile import absoluteName [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
)
示例12: gedit_drawing
# 需要导入模块: from MoinMoin.action import AttachFile [as 别名]
# 或者: from MoinMoin.action.AttachFile import absoluteName [as 别名]
def gedit_drawing(self, url, text, **kw):
# This is called for displaying a drawing image by gui editor.
_ = self.request.getText
# TODO: this 'text' argument is kind of superfluous, replace by using alt=... kw arg
# ToDo: make this clickable for the gui editor
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, drawing = AttachFile.absoluteName(url, self.page.page_name)
containername = wikiutil.taintfilename(drawing)
drawing_url = AttachFile.getAttachUrl(pagename, containername, self.request)
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)
kw['src'] = ci.member_url('drawing.png')
return self.image(**kw)
示例13: attachment
# 需要导入模块: from MoinMoin.action import AttachFile [as 别名]
# 或者: from MoinMoin.action.AttachFile import absoluteName [as 别名]
def attachment(self, url_and_text):
""" This gets called on attachment URLs. """
if len(url_and_text) == 1:
url = url_and_text[0]
text = ''
else:
url, text = url_and_text
text = '|' + text
scheme, fname = url.split(":", 1)
#scheme, fname, text = wikiutil.split_wiki(target_and_text)
pagename, fname = AttachFile.absoluteName(fname, self.pagename)
from_this_page = pagename == self.pagename
fname = self._replace(('FILE', pagename, fname))
fname = wikiutil.url_unquote(fname)
fname = self._replace(('FILE', pagename, fname))
pagename = self._replace(('PAGE', pagename))
if from_this_page:
name = fname
else:
name = "%s/%s" % (pagename, fname)
if scheme == 'drawing':
return "{{drawing:%s%s}}" % (name, text)
# check for image URL, and possibly return IMG tag
# (images are always inlined, just like for other URLs)
if wikiutil.isPicture(name):
return "{{attachment:%s%s}}" % (name, text)
# inline the attachment
if scheme == 'inline':
return '{{attachment:%s%s}}' % (name, text)
else: # 'attachment'
return '[[attachment:%s%s]]' % (name, text)
示例14: macro_EmbedObject
# 需要导入模块: from MoinMoin.action import AttachFile [as 别名]
# 或者: from MoinMoin.action.AttachFile import absoluteName [as 别名]
def macro_EmbedObject(macro, target=wikiutil.required_arg(unicode), pagename=None,
width=wikiutil.UnitArgument(None, float, ['px', 'em', 'pt', 'in', 'mm', '%'], defaultunit='px'),
height=wikiutil.UnitArgument(None, float, ['px', 'em', 'pt', 'in', 'mm', '%'], defaultunit='px'),
alt=u'',
play=False, stop=True, loop=False, quality=(u'high', u'low', u'medium'),
op=True, repeat=False, autostart=False, align=(u'middle', u'top', u'bottom'), hidden=False,
menu=True, wmode=u'transparent', url_mimetype=None):
""" This macro is used to embed an object into a wiki page """
# Join unit arguments with their units
if width:
if width[1] == 'px':
width = '%dpx' % int(width[0])
else:
width = '%g%s' % width
if height:
if height[1] == 'px':
height = '%dpx' % int(height[0])
else:
height = '%g%s' % height
request = macro.request
_ = macro.request.getText
fmt = macro.formatter
# AttachFile calls always with pagename. Users can call the macro from a different page as the attachment is saved.
if not pagename:
pagename = fmt.page.page_name
if not wikiutil.is_URL(target):
pagename, fname = AttachFile.absoluteName(target, pagename)
if not AttachFile.exists(request, pagename, fname):
linktext = _('Upload new attachment "%(filename)s"') % {'filename': fname}
target = AttachFile.getAttachUrl(pagename, fname, request, do='upload_form')
return (fmt.url(1, target) +
fmt.text(linktext) +
fmt.url(0))
url = AttachFile.getAttachUrl(pagename, fname, request)
mt = wikiutil.MimeType(filename=fname)
else:
if not url_mimetype:
return fmt.text(_('%(extension_name)s %(extension_type)s: Required argument %(argument_name)s missing.') % {
"extension_name": extension_name,
"extension_type": extension_type,
"argument_name": "url_mimetype",
})
else:
url = target
mt = wikiutil.MimeType() # initialize dict
try:
mt.major, mt.minor = url_mimetype.split('/')
except ValueError:
return fmt.text(_('%(extension_name)s %(extension_type)s: Invalid %(argument_name)s=%(argument_value)s!') % {
"extension_name": extension_name,
"extension_type": extension_type,
"argument_name": "url_mimetype",
"argument_value": str(url_mimetype),
})
mime_type = "%s/%s" % (mt.major, mt.minor, )
dangerous = mime_type in request.cfg.mimetypes_xss_protect
if not mime_type in request.cfg.mimetypes_embed or dangerous:
return "%s: %s%s%s" % (fmt.text(
_("Current configuration does not allow embedding of the file %(file)s because of its mimetype %(mimetype)s.") % {
"mimetype": mime_type,
"file": target}),
fmt.url(1, url),
fmt.text(target),
fmt.url(0))
if not alt:
alt = "%(text)s %(mime_type)s" % {'text': _("Embedded"), 'mime_type': mime_type}
embed_src = ''
if mt.major == 'video':
if not width and not height:
width = '400px'
height = '400px'
embed_src = '''
<object %(ob_data)s %(ob_type)s %(ob_width)s %(ob_height)s %(ob_align)s %(ob_standby)s %(ob_stop)s>
%(wmode)s%(movie)s%(play)s%(stop)s%(repeat)s%(autostart)s%(op)s%(menu)s
<p>%(alt)s</p>
</object>''' % {
"ob_data": _check_object_value("data", url),
"ob_type": _check_object_value("type", mime_type),
"ob_width": _check_object_value("width", width),
"ob_height": _check_object_value("height", height),
"ob_align": _check_object_value("align", align),
"ob_standby": _check_object_value("standby", alt),
"ob_stop": _check_object_value("stop", stop),
"wmode": _check_param_value("wmode", wmode, "data"),
"movie": _check_param_value("movie", url, "data"),
"play": _check_param_value("play", play, "data"),
"stop": _check_param_value("stop", stop, "data"),
"repeat": _check_param_value("repeat", repeat, "data"),
"autostart": _check_param_value("autostart", autostart, "data"),
#.........这里部分代码省略.........
示例15: execute
# 需要导入模块: from MoinMoin.action import AttachFile [as 别名]
# 或者: from MoinMoin.action.AttachFile import absoluteName [as 别名]
def execute(self):
request = self.request
_ = request.getText
pagename = request.page.page_name
if not request.user.may.read(pagename):
fault = _(u'Can not read page') + u'\n'
if self.inline:
request.write(request.formatter.text(fault))
return
request.content_type = 'text/plain'
request.write(fault)
return
form = values_to_form(request.values)
self.formargs(form)
if self.help or not self.attachment:
enter_page(request, pagename, 'View .gv attachment')
self.sendForm()
if self.help:
# This is the URL addition to the nodes that have graph data
self.urladd = url_parameters(form)
self.urladd = self.urladd.replace('&help=Inline', '')
request.write('<<ViewDot(' + self.urladd + ')>>')
exit_page(request, pagename)
return
if not self.attachment[:10].lower() == 'attachment':
fault = _(u'No attachment defined') + u'\n'
if self.inline:
request.write(request.formatter.text(fault))
return
request.content_type = 'text/plain'
request.write(fault)
return
self.attachment = self.attachment[11:]
pagename, filename = AttachFile.absoluteName(self.attachment,
self.pagename)
if not request.user.may.read(pagename):
fault = _(u'Can not read attachment page') + u'\n'
if self.inline:
request.write(request.formatter.text(fault))
return
request.content_type = 'text/plain'
request.write(fault)
return
fname = wikiutil.taintfilename(filename)
fpath = AttachFile.getFilename(request, pagename, fname)
try:
data = file(fpath, 'r').read()
except IOError:
fault = _(u'Can not read attachment') + u'\n'
if self.inline:
request.write(request.formatter.text(fault))
return
request.content_type = 'text/plain'
request.write(fault)
return
if not have_gv():
fault = _(u"ERROR: Graphviz Python extensions not installed. " +\
u"Not performing layout.")
if self.inline:
request.write(request.formatter.text(fault))
return
request.content_type = 'text/plain'
request.write(fault)
return
self.cache_key = cache_key(self.request,
[data, self.graphengine, self.format])
key = "%s-%s" % (self.cache_key, self.format)
if self.format in ['zgr', 'svg']:
formatcontent = 'svg+xml'
else:
formatcontent = self.format
if not cache_exists(request, key):
graphviz = Graphviz(engine=self.graphengine, string=data)
data = self.getLayoutInFormat(graphviz, self.format)
cache.put(self.request, key, data, content_type=formatcontent)
if self.format in ['zgr', 'svg']:
# Display zgr graphs as applets
if self.format == 'zgr':
image_p = lambda url, text: \
'<applet code="net.claribole.zgrviewer.ZGRApplet.class"'+ \
' archive="%s/gwikicommon/zgrviewer/zvtm.jar,' % \
(self.request.cfg.url_prefix_static) + \
'%s/gwikicommon/zgrviewer/zgrviewer.jar" ' % \
#.........这里部分代码省略.........