Attachment 'meta.py'
Download 1 #!/usr/bin/env python
2 # -*- coding: iso8859-1 -*-
3 import email, email.Message
4
5 def make_meta(mime='text/wiki', charset='utf-8', **kw):
6 meta = email.Message.Message()
7 meta.set_type(mime)
8 meta.set_charset(charset)
9 for k,v in kw.items():
10 if isinstance(v, unicode):
11 meta[k] = v.encode(charset)
12 else:
13 meta[k] = str(v)
14 # remove stuff we don't need:
15 del meta['Content-Transfer-Encoding']
16 del meta['Mime-Version']
17 return meta.as_string()
18
19 def parse_meta(metastr):
20 meta = email.message_from_string(metastr)
21 mime = meta.get_content_type()
22 charset = 'ascii'
23 for k,v in meta.get_params():
24 if k == 'charset':
25 charset = v
26 # we only need it once:
27 del meta['Content-Type']
28 d = {}
29 for k in meta.keys():
30 d[k] = unicode(meta[k], charset)
31 return mime, charset, d
32
33 meta = make_meta('text/wiki', 'utf-8',
34 current = 3,
35 acl = 'WikiAdmin:read,write,revert,delete,admin All:',
36 lasteditor = u'JürgenHermann',
37 lastchange = 12345678)
38
39 print meta
40
41 print parse_meta(meta)
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.