本文整理汇总了Python中MoinMoin.action.AttachFile类的典型用法代码示例。如果您正苦于以下问题:Python AttachFile类的具体用法?Python AttachFile怎么用?Python AttachFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AttachFile类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: visit_image
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)
开发者ID:IvanLogvinov,项目名称:soar,代码行数:31,代码来源:text_rst.py
示例2: test_cache_key_attachment
def test_cache_key_attachment(self):
request = self.request
pagename = self.pagename
attachname = 'foo.txt'
become_trusted(request)
create_page(request, pagename, u"Foo!")
AttachFile.add_attachment(request, pagename, attachname, "Test content1", True)
result1 = cache.key(request, itemname=pagename, attachname=attachname, secret='bar')
result2 = cache.key(request, itemname=pagename, attachname=attachname, secret='baz')
assert result1 # not empty
assert result1 != result2 # different for different secret
# test below does not work, because mtime is often same, inode can be same due to how add_attachment
# works, file size is same, attachment name is same, wikiname/pagename is same.
# In practice, this should rather rarely cause problems:
#AttachFile.add_attachment(request, pagename, attachname, "Test content2", True)
#result3 = cache.key(request, itemname=pagename, attachname=attachname, secret='baz')
#assert result3 != result2 # different for different content
AttachFile.add_attachment(request, pagename, attachname, "Test content33333", True)
result4 = cache.key(request, itemname=pagename, attachname=attachname, secret='baz')
assert len(result4) == len(result2) # same length of key for different input lengths
nuke_page(request, pagename)
开发者ID:Kartstig,项目名称:engineering-inventions-wiki,代码行数:26,代码来源:test_cache.py
示例3: xmlrpc_putAttachment
def xmlrpc_putAttachment(self, pagename, attachname, data):
""" Set attachname associated with pagename to data
@param pagename: pagename (utf-8)
@param attachname: attachment name (utf-8)
@param data: file data (base64)
@rtype boolean
@return True if attachment was set
"""
pagename = self._instr(pagename)
# User may read page?
if not self.request.user.may.read(pagename):
return self.notAllowedFault()
# also check ACLs
if not self.request.user.may.write(pagename):
return xmlrpclib.Fault(1, "You are not allowed to edit this page")
attachname = wikiutil.taintfilename(attachname)
filename = AttachFile.getFilename(self.request, pagename, attachname)
if os.path.exists(filename) and not os.path.isfile(filename):
return self.noSuchPageFault()
open(filename, 'wb+').write(data.data)
AttachFile._addLogEntry(self.request, 'ATTNEW', pagename, filename)
return xmlrpclib.Boolean(1)
开发者ID:steveyen,项目名称:moingo,代码行数:25,代码来源:__init__.py
示例4: attachment_inlined
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 ""
开发者ID:pombredanne,项目名称:akara,代码行数:25,代码来源:application_xml.py
示例5: xmlrpc_putAttachment
def xmlrpc_putAttachment(self, pagename, attachname, data):
"""
Store <data> as content of attachment <attachname> of page <pagename>.
@param pagename: pagename (utf-8)
@param attachname: attachment name (utf-8)
@param data: file data (base64)
@rtype: bool
@return: True if attachment was successfully stored
"""
pagename = self._instr(pagename)
# User may read page?
if not self.request.user.may.read(pagename):
return self.notAllowedFault()
# also check ACLs
if not self.request.user.may.write(pagename):
return xmlrpclib.Fault(1, "You are not allowed to edit this page")
attachname = wikiutil.taintfilename(self._instr(attachname))
filename = AttachFile.getFilename(self.request, pagename, attachname)
if os.path.exists(filename) and not os.path.isfile(filename):
return self.noSuchPageFault()
open(filename, 'wb+').write(data.data)
AttachFile._addLogEntry(self.request, 'ATTNEW', pagename, attachname)
return xmlrpclib.Boolean(1)
开发者ID:Kartstig,项目名称:engineering-inventions-wiki,代码行数:26,代码来源:__init__.py
示例6: test_attachment
def test_attachment(self):
page_name = u'TestAttachment'
self.pages[page_name] = 'some text' # Moin search must search this page
filename = "AutoCreatedSillyAttachmentForSearching.png"
data = "Test content"
filecontent = StringIO.StringIO(data)
result = self.search(filename)
found_attachments = set([(hit.page_name, hit.attachment) for hit in result.hits])
assert not found_attachments
try:
create_page(self.request, page_name, self.pages[page_name])
AttachFile.add_attachment(self.request, page_name, filename, filecontent, True)
append_page(self.request, page_name, '[[attachment:%s]]' % filename)
self._index_update()
result = self.search(filename)
found_attachments = set([(hit.page_name, hit.attachment) for hit in result.hits])
assert (page_name, '') in found_attachments
assert 1 <= len(found_attachments) <= 2
# Note: moin search returns (page_name, '') as only result
# xapian search returns 2 results: (page_name, '') and (page_name, filename)
# TODO: make behaviour the same, if possible
finally:
nuke_page(self.request, page_name)
del self.pages[page_name]
self._index_update()
result = self.search(filename)
found_attachments = set([(hit.page_name, hit.attachment) for hit in result.hits])
assert not found_attachments
开发者ID:Kartstig,项目名称:engineering-inventions-wiki,代码行数:31,代码来源:test_search.py
示例7: _index_page
def _index_page(self, writer, page, update):
""" Index a page - assumes that the write lock is acquired
@arg writer: the index writer object
@arg page: a page object
@arg update: False = index in any case, True = index only when changed
"""
pagename = page.page_name
request = page.request
mtime = page.mtime_usecs()
if update:
query = BooleanQuery()
query.add(TermQuery(Term("pagename", pagename)), True, False)
query.add(TermQuery(Term("attachment", "")), True, False)
docs = self._search(query)
updated = len(docs) == 0 or mtime > int(docs[0].get('mtime'))
else:
updated = True
request.log("%s %r" % (pagename, updated))
if updated:
d = document.Document()
d.add(document.Keyword('pagename', pagename))
d.add(document.Keyword('mtime', str(mtime)))
d.add(document.Keyword('attachment', '')) # this is a real page, not an attachment
d.add(document.Text('title', pagename, store=False))
d.add(document.Text('text', page.get_raw_body(), store=False))
links = page.getPageLinks(request)
t = document.Text('links', '', store=False)
t.stringVal = links
d.add(t)
d.add(document.Text('link_text', ' '.join(links), store=False))
writer.addDocument(d)
from MoinMoin.action import AttachFile
attachments = AttachFile._get_files(request, pagename)
for att in attachments:
filename = AttachFile.getFilename(request, pagename, att)
mtime = wikiutil.timestamp2version(os.path.getmtime(filename))
if update:
query = BooleanQuery()
query.add(TermQuery(Term("pagename", pagename)), True, False)
query.add(TermQuery(Term("attachment", att)), True, False)
docs = self._search(query)
updated = len(docs) == 0 or mtime > int(docs[0].get('mtime'))
else:
updated = True
request.log("%s %s %r" % (pagename, att, updated))
if updated:
att_content = self.contentfilter(filename)
d = document.Document()
d.add(document.Keyword('pagename', pagename))
d.add(document.Keyword('mtime', str(mtime)))
d.add(document.Keyword('attachment', att)) # this is an attachment, store its filename
d.add(document.Text('title', att, store=False)) # the filename is the "title" of an attachment
d.add(document.Text('text', att_content, store=False))
writer.addDocument(d)
开发者ID:imosts,项目名称:flume,代码行数:58,代码来源:lupy.py
示例8: attachment_drawing
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))
开发者ID:imosts,项目名称:flume,代码行数:9,代码来源:text_gedit.py
示例9: attachment_image
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)
开发者ID:IvanLogvinov,项目名称:soar,代码行数:10,代码来源:text_gedit.py
示例10: attachment_link
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)
开发者ID:Kartstig,项目名称:engineering-inventions-wiki,代码行数:10,代码来源:text_docbook.py
示例11: nuke_page
def nuke_page(request, pagename):
""" completely delete a page, everything in the pagedir """
attachments = AttachFile._get_files(request, pagename)
for attachment in attachments:
AttachFile.remove_attachment(request, pagename, attachment)
page = PageEditor(request, pagename, do_editor_backup=False)
page.deletePage()
# really get rid of everything there:
fpath = page.getPagePath(check_create=0)
shutil.rmtree(fpath, True)
开发者ID:happytk,项目名称:moin,代码行数:10,代码来源:__init__.py
示例12: addAttachment
def addAttachment(self, name, content):
"""add image to attachment"""
if os.path.splitext(name)[1].lower() not in \
['.' + x for x in self.image_extenstions]:
name += '.jpg' # if the url didn't contain a image extention
AttachFile.add_attachment(self.request,
self.pagename,
name,
content,
True)
return wikiutil.taintfilename(name)
开发者ID:alswl,项目名称:image2attach,代码行数:11,代码来源:Image2Attach.py
示例13: attachment_link
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))
开发者ID:imosts,项目名称:flume,代码行数:12,代码来源:xml_docbook.py
示例14: execute
def execute(pagename, request):
"""
Handle action=IntraFarmCopy
"""
if not request.user.may.read(pagename):
Page(request, pagename).send_page()
return
# Which local farm wiki - assume team for now
to_wiki_url = COPY_TO_WIKI_URL
# New page name
to_wiki_pagename = '%s%s' % (COPY_TO_PREFIX, pagename)
# create page at local wiki if it doesn't exist
to_request = ScriptContext(to_wiki_url)
# login this user remotely
to_uid = user.getUserId(to_request, request.user.name)
to_user = user.User(to_request, id=to_uid, name=request.user.name, password=request.user.password, auth_method="moin")
to_request.user = to_user
try:
page = Page(to_request, to_wiki_pagename)
except:
return action_error(u'Error accessing destination page')
if not page.exists():
pe = PageEditor(to_request, to_wiki_pagename)
# make initial revision pointer to original
try:
pe.saveText(u'[[%s:%s]]' % (request.cfg.interwikiname, pagename), 0, comment="Automated IntraFarmCopy pointing to original page")
except pe.Unchanged:
return action_error(u'Could not save initial page')
except pe.AccessDenied:
return action_error(u'Could not acquire credentials')
# make next revision content of this page
try:
pe.saveText(Page(request, pagename).get_raw_body(), 0, comment="Automated IntraFarmCopy importing contents from original page at [[%s:%s]]" % (request.cfg.interwikiname, pagename))
except pe.Unchanged:
return action_error(u'Could not save destination page text')
# send attachments over
attachments = AttachFile._get_files(request, pagename)
for attachname in attachments:
filename = AttachFile.getFilename(request, pagename, attachname)
if not os.path.isfile(filename):
continue
to_filename = AttachFile.getFilename(to_request, to_wiki_pagename, attachname)
shutil.copyfile(filename, to_filename)
AttachFile._addLogEntry(to_request, 'ATTNEW', to_wiki_pagename, attachname)
# redirect user to view new page in other wiki
request.http_redirect('%s%s' % (to_wiki_url, to_wiki_pagename))
return
else:
return action_error(u'Destination page already exists!')
开发者ID:iSCInc,项目名称:intrafarmcopy,代码行数:53,代码来源:IntraFarmCopy.py
示例15: attachment_image
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))
开发者ID:imosts,项目名称:flume,代码行数:12,代码来源:xml_docbook.py
示例16: attachment_drawing
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")
开发者ID:Kartstig,项目名称:engineering-inventions-wiki,代码行数:13,代码来源:text_docbook.py
示例17: test_add_attachment
def test_add_attachment(self):
"""Test if add_attachment() works"""
become_trusted(self.request)
filename = "AutoCreatedSillyAttachment"
create_page(self.request, self.pagename, u"Foo!")
AttachFile.add_attachment(self.request, self.pagename, filename, "Test content", True)
exists = AttachFile.exists(self.request, self.pagename, filename)
nuke_page(self.request, self.pagename)
assert exists
开发者ID:steveyen,项目名称:moingo,代码行数:14,代码来源:test_attachfile.py
示例18: attachment_drawing
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)
开发者ID:Kartstig,项目名称:engineering-inventions-wiki,代码行数:50,代码来源:twikidraw.py
示例19: render
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))
开发者ID:imosts,项目名称:flume,代码行数:50,代码来源:EmbedObject.py
示例20: attachment_drawing
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)
开发者ID:steveyen,项目名称:moingo,代码行数:14,代码来源:text_gedit.py
注:本文中的MoinMoin.action.AttachFile类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论