From fc97e515c8841f188b39fa135f57e2f37a21d45a Mon Sep 17 00:00:00 2001 From: Bernie Innocenti Date: Wed, 19 Aug 2009 12:13:10 +0200 Subject: [PATCH] Move macros in sys/ --- sys/macros/CgiVar.py | 9 +++++++++ sys/macros/HttpGet.py | 8 ++++++++ sys/macros/HttpPost.py | 8 ++++++++ sys/macros/TitleIndex.py | 16 ++++++++++++++++ sys/macros/WordIndex.py | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 74 insertions(+) create mode 100644 sys/macros/CgiVar.py create mode 100644 sys/macros/HttpGet.py create mode 100644 sys/macros/HttpPost.py create mode 100644 sys/macros/TitleIndex.py create mode 100644 sys/macros/WordIndex.py diff --git a/sys/macros/CgiVar.py b/sys/macros/CgiVar.py new file mode 100644 index 0000000..c2ba707 --- /dev/null +++ b/sys/macros/CgiVar.py @@ -0,0 +1,9 @@ +#acl bernie:read,write All:read + +def _macro_CgiVar(*args, **kvargs): + return { + 'REMOTE_USER': remote_user(), + 'REMOTE_HOST': get_hostname(remote_host()), + 'REMOTE_ADDR': remote_host(), + 'QUERY_STRING': relative_url(query_string()), + }[args[1]] diff --git a/sys/macros/HttpGet.py b/sys/macros/HttpGet.py new file mode 100644 index 0000000..dfe1dfb --- /dev/null +++ b/sys/macros/HttpGet.py @@ -0,0 +1,8 @@ +#acl bernie:read,write All:read + +def _macro_HttpGet(*args, **kvargs): + if args[1] in form: + return form[args[1]].value + elif len(args) > 2: + return args[2] # default value + raise Exception("Undefined argument " + args[1]) diff --git a/sys/macros/HttpPost.py b/sys/macros/HttpPost.py new file mode 100644 index 0000000..fbe277a --- /dev/null +++ b/sys/macros/HttpPost.py @@ -0,0 +1,8 @@ +#acl bernie:read,write All:read + +def _macro_HttpPost(*args, **kvargs): + if args[1] in form: + return form[argv[1]].value + elif len(args) > 2: + return args[2] # default value + raise Exception("Undefined argument " + args[1]) diff --git a/sys/macros/TitleIndex.py b/sys/macros/TitleIndex.py new file mode 100644 index 0000000..9f5c25b --- /dev/null +++ b/sys/macros/TitleIndex.py @@ -0,0 +1,16 @@ +#acl bernie:read,write All:read + +def _macro_TitleIndex(*args, **kvargs): + s = make_index_key() + pages = list(page_list()) + pages.sort() + current_letter = None + for name in pages: + letter = name[0].lower() + if letter != current_letter: + s += '

%s

' % (letter, letter) + current_letter = letter + else: + s += '
' + s += link_tag(name) + return s diff --git a/sys/macros/WordIndex.py b/sys/macros/WordIndex.py new file mode 100644 index 0000000..635ef6b --- /dev/null +++ b/sys/macros/WordIndex.py @@ -0,0 +1,33 @@ +#acl bernie:read,write All:read + +def _macro_WordIndex(*args, **kvargs): + s = make_index_key() + pages = list(page_list()) + map = {} + word_re = re.compile('[A-Z][a-z]+') + for name in pages: + for word in word_re.findall(name): + try: + map[word].append(name) + except KeyError: + map[word] = [name] + + all_words = list(map.keys()) + all_words.sort() + last_letter = None + # set title + for word in all_words: + letter = word[0].lower() + if letter != last_letter: + s += '

%s

' % (letter, letter) + last_letter = letter + + s += '%s' + return s -- 2.25.1