Attachment 'VarStr.py'
Download 1 # -*- coding: utf-8 -*-
2 """
3 MoinMoin - VarStr
4
5 Set and Get variable strings in current wiki documents.
6
7 @copyright: 2006 by Gouichi Iisaka < iisaka51 at hotmail dot com >
8 @license: GNU GPL
9 """
10
11 from MoinMoin import config
12 from MoinMoin.parser import wiki
13
14 _ErrVar = 0
15 _GetVar = 1
16 _SetVar = 2
17
18 # VarStr macro cannot be cached
19 Dependencies = ["time"]
20
21 def parse_args(args):
22 if len(args) == 0:
23 return _ErrVar, '', ''
24
25 pos = args.find('=')
26 if pos < 0:
27 return _GetVar, '', args
28 elif pos == 0:
29 return _ErrVar, '', ''
30 else:
31 return _SetVar, args[:pos], args[pos+1:]
32
33 def execute(macro, args):
34 # create storage for variable string
35 if not hasattr(macro.request, 'varbuffer'):
36 macro.request.varbuffer = {}
37
38 op, tag, val = parse_args(args)
39 # nothing to do
40 if op == _GetVar:
41 if macro.request.varbuffer.has_key(val):
42 return macro.formatter.text(macro.request.varbuffer[val])
43 else:
44 return macro.formatter.text("VarStr:Keyword Error: %s" % val)
45 elif op == _SetVar:
46 macro.request.varbuffer[tag]=val
47 return ''
48 else:
49 return macro.formatter.text("VarStr:Syntax Error:%s" % args)
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.