annotate MoinMoin/wikiutil.py @ 1122:2be8ec7ba817

Now the interwiki code caches the modification time of the interwiki files.
author Alexander Schremmer <alex AT alexanderweb DOT de>
date Thu, 03 Aug 2006 18:20:48 +0200
parents 2aa53ed0afa0
children a7f8dceb4410
rev   line source
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
2 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
3 MoinMoin - Wiki Utility Functions
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
4
987
95f57ffeb4e9 added umlaut somewhere else.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 974
diff changeset
5 @copyright: 2000 - 2004 by Jürgen Hermann <jh@web.de>
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
6 @license: GNU GPL, see COPYING for details.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
7 """
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 930
diff changeset
8
1085
2bcb7bdf94a2 Implemented an editable InterWikiMap, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1082
diff changeset
9 import cgi
2bcb7bdf94a2 Implemented an editable InterWikiMap, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1082
diff changeset
10 import codecs
2bcb7bdf94a2 Implemented an editable InterWikiMap, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1082
diff changeset
11 import os
2bcb7bdf94a2 Implemented an editable InterWikiMap, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1082
diff changeset
12 import re
2bcb7bdf94a2 Implemented an editable InterWikiMap, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1082
diff changeset
13 import time
2bcb7bdf94a2 Implemented an editable InterWikiMap, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1082
diff changeset
14 import types
2bcb7bdf94a2 Implemented an editable InterWikiMap, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1082
diff changeset
15 import urllib
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
16
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
17 from MoinMoin import util, version, config
1082
ba25ee4ea61d Added locking to the MetaDict code.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1079
diff changeset
18 from MoinMoin.util import pysupport, filesys, lock
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
19
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
20 # Exceptions
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
21 class InvalidFileNameError(Exception):
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 930
diff changeset
22 """ Called when we find an invalid file name """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
23 pass
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
24
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
25 # constants for page names
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
26 PARENT_PREFIX = "../"
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
27 PARENT_PREFIX_LEN = len(PARENT_PREFIX)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
28 CHILD_PREFIX = "/"
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
29 CHILD_PREFIX_LEN = len(CHILD_PREFIX)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
30
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
31 #############################################################################
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
32 ### Getting data from user/Sending data to user
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
33 #############################################################################
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
34
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
35 def decodeWindowsPath(text):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
36 """ Decode Windows path names correctly. This is needed because many CGI
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
37 servers follow the RFC recommendation and re-encode the path_info variable
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
38 according to the file system semantics.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
39
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
40 @param text: the text to decode, string
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
41 @rtype: unicode
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
42 @return: decoded text
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
43 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
44
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
45 import locale
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
46 cur_charset = locale.getdefaultlocale()[1]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
47 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
48 return unicode(text, 'utf-8')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
49 except UnicodeError:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
50 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
51 return unicode(text, cur_charset, 'replace')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
52 except LookupError:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
53 return unicode(text, 'iso-8859-1', 'replace')
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 930
diff changeset
54
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
55 def decodeUnknownInput(text):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
56 """ Decode unknown input, like text attachments
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
57
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
58 First we try utf-8 because it has special format, and it will decode
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
59 only utf-8 files. Then we try config.charset, then iso-8859-1 using
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
60 'replace'. We will never raise an exception, but may return junk
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
61 data.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
62
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
63 WARNING: Use this function only for data that you view, not for data
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
64 that you save in the wiki.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
65
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
66 @param text: the text to decode, string
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
67 @rtype: unicode
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
68 @return: decoded text (maybe wrong)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
69 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
70 # Shortcut for unicode input
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
71 if isinstance(text, unicode):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
72 return text
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 930
diff changeset
73
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
74 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
75 return unicode(text, 'utf-8')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
76 except UnicodeError:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
77 if config.charset not in ['utf-8', 'iso-8859-1']:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
78 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
79 return unicode(text, config.charset)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
80 except UnicodeError:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
81 pass
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
82 return unicode(text, 'iso-8859-1', 'replace')
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 930
diff changeset
83
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
84
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
85 def decodeUserInput(s, charsets=[config.charset]):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
86 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
87 Decodes input from the user.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
88
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
89 @param s: the string to unquote
490
ca35d9e6d63e eypdoc comments: fixed some warnings/errors
Thomas Waldmann <tw@waldmann-edv.de>
parents: 471
diff changeset
90 @param charsets: list of charsets to assume the string is in
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
91 @rtype: unicode
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
92 @return: the unquoted string as unicode
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
93 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
94 for charset in charsets:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
95 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
96 return s.decode(charset)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
97 except UnicodeError:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
98 pass
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
99 raise UnicodeError('The string %r cannot be decoded.' % s)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
100
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
101
101
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
102 # this is a thin wrapper around urllib (urllib only handles str, not unicode)
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
103 # with py <= 2.4.1, it would give incorrect results with unicode
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
104 # with py == 2.4.2, it crashes with unicode, if it contains non-ASCII chars
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
105 def url_quote(s, safe='/', want_unicode=False):
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
106 """
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
107 Wrapper around urllib.quote doing the encoding/decoding as usually wanted:
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
108
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
109 @param s: the string to quote (can be str or unicode, if it is unicode,
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
110 config.charset is used to encode it before calling urllib)
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
111 @param safe: just passed through to urllib
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
112 @param want_unicode: for the less usual case that you want to get back
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
113 unicode and not str, set this to True
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
114 Default is False.
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
115 """
132
88acc9c18b90 fixed some tests, fixed quote functions for non-str/non-unicode values (make str out of them)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 128
diff changeset
116 if isinstance(s, unicode):
101
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
117 s = s.encode(config.charset)
132
88acc9c18b90 fixed some tests, fixed quote functions for non-str/non-unicode values (make str out of them)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 128
diff changeset
118 elif not isinstance(s, str):
88acc9c18b90 fixed some tests, fixed quote functions for non-str/non-unicode values (make str out of them)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 128
diff changeset
119 s = str(s)
101
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
120 s = urllib.quote(s, safe)
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
121 if want_unicode:
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
122 s = s.decode(config.charset) # ascii would also work
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
123 return s
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
124
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
125 def url_quote_plus(s, safe='/', want_unicode=False):
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
126 """
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
127 Wrapper around urllib.quote_plus doing the encoding/decoding as usually wanted:
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
128
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
129 @param s: the string to quote (can be str or unicode, if it is unicode,
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
130 config.charset is used to encode it before calling urllib)
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
131 @param safe: just passed through to urllib
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
132 @param want_unicode: for the less usual case that you want to get back
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
133 unicode and not str, set this to True
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
134 Default is False.
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
135 """
132
88acc9c18b90 fixed some tests, fixed quote functions for non-str/non-unicode values (make str out of them)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 128
diff changeset
136 if isinstance(s, unicode):
101
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
137 s = s.encode(config.charset)
132
88acc9c18b90 fixed some tests, fixed quote functions for non-str/non-unicode values (make str out of them)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 128
diff changeset
138 elif not isinstance(s, str):
88acc9c18b90 fixed some tests, fixed quote functions for non-str/non-unicode values (make str out of them)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 128
diff changeset
139 s = str(s)
101
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
140 s = urllib.quote_plus(s, safe)
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
141 if want_unicode:
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
142 s = s.decode(config.charset) # ascii would also work
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
143 return s
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
144
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
145 def url_unquote(s, want_unicode=True):
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
146 """
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
147 Wrapper around urllib.unquote doing the encoding/decoding as usually wanted:
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
148
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
149 @param s: the string to unquote (can be str or unicode, if it is unicode,
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
150 config.charset is used to encode it before calling urllib)
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
151 @param want_unicode: for the less usual case that you want to get back
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
152 str and not unicode, set this to False.
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
153 Default is True.
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
154 """
132
88acc9c18b90 fixed some tests, fixed quote functions for non-str/non-unicode values (make str out of them)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 128
diff changeset
155 if isinstance(s, unicode):
101
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
156 s = s.encode(config.charset) # ascii would also work
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
157 s = urllib.unquote(s)
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
158 if want_unicode:
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
159 s = s.decode(config.charset)
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
160 return s
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
161
175
df4fe62dc160 fixing eventlog UnicodeDecodeError, try2
Thomas Waldmann <tw@waldmann-edv.de>
parents: 171
diff changeset
162 def parseQueryString(qstr, want_unicode=True):
102
a54cebaab73e move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
163 """ Parse a querystring "key=value&..." into a dict.
a54cebaab73e move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
164 """
a54cebaab73e move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
165 is_unicode = isinstance(qstr, unicode)
a54cebaab73e move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
166 if is_unicode:
a54cebaab73e move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
167 qstr = qstr.encode(config.charset)
a54cebaab73e move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
168 values = {}
a54cebaab73e move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
169 for key, value in cgi.parse_qs(qstr).items():
a54cebaab73e move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
170 if len(value) < 2:
a54cebaab73e move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
171 v = ''.join(value)
a54cebaab73e move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
172 if want_unicode:
175
df4fe62dc160 fixing eventlog UnicodeDecodeError, try2
Thomas Waldmann <tw@waldmann-edv.de>
parents: 171
diff changeset
173 try:
df4fe62dc160 fixing eventlog UnicodeDecodeError, try2
Thomas Waldmann <tw@waldmann-edv.de>
parents: 171
diff changeset
174 v = unicode(v, config.charset)
df4fe62dc160 fixing eventlog UnicodeDecodeError, try2
Thomas Waldmann <tw@waldmann-edv.de>
parents: 171
diff changeset
175 except UnicodeDecodeError:
df4fe62dc160 fixing eventlog UnicodeDecodeError, try2
Thomas Waldmann <tw@waldmann-edv.de>
parents: 171
diff changeset
176 v = unicode(v, 'iso-8859-1', 'replace')
102
a54cebaab73e move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
177 values[key] = v
a54cebaab73e move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
178 return values
a54cebaab73e move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
179
a54cebaab73e move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
180 def makeQueryString(qstr=None, want_unicode=False, **kw):
a54cebaab73e move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
181 """ Make a querystring from arguments.
a54cebaab73e move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
182
a54cebaab73e move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
183 kw arguments overide values in qstr.
a54cebaab73e move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
184
a54cebaab73e move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
185 If a string is passed in, it's returned verbatim and
a54cebaab73e move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
186 keyword parameters are ignored.
a54cebaab73e move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
187
a54cebaab73e move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
188 @param qstr: dict to format as query string, using either ascii or unicode
132
88acc9c18b90 fixed some tests, fixed quote functions for non-str/non-unicode values (make str out of them)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 128
diff changeset
189 @param kw: same as dict when using keywords, using ascii or unicode
102
a54cebaab73e move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
190 @rtype: string
a54cebaab73e move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
191 @return: query string ready to use in a url
a54cebaab73e move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
192 """
a54cebaab73e move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
193 if qstr is None:
a54cebaab73e move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
194 qstr = {}
a54cebaab73e move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
195 if isinstance(qstr, type({})):
a54cebaab73e move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
196 qstr.update(kw)
a54cebaab73e move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
197 items = ['%s=%s' % (url_quote_plus(key, want_unicode=want_unicode), url_quote_plus(value, want_unicode=want_unicode)) for key, value in qstr.items()]
a54cebaab73e move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
198 qstr = '&'.join(items)
a54cebaab73e move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
199 return qstr
a54cebaab73e move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
200
101
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
201
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
202 # FIXME: better name would be quoteURL, as this is useful for any
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
203 # string, not only wiki names.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
204 def quoteWikinameURL(pagename, charset=config.charset):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
205 """ Return a url encoding of filename in plain ascii
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
206
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
207 Use urllib.quote to quote any character that is not always safe.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
208
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
209 @param pagename: the original pagename (unicode)
490
ca35d9e6d63e eypdoc comments: fixed some warnings/errors
Thomas Waldmann <tw@waldmann-edv.de>
parents: 471
diff changeset
210 @param charset: url text encoding, 'utf-8' recommended. Other charsert
ca35d9e6d63e eypdoc comments: fixed some warnings/errors
Thomas Waldmann <tw@waldmann-edv.de>
parents: 471
diff changeset
211 might not be able to encode the page name and raise
ca35d9e6d63e eypdoc comments: fixed some warnings/errors
Thomas Waldmann <tw@waldmann-edv.de>
parents: 471
diff changeset
212 UnicodeError. (default config.charset ('utf-8')).
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
213 @rtype: string
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
214 @return: the quoted filename, all unsafe characters encoded
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
215 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
216 pagename = pagename.encode(charset)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
217 return urllib.quote(pagename)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
218
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
219
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
220 def escape(s, quote=0):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
221 """ Escape possible html tags
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
222
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
223 Replace special characters '&', '<' and '>' by SGML entities.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
224 (taken from cgi.escape so we don't have to include that, even if we
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
225 don't use cgi at all)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
226
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
227 FIXME: should return string or unicode?
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
228
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
229 @param s: (unicode) string to escape
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
230 @param quote: bool, should transform '\"' to '&quot;'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
231 @rtype: (unicode) string
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
232 @return: escaped version of s
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
233 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
234 if not isinstance(s, (str, unicode)):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
235 s = str(s)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
236
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
237 # Must first replace &
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
238 s = s.replace("&", "&amp;")
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
239
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
240 # Then other...
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
241 s = s.replace("<", "&lt;")
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
242 s = s.replace(">", "&gt;")
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
243 if quote:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
244 s = s.replace('"', "&quot;")
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
245 return s
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
246
332
0a40d8a4057e fixed logfile breaking when DeletePage/RenamePage comment contains CRLF chars
Thomas Waldmann <tw@waldmann-edv.de>
parents: 198
diff changeset
247 def clean_comment(comment):
0a40d8a4057e fixed logfile breaking when DeletePage/RenamePage comment contains CRLF chars
Thomas Waldmann <tw@waldmann-edv.de>
parents: 198
diff changeset
248 """ Clean comment - replace CR, LF, TAB by whitespace, delete control chars
0a40d8a4057e fixed logfile breaking when DeletePage/RenamePage comment contains CRLF chars
Thomas Waldmann <tw@waldmann-edv.de>
parents: 198
diff changeset
249 TODO: move this to config, create on first call then return cached.
0a40d8a4057e fixed logfile breaking when DeletePage/RenamePage comment contains CRLF chars
Thomas Waldmann <tw@waldmann-edv.de>
parents: 198
diff changeset
250 """
930
dec2797d37bc we only have comment input fields up to 200 chars, more is likely a spammer POSTing
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 874
diff changeset
251 # we only have input fields with max 200 chars, but spammers send us more
dec2797d37bc we only have comment input fields up to 200 chars, more is likely a spammer POSTing
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 874
diff changeset
252 if len(comment) > 201:
dec2797d37bc we only have comment input fields up to 200 chars, more is likely a spammer POSTing
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 874
diff changeset
253 comment = u''
332
0a40d8a4057e fixed logfile breaking when DeletePage/RenamePage comment contains CRLF chars
Thomas Waldmann <tw@waldmann-edv.de>
parents: 198
diff changeset
254 remap_chars = {
0a40d8a4057e fixed logfile breaking when DeletePage/RenamePage comment contains CRLF chars
Thomas Waldmann <tw@waldmann-edv.de>
parents: 198
diff changeset
255 ord(u'\t'): u' ',
0a40d8a4057e fixed logfile breaking when DeletePage/RenamePage comment contains CRLF chars
Thomas Waldmann <tw@waldmann-edv.de>
parents: 198
diff changeset
256 ord(u'\r'): u' ',
0a40d8a4057e fixed logfile breaking when DeletePage/RenamePage comment contains CRLF chars
Thomas Waldmann <tw@waldmann-edv.de>
parents: 198
diff changeset
257 ord(u'\n'): u' ',
0a40d8a4057e fixed logfile breaking when DeletePage/RenamePage comment contains CRLF chars
Thomas Waldmann <tw@waldmann-edv.de>
parents: 198
diff changeset
258 }
0a40d8a4057e fixed logfile breaking when DeletePage/RenamePage comment contains CRLF chars
Thomas Waldmann <tw@waldmann-edv.de>
parents: 198
diff changeset
259 control_chars = u'\x00\x01\x02\x03\x04\x05\x06\x07\x08\x0b\x0c\x0e\x0f' \
0a40d8a4057e fixed logfile breaking when DeletePage/RenamePage comment contains CRLF chars
Thomas Waldmann <tw@waldmann-edv.de>
parents: 198
diff changeset
260 '\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f'
0a40d8a4057e fixed logfile breaking when DeletePage/RenamePage comment contains CRLF chars
Thomas Waldmann <tw@waldmann-edv.de>
parents: 198
diff changeset
261 for c in control_chars:
0a40d8a4057e fixed logfile breaking when DeletePage/RenamePage comment contains CRLF chars
Thomas Waldmann <tw@waldmann-edv.de>
parents: 198
diff changeset
262 remap_chars[c] = None
0a40d8a4057e fixed logfile breaking when DeletePage/RenamePage comment contains CRLF chars
Thomas Waldmann <tw@waldmann-edv.de>
parents: 198
diff changeset
263 comment = comment.translate(remap_chars)
0a40d8a4057e fixed logfile breaking when DeletePage/RenamePage comment contains CRLF chars
Thomas Waldmann <tw@waldmann-edv.de>
parents: 198
diff changeset
264 return comment
0a40d8a4057e fixed logfile breaking when DeletePage/RenamePage comment contains CRLF chars
Thomas Waldmann <tw@waldmann-edv.de>
parents: 198
diff changeset
265
156
206b3db4eade RC: make NEW icon clickable, make long comment parts breakable (fixing ugly rendering for some use cases)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 132
diff changeset
266 def make_breakable(text, maxlen):
206b3db4eade RC: make NEW icon clickable, make long comment parts breakable (fixing ugly rendering for some use cases)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 132
diff changeset
267 """ make a text breakable by inserting spaces into nonbreakable parts
206b3db4eade RC: make NEW icon clickable, make long comment parts breakable (fixing ugly rendering for some use cases)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 132
diff changeset
268 """
206b3db4eade RC: make NEW icon clickable, make long comment parts breakable (fixing ugly rendering for some use cases)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 132
diff changeset
269 text = text.split(" ")
206b3db4eade RC: make NEW icon clickable, make long comment parts breakable (fixing ugly rendering for some use cases)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 132
diff changeset
270 newtext = []
206b3db4eade RC: make NEW icon clickable, make long comment parts breakable (fixing ugly rendering for some use cases)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 132
diff changeset
271 for part in text:
206b3db4eade RC: make NEW icon clickable, make long comment parts breakable (fixing ugly rendering for some use cases)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 132
diff changeset
272 if len(part) > maxlen:
206b3db4eade RC: make NEW icon clickable, make long comment parts breakable (fixing ugly rendering for some use cases)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 132
diff changeset
273 while part:
206b3db4eade RC: make NEW icon clickable, make long comment parts breakable (fixing ugly rendering for some use cases)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 132
diff changeset
274 newtext.append(part[:maxlen])
206b3db4eade RC: make NEW icon clickable, make long comment parts breakable (fixing ugly rendering for some use cases)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 132
diff changeset
275 part = part[maxlen:]
206b3db4eade RC: make NEW icon clickable, make long comment parts breakable (fixing ugly rendering for some use cases)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 132
diff changeset
276 else:
206b3db4eade RC: make NEW icon clickable, make long comment parts breakable (fixing ugly rendering for some use cases)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 132
diff changeset
277 newtext.append(part)
206b3db4eade RC: make NEW icon clickable, make long comment parts breakable (fixing ugly rendering for some use cases)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 132
diff changeset
278 return " ".join(newtext)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
279
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
280 ########################################################################
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
281 ### Storage
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
282 ########################################################################
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
283
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
284 # FIXME: These functions might be moved to storage module, when we have
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
285 # one. Then they will be called transparently whenever a page is saved.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
286
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
287 # Precompiled patterns for file name [un]quoting
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
288 UNSAFE = re.compile(r'[^a-zA-Z0-9_]+')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
289 QUOTED = re.compile(r'\(([a-fA-F0-9]+)\)')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
290
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
291
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
292 # FIXME: better name would be quoteWikiname
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
293 def quoteWikinameFS(wikiname, charset=config.charset):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
294 """ Return file system representation of a Unicode WikiName.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
295
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
296 Warning: will raise UnicodeError if wikiname can not be encoded using
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
297 charset. The default value of config.charset, 'utf-8' can encode any
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
298 character.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
299
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
300 @param wikiname: Unicode string possibly containing non-ascii characters
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
301 @param charset: charset to encode string
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
302 @rtype: string
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
303 @return: quoted name, safe for any file system
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
304 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
305 filename = wikiname.encode(charset)
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 930
diff changeset
306
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 930
diff changeset
307 quoted = []
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
308 location = 0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
309 for needle in UNSAFE.finditer(filename):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
310 # append leading safe stuff
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
311 quoted.append(filename[location:needle.start()])
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 930
diff changeset
312 location = needle.end()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
313 # Quote and append unsafe stuff
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
314 quoted.append('(')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
315 for character in needle.group():
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
316 quoted.append('%02x' % ord(character))
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
317 quoted.append(')')
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 930
diff changeset
318
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
319 # append rest of string
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 930
diff changeset
320 quoted.append(filename[location:])
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
321 return ''.join(quoted)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
322
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
323
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
324 # FIXME: better name would be unquoteFilename
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
325 def unquoteWikiname(filename, charsets=[config.charset]):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
326 """ Return Unicode WikiName from quoted file name.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
327
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
328 We raise an InvalidFileNameError if we find an invalid name, so the
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
329 wiki could alarm the admin or suggest the user to rename a page.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
330 Invalid file names should never happen in normal use, but are rather
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
331 cheap to find.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
332
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
333 This function should be used only to unquote file names, not page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
334 names we receive from the user. These are handled in request by
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
335 urllib.unquote, decodePagename and normalizePagename.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
336
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
337 Todo: search clients of unquoteWikiname and check for exceptions.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
338
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
339 @param filename: string using charset and possibly quoted parts
490
ca35d9e6d63e eypdoc comments: fixed some warnings/errors
Thomas Waldmann <tw@waldmann-edv.de>
parents: 471
diff changeset
340 @param charsets: list of charsets used by string
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
341 @rtype: Unicode String
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
342 @return: WikiName
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
343 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
344 ### Temporary fix start ###
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
345 # From some places we get called with Unicode strings
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
346 if isinstance(filename, type(u'')):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
347 filename = filename.encode(config.charset)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
348 ### Temporary fix end ###
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 930
diff changeset
349
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 930
diff changeset
350 parts = []
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
351 start = 0
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 930
diff changeset
352 for needle in QUOTED.finditer(filename):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
353 # append leading unquoted stuff
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
354 parts.append(filename[start:needle.start()])
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 930
diff changeset
355 start = needle.end()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
356 # Append quoted stuff
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 930
diff changeset
357 group = needle.group(1)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
358 # Filter invalid filenames
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
359 if (len(group) % 2 != 0):
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 930
diff changeset
360 raise InvalidFileNameError(filename)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
361 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
362 for i in range(0, len(group), 2):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
363 byte = group[i:i+2]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
364 character = chr(int(byte, 16))
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
365 parts.append(character)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
366 except ValueError:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
367 # byte not in hex, e.g 'xy'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
368 raise InvalidFileNameError(filename)
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 930
diff changeset
369
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
370 # append rest of string
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
371 if start == 0:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
372 wikiname = filename
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
373 else:
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 930
diff changeset
374 parts.append(filename[start:len(filename)])
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
375 wikiname = ''.join(parts)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
376
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
377 # This looks wrong, because at this stage "()" can be both errors
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
378 # like open "(" without close ")", or unquoted valid characters in
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
379 # the file name. FIXME: check this.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
380 # Filter invalid filenames. Any left (xx) must be invalid
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
381 #if '(' in wikiname or ')' in wikiname:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
382 # raise InvalidFileNameError(filename)
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 930
diff changeset
383
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
384 wikiname = decodeUserInput(wikiname, charsets)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
385 return wikiname
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
386
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
387 # time scaling
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
388 def timestamp2version(ts):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
389 """ Convert UNIX timestamp (may be float or int) to our version
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
390 (long) int.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
391 We don't want to use floats, so we just scale by 1e6 to get
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
392 an integer in usecs.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
393 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
394 return long(ts*1000000L) # has to be long for py 2.2.x
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
395
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
396 def version2timestamp(v):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
397 """ Convert version number to UNIX timestamp (float).
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
398 This must ONLY be used for display purposes.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
399 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
400 return v/1000000.0
497
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
401
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
402
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
403 # This is the list of meta attribute names to be treated as integers.
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
404 # IMPORTANT: do not use any meta attribute names with "-" (or any other chars
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
405 # invalid in python attribute names), use e.g. _ instead.
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
406 INTEGER_METAS = ['current', 'revision', # for page storage (moin 2.0)
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
407 'data_format_revision', # for data_dir format spec (use by mig scripts)
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
408 ]
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
409
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
410 class MetaDict(dict):
1088
55ebe3c0867c Fixed bugs, raise exceptions on locking.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1085
diff changeset
411 """ store meta informations as a dict.
55ebe3c0867c Fixed bugs, raise exceptions on locking.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1085
diff changeset
412 XXX It is not thread-safe, add locks!
55ebe3c0867c Fixed bugs, raise exceptions on locking.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1085
diff changeset
413 """
1111
2aa53ed0afa0 Fix the unrespected cache_dir problem.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1090
diff changeset
414 def __init__(self, metafilename, cache_directory):
497
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
415 """ create a MetaDict from metafilename """
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
416 dict.__init__(self)
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
417 self.metafilename = metafilename
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
418 self.dirty = False
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
419 self.loaded = False
1111
2aa53ed0afa0 Fix the unrespected cache_dir problem.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1090
diff changeset
420 lock_dir = os.path.join(cache_directory, '__metalock__')
1082
ba25ee4ea61d Added locking to the MetaDict code.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1079
diff changeset
421 self.rlock = lock.ReadLock(lock_dir, 60.0)
ba25ee4ea61d Added locking to the MetaDict code.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1079
diff changeset
422 self.wlock = lock.WriteLock(lock_dir, 60.0)
497
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
423
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
424 def _get_meta(self):
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
425 """ get the meta dict from an arbitrary filename.
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
426 does not keep state, does uncached, direct disk access.
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
427 @param metafilename: the name of the file to read
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
428 @return: dict with all values or {} if empty or error
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
429 """
1082
ba25ee4ea61d Added locking to the MetaDict code.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1079
diff changeset
430
497
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
431 try:
1088
55ebe3c0867c Fixed bugs, raise exceptions on locking.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1085
diff changeset
432 if not self.rlock.acquire(3.0):
55ebe3c0867c Fixed bugs, raise exceptions on locking.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1085
diff changeset
433 raise EnvironmentError("Could not lock in MetaDict")
1082
ba25ee4ea61d Added locking to the MetaDict code.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1079
diff changeset
434 try:
ba25ee4ea61d Added locking to the MetaDict code.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1079
diff changeset
435 metafile = codecs.open(self.metafilename, "r", "utf-8")
ba25ee4ea61d Added locking to the MetaDict code.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1079
diff changeset
436 meta = metafile.read() # this is much faster than the file's line-by-line iterator
ba25ee4ea61d Added locking to the MetaDict code.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1079
diff changeset
437 metafile.close()
ba25ee4ea61d Added locking to the MetaDict code.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1079
diff changeset
438 finally:
ba25ee4ea61d Added locking to the MetaDict code.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1079
diff changeset
439 self.rlock.release()
497
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
440 except IOError:
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
441 meta = u''
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
442 for line in meta.splitlines():
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
443 key, value = line.split(':', 1)
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
444 value = value.strip()
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
445 if key in INTEGER_METAS:
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
446 value = int(value)
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
447 dict.__setitem__(self, key, value)
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
448 self.loaded = True
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 930
diff changeset
449
497
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
450 def _put_meta(self):
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
451 """ put the meta dict into an arbitrary filename.
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
452 does not keep or modify state, does uncached, direct disk access.
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
453 @param metafilename: the name of the file to write
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
454 @param metadata: dict of the data to write to the file
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
455 """
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
456 meta = []
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
457 for key, value in self.items():
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
458 if key in INTEGER_METAS:
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
459 value = str(value)
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
460 meta.append("%s: %s" % (key, value))
1079
029754c52b11 Changed file format of meta file (\r\n line endings). Enhanced docstrings.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1019
diff changeset
461 meta = '\r\n'.join(meta)
1088
55ebe3c0867c Fixed bugs, raise exceptions on locking.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1085
diff changeset
462
55ebe3c0867c Fixed bugs, raise exceptions on locking.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1085
diff changeset
463 if not self.wlock.acquire(5.0):
55ebe3c0867c Fixed bugs, raise exceptions on locking.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1085
diff changeset
464 raise EnvironmentError("Could not lock in MetaDict")
1082
ba25ee4ea61d Added locking to the MetaDict code.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1079
diff changeset
465 try:
ba25ee4ea61d Added locking to the MetaDict code.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1079
diff changeset
466 metafile = codecs.open(self.metafilename, "w", "utf-8")
ba25ee4ea61d Added locking to the MetaDict code.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1079
diff changeset
467 metafile.write(meta)
ba25ee4ea61d Added locking to the MetaDict code.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1079
diff changeset
468 metafile.close()
ba25ee4ea61d Added locking to the MetaDict code.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1079
diff changeset
469 finally:
ba25ee4ea61d Added locking to the MetaDict code.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1079
diff changeset
470 self.wlock.release()
497
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
471 filesys.chmod(self.metafilename, 0666 & config.umask)
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
472 self.dirty = False
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
473
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
474 def sync(self, mtime_usecs=None):
1079
029754c52b11 Changed file format of meta file (\r\n line endings). Enhanced docstrings.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1019
diff changeset
475 """ sync the in-memory dict to the persistent store (if dirty) """
497
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
476 if self.dirty:
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
477 if not mtime_usecs is None:
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
478 self.__setitem__('mtime', str(mtime_usecs))
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
479 self._put_meta()
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
480
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
481 def __getitem__(self, key):
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
482 try:
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
483 return dict.__getitem__(self, key)
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
484 except KeyError:
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
485 if not self.loaded:
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
486 self._get_meta() # lazy loading of metadata
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
487 return dict.__getitem__(self, key)
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
488 else:
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
489 raise
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
490
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
491 def __setitem__(self, key, value):
1079
029754c52b11 Changed file format of meta file (\r\n line endings). Enhanced docstrings.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1019
diff changeset
492 """ Sets a dictionary entry. You actually have to call sync to write it
029754c52b11 Changed file format of meta file (\r\n line endings). Enhanced docstrings.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1019
diff changeset
493 to the persistent store. """
497
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
494 try:
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
495 oldvalue = dict.__getitem__(self, key)
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
496 except KeyError:
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
497 oldvalue = None
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
498 if value != oldvalue:
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
499 dict.__setitem__(self, key, value)
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
500 self.dirty = True
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
501
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
502
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
503 #############################################################################
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
504 ### InterWiki
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
505 #############################################################################
1122
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
506 INTERWIKI_PAGE = "InterWikiMap"
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
507
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
508 def generate_file_list(request):
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
509 """ generates a list of all files. for internal use. """
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
510
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
511 # order is important here, the local intermap file takes
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
512 # precedence over the shared one, and is thus read AFTER
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
513 # the shared one
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
514 intermap_files = request.cfg.shared_intermap
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
515 if not isinstance(intermap_files, list):
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
516 intermap_files = [intermap_files]
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
517 else:
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
518 intermap_files = intermap_files[:]
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
519 intermap_files.append(os.path.join(request.cfg.data_dir, "intermap.txt"))
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
520 request.cfg.shared_intermap_files = [filename for filename in intermap_files
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
521 if filename and os.path.isfile(filename)]
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
522
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
523
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
524 def get_max_mtime(file_list, page):
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
525 """ Returns the highest modification time of the files in file_list and the
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
526 page page. """
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
527 return max([os.stat(filename).st_mtime for filename in file_list] +
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
528 [version2timestamp(page.mtime_usecs())])
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
529
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
530
828
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
531 def load_wikimap(request):
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
532 """ load interwiki map (once, and only on demand) """
1122
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
533 from MoinMoin.Page import Page
1088
55ebe3c0867c Fixed bugs, raise exceptions on locking.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1085
diff changeset
534
55ebe3c0867c Fixed bugs, raise exceptions on locking.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1085
diff changeset
535 now = int(time.time())
1122
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
536 if getattr(request.cfg, "shared_intermap_files", None) is None:
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
537 generate_file_list(request)
1085
2bcb7bdf94a2 Implemented an editable InterWikiMap, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1082
diff changeset
538
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
539 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
540 _interwiki_list = request.cfg._interwiki_list
1122
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
541 old_mtime = request.cfg._interwiki_mtime
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
542 if request.cfg._interwiki_ts + (1*60) < now: # 1 minutes caching time
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
543 max_mtime = get_max_mtime(request.cfg.shared_intermap_files, Page(request, INTERWIKI_PAGE))
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
544 if max_mtime > old_mtime:
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
545 raise AttributeError # refresh cache
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
546 else:
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
547 request.cfg._interwiki_ts = now
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
548 except AttributeError:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
549 _interwiki_list = {}
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
550 lines = []
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 930
diff changeset
551
1122
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
552 for filename in request.cfg.shared_intermap_files:
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
553 f = open(filename, "r")
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
554 lines.extend(f.readlines())
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
555 f.close()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
556
1085
2bcb7bdf94a2 Implemented an editable InterWikiMap, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1082
diff changeset
557 # add the contents of the InterWikiMap page
1122
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
558 lines += Page(request, INTERWIKI_PAGE).get_raw_body().splitlines()
1085
2bcb7bdf94a2 Implemented an editable InterWikiMap, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1082
diff changeset
559
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
560 for line in lines:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
561 if not line or line[0] == '#': continue
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
562 try:
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 930
diff changeset
563 line = "%s %s/InterWiki" % (line, request.getScriptname())
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
564 wikitag, urlprefix, trash = line.split(None, 2)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
565 except ValueError:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
566 pass
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
567 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
568 _interwiki_list[wikitag] = urlprefix
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
569
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
570 del lines
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
571
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
572 # add own wiki as "Self" and by its configured name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
573 _interwiki_list['Self'] = request.getScriptname() + '/'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
574 if request.cfg.interwikiname:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
575 _interwiki_list[request.cfg.interwikiname] = request.getScriptname() + '/'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
576
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
577 # save for later
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
578 request.cfg._interwiki_list = _interwiki_list
1085
2bcb7bdf94a2 Implemented an editable InterWikiMap, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1082
diff changeset
579 request.cfg._interwiki_ts = now
1122
2be8ec7ba817 Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1111
diff changeset
580 request.cfg._interwiki_mtime = get_max_mtime(request.cfg.shared_intermap_files, Page(request, INTERWIKI_PAGE))
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 930
diff changeset
581
828
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
582 return _interwiki_list
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 930
diff changeset
583
828
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
584 def split_wiki(wikiurl):
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
585 """ Split a wiki url, e.g:
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
586
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
587 'MoinMoin:FrontPage' -> "MoinMoin", "FrontPage", ""
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
588 'FrontPage' -> "Self", "FrontPage", ""
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
589 'MoinMoin:"Page with blanks" link title' -> "MoinMoin", "Page with blanks", "link title"
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
590
828
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
591 can also be used for:
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
592
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
593 'attachment:"filename with blanks.txt" other title' -> "attachment", "filename with blanks.txt", "other title"
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
594
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
595 @param wikiurl: the url to split
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
596 @rtype: tuple
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
597 @return: (wikiname, pagename, linktext)
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
598 """
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
599 try:
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
600 wikiname, rest = wikiurl.split(":", 1) # e.g. MoinMoin:FrontPage
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
601 except ValueError:
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
602 try:
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
603 wikiname, rest = wikiurl.split("/", 1) # for what is this used?
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
604 except ValueError:
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
605 wikiname, rest = 'Self', wikiurl
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
606 first_char = rest[0]
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
607 if first_char in "'\"": # quoted pagename
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
608 pagename_linktext = rest[1:].split(first_char, 1)
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
609 else: # not quoted, split on whitespace
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
610 pagename_linktext = rest.split(None, 1)
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
611 if len(pagename_linktext) == 1:
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
612 pagename, linktext = pagename_linktext[0], ""
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
613 else:
828
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
614 pagename, linktext = pagename_linktext
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
615 linktext = linktext.strip()
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
616 return wikiname, pagename, linktext
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
617
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
618 def resolve_wiki(request, wikiurl):
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
619 """ Resolve an interwiki link.
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
620
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
621 @param request: the request object
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
622 @param wikiurl: the InterWiki:PageName link
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
623 @rtype: tuple
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
624 @return: (wikitag, wikiurl, wikitail, err)
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
625 """
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
626 _interwiki_list = load_wikimap(request)
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
627 wikiname, pagename, linktext = split_wiki(wikiurl)
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
628 if _interwiki_list.has_key(wikiname):
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
629 return (wikiname, _interwiki_list[wikiname], pagename, False)
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
630 else:
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
631 return (wikiname, request.getScriptname(), "/InterWiki", True)
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
632
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
633 def join_wiki(wikiurl, wikitail):
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
634 """
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
635 Add a (url_quoted) page name to an interwiki url.
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
636
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
637 Note: We can't know what kind of URL quoting a remote wiki expects.
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
638 We just use a utf-8 encoded string with standard URL quoting.
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
639
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
640 @param wikiurl: wiki url, maybe including a $PAGE placeholder
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
641 @param wikitail: page name
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
642 @rtype: string
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
643 @return: generated URL of the page in the other wiki
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
644 """
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
645 wikitail = url_quote(wikitail)
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
646 if '$PAGE' in wikiurl:
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
647 return wikiurl.replace('$PAGE', wikitail)
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
648 else:
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
649 return wikiurl + wikitail
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
650
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
651
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
652 #############################################################################
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
653 ### Page types (based on page names)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
654 #############################################################################
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
655
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
656 def isSystemPage(request, pagename):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
657 """ Is this a system page? Uses AllSystemPagesGroup internally.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
658
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
659 @param request: the request object
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
660 @param pagename: the page name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
661 @rtype: bool
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
662 @return: true if page is a system page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
663 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
664 return (request.dicts.has_member('SystemPagesGroup', pagename) or
413
c85132ab35e3 Removed form code (which had been broken since it was hacked into) and the export action (which had been in a similar state).
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 393
diff changeset
665 isTemplatePage(request, pagename))
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
666
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
667
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
668 def isTemplatePage(request, pagename):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
669 """ Is this a template page?
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
670
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
671 @param pagename: the page name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
672 @rtype: bool
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
673 @return: true if page is a template page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
674 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
675 filter = re.compile(request.cfg.page_template_regex, re.UNICODE)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
676 return filter.search(pagename) is not None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
677
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
678
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
679 def isGroupPage(request, pagename):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
680 """ Is this a name of group page?
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
681
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
682 @param pagename: the page name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
683 @rtype: bool
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
684 @return: true if page is a form page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
685 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
686 filter = re.compile(request.cfg.page_group_regex, re.UNICODE)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
687 return filter.search(pagename) is not None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
688
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
689
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
690 def filterCategoryPages(request, pagelist):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
691 """ Return category pages in pagelist
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
692
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
693 WARNING: DO NOT USE THIS TO FILTER THE FULL PAGE LIST! Use
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
694 getPageList with a filter function.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
695
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
696 If you pass a list with a single pagename, either that is returned
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
697 or an empty list, thus you can use this function like a `isCategoryPage`
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
698 one.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
699
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
700 @param pagelist: a list of pages
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
701 @rtype: list
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
702 @return: only the category pages of pagelist
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
703 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
704 func = re.compile(request.cfg.page_category_regex, re.UNICODE).search
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
705 return filter(func, pagelist)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
706
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
707
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
708 # TODO: we may rename this to getLocalizedPage because it returns page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
709 # that have translations.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
710 def getSysPage(request, pagename):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
711 """ Get a system page according to user settings and available translations.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
712
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
713 We include some special treatment for the case that <pagename> is the
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
714 currently rendered page, as this is the case for some pages used very
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
715 often, like FrontPage, RecentChanges etc. - in that case we reuse the
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
716 already existing page object instead creating a new one.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
717
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
718 @param request: the request object
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
719 @param pagename: the name of the page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
720 @rtype: Page object
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
721 @return: the page object of that system page, using a translated page,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
722 if it exists
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
723 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
724 from MoinMoin.Page import Page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
725 i18n_name = request.getText(pagename, formatted=False)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
726 pageobj = None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
727 if i18n_name != pagename:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
728 if request.page and i18n_name == request.page.page_name:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
729 # do not create new object for current page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
730 i18n_page = request.page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
731 if i18n_page.exists():
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
732 pageobj = i18n_page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
733 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
734 i18n_page = Page(request, i18n_name)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
735 if i18n_page.exists():
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
736 pageobj = i18n_page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
737
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
738 # if we failed getting a translated version of <pagename>,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
739 # we fall back to english
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
740 if not pageobj:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
741 if request.page and pagename == request.page.page_name:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
742 # do not create new object for current page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
743 pageobj = request.page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
744 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
745 pageobj = Page(request, pagename)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
746 return pageobj
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
747
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
748
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
749 def getFrontPage(request):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
750 """ Convenience function to get localized front page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
751
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
752 @param request: current request
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
753 @rtype: Page object
35
f0af060fb82b making people choose the right approach to page_front_page
Thomas Waldmann <tw@waldmann-edv.de>
parents: 33
diff changeset
754 @return localized page_front_page, if there is a translation
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
755 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
756 return getSysPage(request, request.cfg.page_front_page)
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 930
diff changeset
757
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
758
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
759 def getHomePage(request, username=None):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
760 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
761 Get a user's homepage, or return None for anon users and
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
762 those who have not created a homepage.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
763
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
764 DEPRECATED - try to use getInterwikiHomePage (see below)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
765
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
766 @param request: the request object
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
767 @param username: the user's name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
768 @rtype: Page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
769 @return: user's homepage object - or None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
770 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
771 from MoinMoin.Page import Page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
772 # default to current user
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
773 if username is None and request.user.valid:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
774 username = request.user.name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
775
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
776 # known user?
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
777 if username:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
778 # Return home page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
779 page = Page(request, username)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
780 if page.exists():
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
781 return page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
782
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
783 return None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
784
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
785
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
786 def getInterwikiHomePage(request, username=None):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
787 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
788 Get a user's homepage.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
789
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
790 cfg.user_homewiki influences behaviour of this:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
791 'Self' does mean we store user homepage in THIS wiki.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
792 When set to our own interwikiname, it behaves like with 'Self'.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
793
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
794 'SomeOtherWiki' means we store user homepages in another wiki.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
795
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
796 @param request: the request object
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
797 @param username: the user's name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
798 @rtype: tuple (or None for anon users)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
799 @return: (wikiname, pagename)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
800 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
801 # default to current user
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
802 if username is None and request.user.valid:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
803 username = request.user.name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
804 if not username:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
805 return None # anon user
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
806
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
807 homewiki = request.cfg.user_homewiki
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
808 if homewiki == request.cfg.interwikiname:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
809 homewiki = 'Self'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
810
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
811 return homewiki, username
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
812
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
813
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
814 def AbsPageName(request, context, pagename):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
815 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
816 Return the absolute pagename for a (possibly) relative pagename.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
817
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
818 @param context: name of the page where "pagename" appears on
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
819 @param pagename: the (possibly relative) page name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
820 @rtype: string
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
821 @return: the absolute page name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
822 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
823 if pagename.startswith(PARENT_PREFIX):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
824 pagename = '/'.join(filter(None, context.split('/')[:-1] + [pagename[PARENT_PREFIX_LEN:]]))
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
825 elif pagename.startswith(CHILD_PREFIX):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
826 pagename = context + '/' + pagename[CHILD_PREFIX_LEN:]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
827 return pagename
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
828
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
829 def pagelinkmarkup(pagename):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
830 """ return markup that can be used as link to page <pagename> """
657
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
831 from MoinMoin.parser.text_moin_wiki import Parser
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
832 if re.match(Parser.word_rule + "$", pagename):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
833 return pagename
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
834 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
835 return u'["%s"]' % pagename
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
836
801
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
837 #############################################################################
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
838 ### mimetype support
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
839 #############################################################################
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
840 import mimetypes
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
841
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
842 MIMETYPES_MORE = {
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
843 # OpenOffice 2.x & other open document stuff
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
844 '.odt': 'application/vnd.oasis.opendocument.text',
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
845 '.ods': 'application/vnd.oasis.opendocument.spreadsheet',
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
846 '.odp': 'application/vnd.oasis.opendocument.presentation',
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
847 '.odg': 'application/vnd.oasis.opendocument.graphics',
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
848 '.odc': 'application/vnd.oasis.opendocument.chart',
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
849 '.odf': 'application/vnd.oasis.opendocument.formula',
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
850 '.odb': 'application/vnd.oasis.opendocument.database',
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
851 '.odi': 'application/vnd.oasis.opendocument.image',
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
852 '.odm': 'application/vnd.oasis.opendocument.text-master',
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
853 '.ott': 'application/vnd.oasis.opendocument.text-template',
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
854 '.ots': 'application/vnd.oasis.opendocument.spreadsheet-template',
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
855 '.otp': 'application/vnd.oasis.opendocument.presentation-template',
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
856 '.otg': 'application/vnd.oasis.opendocument.graphics-template',
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
857 }
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
858 [mimetypes.add_type(mimetype, ext, True) for ext, mimetype in MIMETYPES_MORE.items()]
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
859
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
860 MIMETYPES_sanitize_mapping = {
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
861 # this stuff is text, but got application/* for unknown reasons
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
862 ('application', 'docbook+xml'): ('text', 'docbook'),
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
863 ('application', 'x-latex'): ('text', 'latex'),
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
864 ('application', 'x-tex'): ('text', 'tex'),
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
865 ('application', 'javascript'): ('text', 'javascript'),
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
866 }
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
867
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
868 MIMETYPES_spoil_mapping = {} # inverse mapping of above
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
869 for key, value in MIMETYPES_sanitize_mapping.items():
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
870 MIMETYPES_spoil_mapping[value] = key
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
871
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
872
657
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
873 # mimetype stuff ------------------------------------------------------------
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
874 class MimeType(object):
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
875 """ represents a mimetype like text/plain """
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 930
diff changeset
876
657
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
877 def __init__(self, mimestr=None, filename=None):
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
878 self.major = self.minor = None # sanitized mime type and subtype
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
879 self.params = {} # parameters like "charset" or others
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
880 self.charset = None # this stays None until we know for sure!
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
881
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
882 if mimestr:
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
883 self.parse_mimetype(mimestr)
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
884 elif filename:
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
885 self.parse_filename(filename)
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 930
diff changeset
886
657
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
887 def parse_filename(self, filename):
773
bc1e460db2c8 fix bug in MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 672
diff changeset
888 mtype, encoding = mimetypes.guess_type(filename)
657
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
889 if mtype is None:
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
890 mtype = 'application/octet-stream'
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
891 self.parse_mimetype(mtype)
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 930
diff changeset
892
657
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
893 def parse_mimetype(self, mimestr):
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
894 """ take a string like used in content-type and parse it into components,
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
895 alternatively it also can process some abbreviated string like "wiki"
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
896 """
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
897 parameters = mimestr.split(";")
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
898 parameters = [p.strip() for p in parameters]
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
899 mimetype, parameters = parameters[0], parameters[1:]
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
900 mimetype = mimetype.split('/')
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
901 if len(mimetype) >= 2:
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
902 major, minor = mimetype[:2] # we just ignore more than 2 parts
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
903 else:
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
904 major, minor = self.parse_format(mimetype[0])
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
905 self.major = major.lower()
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
906 self.minor = minor.lower()
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
907 for param in parameters:
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
908 key, value = param.split('=')
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
909 if value[0] == '"' and value[-1] == '"': # remove quotes
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
910 value = value[1:-1]
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
911 self.params[key.lower()] = value
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
912 if self.params.has_key('charset'):
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
913 self.charset = self.params['charset'].lower()
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
914 self.sanitize()
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 930
diff changeset
915
657
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
916 def parse_format(self, format):
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
917 """ maps from what we currently use on-page in a #format xxx processing
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
918 instruction to a sanitized mimetype major, minor tuple.
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
919 can also be user later for easier entry by the user, so he can just
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
920 type "wiki" instead of "text/moin-wiki".
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
921 """
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
922 format = format.lower()
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
923 if format in ('plain', 'csv', 'rst', 'docbook', 'latex', 'tex', 'html', 'css',
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
924 'xml', 'python', 'perl', 'php', 'ruby', 'javascript',
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
925 'cplusplus', 'java', 'pascal', 'diff', 'gettext', 'xslt', ):
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
926 mimetype = 'text', format
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
927 else:
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
928 mapping = {
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
929 'wiki': ('text', 'moin-wiki'),
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
930 'irc': ('text', 'irssi'),
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
931 }
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
932 try:
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
933 mimetype = mapping[format]
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
934 except KeyError:
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
935 mimetype = 'text', 'x-%s' % format
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
936 return mimetype
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
937
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
938 def sanitize(self):
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
939 """ convert to some representation that makes sense - this is not necessarily
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
940 conformant to /etc/mime.types or IANA listing, but if something is
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
941 readable text, we will return some text/* mimetype, not application/*,
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
942 because we need text/plain as fallback and not application/octet-stream.
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
943 """
801
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
944 self.major, self.minor = MIMETYPES_sanitize_mapping.get((self.major, self.minor), (self.major, self.minor))
657
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
945
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
946 def spoil(self):
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
947 """ this returns something conformant to /etc/mime.type or IANA as a string,
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
948 kind of inverse operation of sanitize(), but doesn't change self
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
949 """
801
1f8976e01c3a fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
950 major, minor = MIMETYPES_spoil_mapping.get((self.major, self.minor), (self.major, self.minor))
657
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
951 return self.content_type(major, minor)
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
952
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
953 def content_type(self, major=None, minor=None, charset=None, params=None):
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
954 """ return a string suitable for Content-Type header
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
955 """
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
956 major = major or self.major
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
957 minor = minor or self.minor
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
958 params = params or self.params or {}
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
959 if major == 'text':
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
960 charset = charset or self.charset or params.get('charset', config.charset)
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
961 params['charset'] = charset
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
962 mimestr = "%s/%s" % (major, minor)
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
963 params = ['%s="%s"' % (key.lower(), value) for key, value in params.items()]
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
964 params.insert(0, mimestr)
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
965 return "; ".join(params)
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
966
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
967 def mime_type(self):
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
968 """ return a string major/minor only, no params """
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
969 return "%s/%s" % (self.major, self.minor)
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
970
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
971 def module_name(self):
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
972 """ convert this mimetype to a string useable as python module name,
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
973 we yield the exact module name first and then proceed to shorter
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
974 module names (useful for falling back to them, if the more special
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
975 module is not found) - e.g. first "text_python", next "text".
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
976 Finally, we yield "application_octet_stream" as the most general
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
977 mimetype we have.
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
978 Hint: the fallback handler module for text/* should be implemented
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
979 in module "text" (not "text_plain")
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
980 """
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
981 mimetype = self.mime_type()
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
982 modname = mimetype.replace("/", "_").replace("-", "_").replace(".", "_")
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
983 fragments = modname.split('_')
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
984 for length in range(len(fragments), 0, -1):
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
985 yield "_".join(fragments[:length])
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
986 yield "application_octet_stream"
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
987
016a8a3ef354 wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 639
diff changeset
988
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
989 #############################################################################
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
990 ### Plugins
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
991 #############################################################################
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
992
53
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
993 class PluginError(Exception):
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
994 """ Base class for plugin errors """
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
995
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
996 class PluginMissingError(PluginError):
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
997 """ Raised when a plugin is not found """
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
998
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
999 class PluginAttributeError(PluginError):
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
1000 """ Raised when plugin does not contain an attribtue """
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
1001
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
1002
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1003 def importPlugin(cfg, kind, name, function="execute"):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1004 """ Import wiki or builtin plugin
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1005
53
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
1006 Returns function from a plugin module name. If name can not be
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
1007 imported, raise PluginMissingError. If function is missing, raise
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
1008 PluginAttributeError.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1009
639
a80a6c629bc3 remove processor support, use a parser now
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 616
diff changeset
1010 kind may be one of 'action', 'formatter', 'macro', 'parser' or any other
a80a6c629bc3 remove processor support, use a parser now
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 616
diff changeset
1011 directory that exist in MoinMoin or data/plugin.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1012
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1013 Wiki plugins will always override builtin plugins. If you want
53
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
1014 specific plugin, use either importWikiPlugin or importBuiltinPlugin
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
1015 directly.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1016
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1017 @param cfg: wiki config instance
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1018 @param kind: what kind of module we want to import
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1019 @param name: the name of the module
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1020 @param function: the function name
53
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
1021 @rtype: any object
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1022 @return: "function" of module "name" of kind "kind", or None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1023 """
51
54d5932d5a03 merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents: 35
diff changeset
1024 try:
53
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
1025 return importWikiPlugin(cfg, kind, name, function)
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
1026 except PluginMissingError:
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
1027 return importBuiltinPlugin(kind, name, function)
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
1028
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1029
497
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
1030 def importWikiPlugin(cfg, kind, name, function="execute"):
53
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
1031 """ Import plugin from the wiki data directory
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1032
53
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
1033 See importPlugin docstring.
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
1034 """
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
1035 if not name in wikiPlugins(kind, cfg):
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
1036 raise PluginMissingError
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
1037 moduleName = '%s.plugin.%s.%s' % (cfg.siteid, kind, name)
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
1038 return importNameFromPlugin(moduleName, function)
51
54d5932d5a03 merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents: 35
diff changeset
1039
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1040
497
ef41e35985dc new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
1041 def importBuiltinPlugin(kind, name, function="execute"):
53
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
1042 """ Import builtin plugin from MoinMoin package
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
1043
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
1044 See importPlugin docstring.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1045 """
53
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
1046 if not name in builtinPlugins(kind):
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
1047 raise PluginMissingError
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
1048 moduleName = 'MoinMoin.%s.%s' % (kind, name)
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
1049 return importNameFromPlugin(moduleName, function)
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
1050
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
1051
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
1052 def importNameFromPlugin(moduleName, name):
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
1053 """ Return name from plugin module
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
1054
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
1055 Raise PluginAttributeError if name does not exists.
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
1056 """
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
1057 module = __import__(moduleName, globals(), {}, [name])
51
54d5932d5a03 merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents: 35
diff changeset
1058 try:
53
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
1059 return getattr(module, name)
51
54d5932d5a03 merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents: 35
diff changeset
1060 except AttributeError:
53
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
1061 raise PluginAttributeError
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1062
51
54d5932d5a03 merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents: 35
diff changeset
1063
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1064 def builtinPlugins(kind):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1065 """ Gets a list of modules in MoinMoin.'kind'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1066
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1067 @param kind: what kind of modules we look for
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1068 @rtype: list
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1069 @return: module names
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1070 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1071 modulename = "MoinMoin." + kind
51
54d5932d5a03 merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents: 35
diff changeset
1072 return pysupport.importName(modulename, "modules")
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1073
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1074
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1075 def wikiPlugins(kind, cfg):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1076 """ Gets a list of modules in data/plugin/'kind'
51
54d5932d5a03 merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents: 35
diff changeset
1077
54d5932d5a03 merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents: 35
diff changeset
1078 Require valid plugin directory. e.g missing 'parser' directory or
54d5932d5a03 merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents: 35
diff changeset
1079 missing '__init__.py' file will raise errors.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1080
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1081 @param kind: what kind of modules we look for
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1082 @rtype: list
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1083 @return: module names
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1084 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1085 # Wiki plugins are located in wikiconfig.plugin module
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1086 modulename = '%s.plugin.%s' % (cfg.siteid, kind)
51
54d5932d5a03 merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents: 35
diff changeset
1087 return pysupport.importName(modulename, "modules")
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1088
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1089
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1090 def getPlugins(kind, cfg):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1091 """ Gets a list of plugin names of kind
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1092
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1093 @param kind: what kind of modules we look for
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1094 @rtype: list
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1095 @return: module names
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1096 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1097 # Copy names from builtin plugins - so we dont destroy the value
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1098 all_plugins = builtinPlugins(kind)[:]
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 930
diff changeset
1099
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1100 # Add extension plugins without duplicates
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1101 for plugin in wikiPlugins(kind, cfg):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1102 if plugin not in all_plugins:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1103 all_plugins.append(plugin)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1104
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1105 return all_plugins
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1106
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1107
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1108 #############################################################################
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1109 ### Parsers
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1110 #############################################################################
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1111
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1112 def getParserForExtension(cfg, extension):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1113 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1114 Returns the Parser class of the parser fit to handle a file
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1115 with the given extension. The extension should be in the same
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1116 format as os.path.splitext returns it (i.e. with the dot).
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1117 Returns None if no parser willing to handle is found.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1118 The dict of extensions is cached in the config object.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1119
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1120 @param cfg: the Config instance for the wiki in question
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1121 @param extension: the filename extension including the dot
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1122 @rtype: class, None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1123 @returns: the parser class or None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1124 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1125 if not hasattr(cfg, '_EXT_TO_PARSER'):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1126 etp, etd = {}, None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1127 for pname in getPlugins('parser', cfg):
51
54d5932d5a03 merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents: 35
diff changeset
1128 try:
54d5932d5a03 merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents: 35
diff changeset
1129 Parser = importPlugin(cfg, 'parser', pname, 'Parser')
104
67f71c7a8c43 some unicode related (and other) fixes for the last patches
Thomas Waldmann <tw@waldmann-edv.de>
parents: 102
diff changeset
1130 except PluginMissingError:
51
54d5932d5a03 merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents: 35
diff changeset
1131 continue
54d5932d5a03 merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents: 35
diff changeset
1132 if hasattr(Parser, 'extensions'):
54d5932d5a03 merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents: 35
diff changeset
1133 exts = Parser.extensions
54d5932d5a03 merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents: 35
diff changeset
1134 if type(exts) == types.ListType:
54d5932d5a03 merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents: 35
diff changeset
1135 for ext in Parser.extensions:
54d5932d5a03 merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents: 35
diff changeset
1136 etp[ext] = Parser
54d5932d5a03 merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents: 35
diff changeset
1137 elif str(exts) == '*':
54d5932d5a03 merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents: 35
diff changeset
1138 etd = Parser
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1139 cfg._EXT_TO_PARSER = etp
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1140 cfg._EXT_TO_PARSER_DEFAULT = etd
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 930
diff changeset
1141
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1142 return cfg._EXT_TO_PARSER.get(extension, cfg._EXT_TO_PARSER_DEFAULT)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1143
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1144
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1145 #############################################################################
671
68d93872d4c9 removed duplicate code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 657
diff changeset
1146 ### Parameter parsing
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1147 #############################################################################
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1148
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1149 def parseAttributes(request, attrstring, endtoken=None, extension=None):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1150 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1151 Parse a list of attributes and return a dict plus a possible
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1152 error message.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1153 If extension is passed, it has to be a callable that returns
517
39da9e68875c wikiutil.parseAttribute extension now must return a tuple (found_flag, errmsg), fixing table attr parsing
Thomas Waldmann <tw@waldmann-edv.de>
parents: 515
diff changeset
1154 a tuple (found_flag, msg). found_flag is whether it did find and process
39da9e68875c wikiutil.parseAttribute extension now must return a tuple (found_flag, errmsg), fixing table attr parsing
Thomas Waldmann <tw@waldmann-edv.de>
parents: 515
diff changeset
1155 something, msg is '' when all was OK or any other string to return an error
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1156 message.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1157
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1158 @param request: the request object
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1159 @param attrstring: string containing the attributes to be parsed
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1160 @param endtoken: token terminating parsing
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1161 @param extension: extension function -
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1162 gets called with the current token, the parser and the dict
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1163 @rtype: dict, msg
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1164 @return: a dict plus a possible error message
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1165 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1166 import shlex, StringIO
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1167
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1168 _ = request.getText
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1169
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1170 parser = shlex.shlex(StringIO.StringIO(attrstring))
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1171 parser.commenters = ''
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1172 msg = None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1173 attrs = {}
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1174
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1175 while not msg:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1176 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1177 key = parser.get_token()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1178 except ValueError, err:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1179 msg = str(err)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1180 break
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1181 if not key: break
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1182 if endtoken and key == endtoken: break
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1183
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1184 # call extension function with the current token, the parser, and the dict
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1185 if extension:
517
39da9e68875c wikiutil.parseAttribute extension now must return a tuple (found_flag, errmsg), fixing table attr parsing
Thomas Waldmann <tw@waldmann-edv.de>
parents: 515
diff changeset
1186 found_flag, msg = extension(key, parser, attrs)
39da9e68875c wikiutil.parseAttribute extension now must return a tuple (found_flag, errmsg), fixing table attr parsing
Thomas Waldmann <tw@waldmann-edv.de>
parents: 515
diff changeset
1187 #request.log("%r = extension(%r, parser, %r)" % (msg, key, attrs))
39da9e68875c wikiutil.parseAttribute extension now must return a tuple (found_flag, errmsg), fixing table attr parsing
Thomas Waldmann <tw@waldmann-edv.de>
parents: 515
diff changeset
1188 if found_flag:
39da9e68875c wikiutil.parseAttribute extension now must return a tuple (found_flag, errmsg), fixing table attr parsing
Thomas Waldmann <tw@waldmann-edv.de>
parents: 515
diff changeset
1189 continue
39da9e68875c wikiutil.parseAttribute extension now must return a tuple (found_flag, errmsg), fixing table attr parsing
Thomas Waldmann <tw@waldmann-edv.de>
parents: 515
diff changeset
1190 elif msg:
39da9e68875c wikiutil.parseAttribute extension now must return a tuple (found_flag, errmsg), fixing table attr parsing
Thomas Waldmann <tw@waldmann-edv.de>
parents: 515
diff changeset
1191 break
39da9e68875c wikiutil.parseAttribute extension now must return a tuple (found_flag, errmsg), fixing table attr parsing
Thomas Waldmann <tw@waldmann-edv.de>
parents: 515
diff changeset
1192 #else (we found nothing, but also didn't have an error msg) we just continue below:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1193
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1194 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1195 eq = parser.get_token()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1196 except ValueError, err:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1197 msg = str(err)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1198 break
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1199 if eq != "=":
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1200 msg = _('Expected "=" to follow "%(token)s"') % {'token': key}
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1201 break
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1202
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1203 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1204 val = parser.get_token()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1205 except ValueError, err:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1206 msg = str(err)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1207 break
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1208 if not val:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1209 msg = _('Expected a value for key "%(token)s"') % {'token': key}
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1210 break
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1211
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1212 key = escape(key) # make sure nobody cheats
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1213
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1214 # safely escape and quote value
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1215 if val[0] in ["'", '"']:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1216 val = escape(val)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1217 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1218 val = '"%s"' % escape(val, 1)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1219
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1220 attrs[key.lower()] = val
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1221
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1222 return attrs, msg or ''
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1223
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1224
672
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1225 class ParameterParser:
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1226 """ MoinMoin macro parameter parser
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1227
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1228 parses a given parameter string and seperates
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1229 the single parameters and detects their type
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1230
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1231 Possible parameterstypes are:
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1232
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1233 Name | short | example
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1234 ----------------------------
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1235 Integer | i | -374
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1236 Float | f | 234.234 23.345E-23
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1237 String | s | 'Stri\'ng'
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1238 Boolean | b | 0 1 True false
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1239 Name | | case_sensitive | converted to string
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1240
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1241 @copyright: 2004 by Florian Festi
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1242 @license: GNU GPL, see COPYING for details.
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1243 """
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1244
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1245 def __init__(self, pattern):
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1246 #parameter_re = "([^\"',]*(\"[^\"]*\"|'[^']*')?[^\"',]*)[,)]"
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1247 name = "(?P<%s>[a-zA-Z_][a-zA-Z0-9_]*)"
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1248 int_re = r"(?P<int>-?\d+)"
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1249 float_re = r"(?P<float>-?\d+\.\d+([eE][+-]?\d+)?)"
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1250 string_re = (r"(?P<string>('([^']|(\'))*?')|" +
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1251 r'("([^"]|(\"))*?"))')
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1252 name_re = name % "name"
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1253 name_param_re = name % "name_param"
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1254
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1255 param_re = r"\s*(\s*%s\s*=\s*)?(%s|%s|%s|%s)\s*(,|$)" % (
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1256 name_re, float_re, int_re, string_re, name_param_re)
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1257 self.param_re = re.compile(param_re, re.U)
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1258 self._parse_pattern(pattern)
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1259
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1260 def _parse_pattern(self, pattern):
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1261 param_re = r"(%(?P<name>\(.*?\))?(?P<type>[ifs]{1,3}))|\|"
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1262 i = 0
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1263 self.optional = -1
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1264 named = False
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1265 self.param_list = []
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1266 self.param_dict = {}
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1267 for match in re.finditer(param_re, pattern):
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1268 if match.group() == "|":
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1269 self.optional = i
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1270 continue
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1271 self.param_list.append(match.group('type'))
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1272 if match.group('name'):
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1273 named = True
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1274 self.param_dict[match.group('name')[1:-1]] = i
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1275 elif named:
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1276 raise ValueError, "Named parameter expected"
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1277 i += 1
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1278
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1279 def __str__(self):
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1280 return "%s, %s, optional:%s" % (self.param_list, self.param_dict,
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1281 self.optional)
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1282
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1283 def parse_parameters(self, input):
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1284 """
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1285 (4, 2)
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1286 """
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1287
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1288 parameter_list = [None] * len(self.param_list)
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1289 parameter_dict = {}
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1290 check_list = [0] * len(self.param_list)
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 930
diff changeset
1291
672
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1292 i = 0
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1293 start = 0
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1294 named = False
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 930
diff changeset
1295 while start < len(input):
672
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1296 match = re.match(self.param_re, input[start:])
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1297 if not match: raise ValueError, "Misformatted value"
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1298 start += match.end()
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1299 value = None
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1300 if match.group("int"):
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1301 value = int(match.group("int"))
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1302 type = 'i'
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1303 elif match.group("float"):
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1304 value = float(match.group("float"))
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1305 type = 'f'
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1306 elif match.group("string"):
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1307 value = match.group("string")[1:-1]
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1308 type = 's'
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1309 elif match.group("name_param"):
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1310 value = match.group("name_param")
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1311 type = 'n'
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1312 else:
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1313 value = None
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1314
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1315 parameter_list.append(value)
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1316 if match.group("name"):
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 930
diff changeset
1317 if not self.param_dict.has_key(match.group("name")):
672
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1318 raise ValueError, "Unknown parameter name '%s'" % match.group("name")
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1319 nr = self.param_dict[match.group("name")]
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1320 if check_list[nr]:
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1321 raise ValueError, "Parameter specified twice"
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1322 else:
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1323 check_list[nr] = 1
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1324 parameter_dict[match.group("name")] = value
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1325 parameter_list[nr] = value
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1326 named = True
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1327 elif named:
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1328 raise ValueError, "Only named parameters allowed"
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1329 else:
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1330 nr = i
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1331 parameter_list[nr] = value
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1332 # check type
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1333 #if not type in self.param_list[nr]:
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1334
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1335 i += 1
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1336 return parameter_list, parameter_dict
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1337
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1338
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1339 def _check_type(value, type, format):
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1340 if type == 'n' and 's' in format: # n as s
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1341 return value
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 930
diff changeset
1342
672
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1343 if type in format: return value # x -> x
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 930
diff changeset
1344
672
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1345 if type == 'i':
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1346 if 'f' in format: return float(value) # i -> f
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1347 elif 'b' in format: return value # i -> b
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1348 elif type == 'f':
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1349 if 'b' in format: return value # f -> b
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1350 elif type == 's':
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1351 if 'b' in format:
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1352 return value.lower() != 'false' # s-> b
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1353
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1354
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff changeset
1355 if 's' in format: # * -> s
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 930
diff changeset
1356 return str(value)
672
b17cce67bcad move parameterparser to wikiutil
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 671
diff cha