Attachment 'IncludeExternalFile.py'
Download 1 """
2 IncludeExternalFile macro
3
4 Outputs the external file's content.
5
6 Usage:
7
8 <<IncludeExternalFile(externalfilename)>>
9 <<IncludeExternalFile(externalfilename, coding)>>
10
11 Note: please set IncludeExternalFileRoot in your wiki config for security reasons.
12
13 @copyright: originally by Albert Ma http://www.ieasy.org,
14 refactored by MoinMoin:ThomasWaldmann
15 license: GNU GPL, see COPYING for details
16 """
17
18 import os, codecs
19
20
21 def macro_IncludeExternalFile(macro, fname=u'', coding='utf-8'):
22 if ".." in fname:
23 return u"Invalid argument - .. is not allowed."
24 abs_fname = os.path.join(macro.request.cfg.IncludeExternalFileRoot, fname)
25 try:
26 f = codecs.open(abs_fname, "r", coding)
27 except IOError:
28 result = u"Can't not open %s." % abs_fname # discloses internal path
29 else:
30 result = f.read()
31 f.close()
32 return result
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.