Mercurial > moin > 1.9
annotate MoinMoin/wikiutil.py @ 3812:30ed528054ed
fix some pep8 failures
author | Johannes Berg <johannes AT sipsolutions DOT net> |
---|---|
date | Wed, 02 Jul 2008 01:05:09 +0200 |
parents | 88b2eecd1fed |
children | 6e7ab559c67d |
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 |
1918
bb2e053067fb
fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1908
diff
changeset
|
5 @copyright: 2000-2004 Juergen Hermann <jh@web.de>, |
2453
adf5ec4874ed
fix ParameterParser, rewrite ParameterParser tests for py.test (and add more tests), refactor Hits macro
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2447
diff
changeset
|
6 2004 by Florian Festi, |
adf5ec4874ed
fix ParameterParser, rewrite ParameterParser tests for py.test (and add more tests), refactor Hits macro
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2447
diff
changeset
|
7 2006 by Mikko Virkkil, |
3127
ea5383222f2f
refactored misc. modules to use own logger instead of request.log
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3110
diff
changeset
|
8 2005-2008 MoinMoin:ThomasWaldmann, |
1993
93877b7d87b9
fixing copyright headers:unified my name
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
1922
diff
changeset
|
9 2007 MoinMoin:ReimarBauer |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
10 @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
|
11 """ |
931
141083b64fb1
whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
930
diff
changeset
|
12 |
1085
2bcb7bdf94a2
Implemented an editable InterWikiMap, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1082
diff
changeset
|
13 import cgi |
2bcb7bdf94a2
Implemented an editable InterWikiMap, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1082
diff
changeset
|
14 import codecs |
2bcb7bdf94a2
Implemented an editable InterWikiMap, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1082
diff
changeset
|
15 import os |
2bcb7bdf94a2
Implemented an editable InterWikiMap, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1082
diff
changeset
|
16 import re |
2bcb7bdf94a2
Implemented an editable InterWikiMap, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1082
diff
changeset
|
17 import time |
2bcb7bdf94a2
Implemented an editable InterWikiMap, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1082
diff
changeset
|
18 import urllib |
3107
c6e39279f83b
refactor logging usage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3093
diff
changeset
|
19 |
3110
a48929a5036c
logging: make it work correctly by doing logging configuration very early
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3107
diff
changeset
|
20 from MoinMoin import log |
a48929a5036c
logging: make it work correctly by doing logging configuration very early
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3107
diff
changeset
|
21 logging = log.getLogger(__name__) |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
22 |
1791
6dd2e29acffe
Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1784
diff
changeset
|
23 from MoinMoin import config |
6dd2e29acffe
Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1784
diff
changeset
|
24 from MoinMoin.util import pysupport, lock |
2557
cc5a81bda460
allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2550
diff
changeset
|
25 from inspect import getargspec, isfunction, isclass, ismethod |
2540
fa4252cb4077
move macro invoker to wikiutil
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2538
diff
changeset
|
26 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
27 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
28 # Exceptions |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
29 class InvalidFileNameError(Exception): |
931
141083b64fb1
whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
930
diff
changeset
|
30 """ 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
|
31 pass |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
32 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
33 # 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
|
34 PARENT_PREFIX = "../" |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
35 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
|
36 CHILD_PREFIX = "/" |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
37 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
|
38 |
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 ### 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
|
41 ############################################################################# |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
42 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
43 def decodeWindowsPath(text): |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
44 """ 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
|
45 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
|
46 according to the file system semantics. |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
47 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
48 @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
|
49 @rtype: unicode |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
50 @return: decoded text |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
51 """ |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
52 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
53 import locale |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
54 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
|
55 try: |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
56 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
|
57 except UnicodeError: |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
58 try: |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
59 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
|
60 except LookupError: |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
61 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
|
62 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
63 def decodeUnknownInput(text): |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
64 """ 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
|
65 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
66 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
|
67 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
|
68 '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
|
69 data. |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
70 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
71 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
|
72 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
|
73 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
74 @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
|
75 @rtype: unicode |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
76 @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
|
77 """ |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
78 # 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
|
79 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
|
80 return text |
931
141083b64fb1
whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
930
diff
changeset
|
81 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
82 try: |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
83 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
|
84 except UnicodeError: |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
85 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
|
86 try: |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
87 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
|
88 except UnicodeError: |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
89 pass |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
90 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
|
91 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
92 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
93 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
|
94 """ |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
95 Decodes input from the user. |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
96 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
97 @param s: the string to unquote |
490
ca35d9e6d63e
eypdoc comments: fixed some warnings/errors
Thomas Waldmann <tw@waldmann-edv.de>
parents:
471
diff
changeset
|
98 @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
|
99 @rtype: unicode |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
100 @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
|
101 """ |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
102 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
|
103 try: |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
104 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
|
105 except UnicodeError: |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
106 pass |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
107 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
|
108 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
109 |
101
2202f548cbb0
use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents:
53
diff
changeset
|
110 # 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
|
111 # 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
|
112 # 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
|
113 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
|
114 """ |
2202f548cbb0
use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents:
53
diff
changeset
|
115 Wrapper around urllib.quote doing the encoding/decoding as usually wanted: |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
116 |
101
2202f548cbb0
use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents:
53
diff
changeset
|
117 @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
|
118 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
|
119 @param safe: just passed through to urllib |
2202f548cbb0
use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents:
53
diff
changeset
|
120 @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
|
121 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
|
122 Default is False. |
2202f548cbb0
use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents:
53
diff
changeset
|
123 """ |
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
|
124 if isinstance(s, unicode): |
101
2202f548cbb0
use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents:
53
diff
changeset
|
125 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
|
126 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
|
127 s = str(s) |
101
2202f548cbb0
use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents:
53
diff
changeset
|
128 s = urllib.quote(s, safe) |
2202f548cbb0
use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents:
53
diff
changeset
|
129 if want_unicode: |
2202f548cbb0
use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents:
53
diff
changeset
|
130 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
|
131 return s |
2202f548cbb0
use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents:
53
diff
changeset
|
132 |
2202f548cbb0
use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents:
53
diff
changeset
|
133 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
|
134 """ |
2202f548cbb0
use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents:
53
diff
changeset
|
135 Wrapper around urllib.quote_plus doing the encoding/decoding as usually wanted: |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
136 |
101
2202f548cbb0
use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents:
53
diff
changeset
|
137 @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
|
138 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
|
139 @param safe: just passed through to urllib |
2202f548cbb0
use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents:
53
diff
changeset
|
140 @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
|
141 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
|
142 Default is False. |
2202f548cbb0
use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents:
53
diff
changeset
|
143 """ |
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
|
144 if isinstance(s, unicode): |
101
2202f548cbb0
use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents:
53
diff
changeset
|
145 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
|
146 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
|
147 s = str(s) |
101
2202f548cbb0
use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents:
53
diff
changeset
|
148 s = urllib.quote_plus(s, safe) |
2202f548cbb0
use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents:
53
diff
changeset
|
149 if want_unicode: |
2202f548cbb0
use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents:
53
diff
changeset
|
150 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
|
151 return s |
2202f548cbb0
use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents:
53
diff
changeset
|
152 |
2202f548cbb0
use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents:
53
diff
changeset
|
153 def url_unquote(s, want_unicode=True): |
2202f548cbb0
use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents:
53
diff
changeset
|
154 """ |
2202f548cbb0
use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents:
53
diff
changeset
|
155 Wrapper around urllib.unquote doing the encoding/decoding as usually wanted: |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
156 |
101
2202f548cbb0
use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents:
53
diff
changeset
|
157 @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
|
158 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
|
159 @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
|
160 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
|
161 Default is True. |
2202f548cbb0
use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents:
53
diff
changeset
|
162 """ |
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
|
163 if isinstance(s, unicode): |
101
2202f548cbb0
use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents:
53
diff
changeset
|
164 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
|
165 s = urllib.unquote(s) |
2202f548cbb0
use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents:
53
diff
changeset
|
166 if want_unicode: |
3017
2fb7b7a26690
wikiutil.url_unquote: try harder when decoding to unicode, avoid crashing (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2773
diff
changeset
|
167 try: |
2fb7b7a26690
wikiutil.url_unquote: try harder when decoding to unicode, avoid crashing (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2773
diff
changeset
|
168 s = decodeUserInput(s, [config.charset, 'iso-8859-1', ]) # try hard |
2fb7b7a26690
wikiutil.url_unquote: try harder when decoding to unicode, avoid crashing (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2773
diff
changeset
|
169 except UnicodeError: |
2fb7b7a26690
wikiutil.url_unquote: try harder when decoding to unicode, avoid crashing (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2773
diff
changeset
|
170 s = s.decode('ascii', 'replace') # better than crashing |
101
2202f548cbb0
use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents:
53
diff
changeset
|
171 return s |
2202f548cbb0
use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents:
53
diff
changeset
|
172 |
175
df4fe62dc160
fixing eventlog UnicodeDecodeError, try2
Thomas Waldmann <tw@waldmann-edv.de>
parents:
171
diff
changeset
|
173 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
|
174 """ 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
|
175 """ |
a54cebaab73e
move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents:
101
diff
changeset
|
176 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
|
177 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
|
178 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
|
179 values = {} |
a54cebaab73e
move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents:
101
diff
changeset
|
180 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
|
181 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
|
182 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
|
183 if want_unicode: |
175
df4fe62dc160
fixing eventlog UnicodeDecodeError, try2
Thomas Waldmann <tw@waldmann-edv.de>
parents:
171
diff
changeset
|
184 try: |
df4fe62dc160
fixing eventlog UnicodeDecodeError, try2
Thomas Waldmann <tw@waldmann-edv.de>
parents:
171
diff
changeset
|
185 v = unicode(v, config.charset) |
df4fe62dc160
fixing eventlog UnicodeDecodeError, try2
Thomas Waldmann <tw@waldmann-edv.de>
parents:
171
diff
changeset
|
186 except UnicodeDecodeError: |
df4fe62dc160
fixing eventlog UnicodeDecodeError, try2
Thomas Waldmann <tw@waldmann-edv.de>
parents:
171
diff
changeset
|
187 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
|
188 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
|
189 return values |
a54cebaab73e
move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents:
101
diff
changeset
|
190 |
a54cebaab73e
move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents:
101
diff
changeset
|
191 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
|
192 """ Make a querystring from arguments. |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
193 |
102
a54cebaab73e
move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents:
101
diff
changeset
|
194 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
|
195 |
a54cebaab73e
move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents:
101
diff
changeset
|
196 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
|
197 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
|
198 |
a54cebaab73e
move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents:
101
diff
changeset
|
199 @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
|
200 @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
|
201 @rtype: string |
a54cebaab73e
move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents:
101
diff
changeset
|
202 @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
|
203 """ |
a54cebaab73e
move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents:
101
diff
changeset
|
204 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
|
205 qstr = {} |
1339
544b931cd965
new setting url_prefix_action, cleanup page.url/link_to, wikiutil.link_tag
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1317
diff
changeset
|
206 if isinstance(qstr, dict): |
102
a54cebaab73e
move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents:
101
diff
changeset
|
207 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
|
208 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
|
209 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
|
210 return qstr |
a54cebaab73e
move make / parse query string functions to wikiutil, make unicode-safe
Thomas Waldmann <tw@waldmann-edv.de>
parents:
101
diff
changeset
|
211 |
101
2202f548cbb0
use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents:
53
diff
changeset
|
212 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
213 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
|
214 """ 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
|
215 |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
216 Use urllib.quote to quote any character that is not always safe. |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
217 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
218 @param pagename: the original pagename (unicode) |
1775
ec3625137c0d
wikiutil: remove some superfluous FIXMEs, clarify another, fix typo
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1770
diff
changeset
|
219 @param charset: url text encoding, 'utf-8' recommended. Other charset |
490
ca35d9e6d63e
eypdoc comments: fixed some warnings/errors
Thomas Waldmann <tw@waldmann-edv.de>
parents:
471
diff
changeset
|
220 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
|
221 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
|
222 @rtype: string |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
223 @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
|
224 """ |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
225 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
|
226 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
|
227 |
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 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
|
230 """ Escape possible html tags |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
231 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
232 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
|
233 (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
|
234 don't use cgi at all) |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
235 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
236 @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
|
237 @param quote: bool, should transform '\"' to '"' |
1775
ec3625137c0d
wikiutil: remove some superfluous FIXMEs, clarify another, fix typo
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1770
diff
changeset
|
238 @rtype: when called with a unicode object, return unicode object - otherwise return string object |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
239 @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
|
240 """ |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
241 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
|
242 s = str(s) |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
243 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
244 # Must first replace & |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
245 s = s.replace("&", "&") |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
246 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
247 # Then other... |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
248 s = s.replace("<", "<") |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
249 s = s.replace(">", ">") |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
250 if quote: |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
251 s = s.replace('"', """) |
3207
309f5570ba2b
wikiutil.escape: escapes ' too
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
3143
diff
changeset
|
252 s = s.replace("'", "'") |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
253 return s |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
254 |
1922
f486526720c5
renamed wikiutil.clean_comment > clean_input, moved translation map to config
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1921
diff
changeset
|
255 def clean_input(text, max_len=201): |
f486526720c5
renamed wikiutil.clean_comment > clean_input, moved translation map to config
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1921
diff
changeset
|
256 """ Clean input: |
f486526720c5
renamed wikiutil.clean_comment > clean_input, moved translation map to config
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1921
diff
changeset
|
257 replace CR, LF, TAB by whitespace |
f486526720c5
renamed wikiutil.clean_comment > clean_input, moved translation map to config
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1921
diff
changeset
|
258 delete control chars |
f486526720c5
renamed wikiutil.clean_comment > clean_input, moved translation map to config
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1921
diff
changeset
|
259 |
f486526720c5
renamed wikiutil.clean_comment > clean_input, moved translation map to config
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1921
diff
changeset
|
260 @param text: unicode text to clean |
1921
4122148ceadb
clean_comment bugfix for wrong handling of most control chars, better docstring (refactoring follows)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1920
diff
changeset
|
261 @rtype: unicode |
4122148ceadb
clean_comment bugfix for wrong handling of most control chars, better docstring (refactoring follows)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1920
diff
changeset
|
262 @return: cleaned text |
332
0a40d8a4057e
fixed logfile breaking when DeletePage/RenamePage comment contains CRLF chars
Thomas Waldmann <tw@waldmann-edv.de>
parents:
198
diff
changeset
|
263 """ |
1921
4122148ceadb
clean_comment bugfix for wrong handling of most control chars, better docstring (refactoring follows)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1920
diff
changeset
|
264 # we only have input fields with max 200 chars, but spammers send us more |
2716
03e4091531be
wikiutil: some PEP8 fixes
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
2706
diff
changeset
|
265 length = len(text) |
03e4091531be
wikiutil: some PEP8 fixes
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
2706
diff
changeset
|
266 if length == 0 or length > max_len: |
1921
4122148ceadb
clean_comment bugfix for wrong handling of most control chars, better docstring (refactoring follows)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1920
diff
changeset
|
267 return u'' |
1922
f486526720c5
renamed wikiutil.clean_comment > clean_input, moved translation map to config
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1921
diff
changeset
|
268 else: |
f486526720c5
renamed wikiutil.clean_comment > clean_input, moved translation map to config
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1921
diff
changeset
|
269 return text.translate(config.clean_input_translation_map) |
f486526720c5
renamed wikiutil.clean_comment > clean_input, moved translation map to config
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1921
diff
changeset
|
270 |
332
0a40d8a4057e
fixed logfile breaking when DeletePage/RenamePage comment contains CRLF chars
Thomas Waldmann <tw@waldmann-edv.de>
parents:
198
diff
changeset
|
271 |
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
|
272 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
|
273 """ 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
|
274 """ |
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 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
|
276 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
|
277 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
|
278 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
|
279 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
|
280 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
|
281 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
|
282 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
|
283 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
|
284 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
|
285 |
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 ### Storage |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
288 ######################################################################## |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
289 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
290 # 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
|
291 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
|
292 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
|
293 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
294 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
295 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
|
296 """ Return file system representation of a Unicode WikiName. |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
297 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
298 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
|
299 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
|
300 character. |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
301 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
302 @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
|
303 @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
|
304 @rtype: string |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
305 @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
|
306 """ |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
307 filename = wikiname.encode(charset) |
931
141083b64fb1
whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
930
diff
changeset
|
308 |
141083b64fb1
whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
930
diff
changeset
|
309 quoted = [] |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
310 location = 0 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
311 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
|
312 # 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
|
313 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
|
314 location = needle.end() |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
315 # Quote and append unsafe stuff |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
316 quoted.append('(') |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
317 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
|
318 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
|
319 quoted.append(')') |
931
141083b64fb1
whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
930
diff
changeset
|
320 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
321 # append rest of string |
931
141083b64fb1
whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
930
diff
changeset
|
322 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
|
323 return ''.join(quoted) |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
324 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
325 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
326 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
|
327 """ Return Unicode WikiName from quoted file name. |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
328 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
329 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
|
330 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
|
331 Invalid file names should never happen in normal use, but are rather |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
332 cheap to find. |
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
333 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
334 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
|
335 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
|
336 urllib.unquote, decodePagename and normalizePagename. |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
337 |
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
338 Todo: search clients of unquoteWikiname and check for exceptions. |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
339 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
340 @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
|
341 @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
|
342 @rtype: Unicode String |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
343 @return: WikiName |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
344 """ |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
345 ### Temporary fix start ### |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
346 # 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
|
347 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
|
348 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
|
349 ### Temporary fix end ### |
931
141083b64fb1
whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
930
diff
changeset
|
350 |
141083b64fb1
whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
930
diff
changeset
|
351 parts = [] |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
352 start = 0 |
931
141083b64fb1
whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
930
diff
changeset
|
353 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
|
354 # 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
|
355 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
|
356 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
|
357 # Append quoted stuff |
931
141083b64fb1
whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
930
diff
changeset
|
358 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
|
359 # Filter invalid filenames |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
360 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
|
361 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
|
362 try: |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
363 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
|
364 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
|
365 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
|
366 parts.append(character) |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
367 except ValueError: |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
368 # 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
|
369 raise InvalidFileNameError(filename) |
931
141083b64fb1
whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
930
diff
changeset
|
370 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
371 # 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
|
372 if start == 0: |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
373 wikiname = filename |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
374 else: |
931
141083b64fb1
whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
930
diff
changeset
|
375 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
|
376 wikiname = ''.join(parts) |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
377 |
1796
57f12932915f
cleaning up comments, minor refactorings in heading formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1791
diff
changeset
|
378 # FIXME: This looks wrong, because at this stage "()" can be both errors |
57f12932915f
cleaning up comments, minor refactorings in heading formatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1791
diff
changeset
|
379 # like open "(" without close ")", or unquoted valid characters in the file name. |
0
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 |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
392 an integer in usecs. |
0
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 """ |
2447
45641cbe7729
enable new PEP8 test, fixes where it failed
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2381
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 """ |
1111
2aa53ed0afa0
Fix the unrespected cache_dir problem.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1090
diff
changeset
|
413 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
|
414 """ 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
|
415 dict.__init__(self) |
ef41e35985dc
new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents:
490
diff
changeset
|
416 self.metafilename = metafilename |
ef41e35985dc
new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents:
490
diff
changeset
|
417 self.dirty = False |
1111
2aa53ed0afa0
Fix the unrespected cache_dir problem.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1090
diff
changeset
|
418 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
|
419 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
|
420 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
|
421 |
1295
9608758dca9a
Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1181
diff
changeset
|
422 if not self.rlock.acquire(3.0): |
9608758dca9a
Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1181
diff
changeset
|
423 raise EnvironmentError("Could not lock in MetaDict") |
9608758dca9a
Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1181
diff
changeset
|
424 try: |
9608758dca9a
Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1181
diff
changeset
|
425 self._get_meta() |
9608758dca9a
Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1181
diff
changeset
|
426 finally: |
9608758dca9a
Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1181
diff
changeset
|
427 self.rlock.release() |
9608758dca9a
Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1181
diff
changeset
|
428 |
497
ef41e35985dc
new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents:
490
diff
changeset
|
429 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
|
430 """ 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
|
431 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
|
432 @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
|
433 @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
|
434 """ |
1082
ba25ee4ea61d
Added locking to the MetaDict code.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1079
diff
changeset
|
435 |
497
ef41e35985dc
new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents:
490
diff
changeset
|
436 try: |
1295
9608758dca9a
Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1181
diff
changeset
|
437 metafile = codecs.open(self.metafilename, "r", "utf-8") |
9608758dca9a
Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1181
diff
changeset
|
438 meta = metafile.read() # this is much faster than the file's line-by-line iterator |
9608758dca9a
Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1181
diff
changeset
|
439 metafile.close() |
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) |
931
141083b64fb1
whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
930
diff
changeset
|
448 |
497
ef41e35985dc
new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents:
490
diff
changeset
|
449 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
|
450 """ 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
|
451 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
|
452 @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
|
453 @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
|
454 """ |
ef41e35985dc
new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents:
490
diff
changeset
|
455 meta = [] |
ef41e35985dc
new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents:
490
diff
changeset
|
456 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
|
457 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
|
458 value = str(value) |
ef41e35985dc
new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents:
490
diff
changeset
|
459 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
|
460 meta = '\r\n'.join(meta) |
1088
55ebe3c0867c
Fixed bugs, raise exceptions on locking.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1085
diff
changeset
|
461 |
1295
9608758dca9a
Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1181
diff
changeset
|
462 metafile = codecs.open(self.metafilename, "w", "utf-8") |
9608758dca9a
Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1181
diff
changeset
|
463 metafile.write(meta) |
9608758dca9a
Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1181
diff
changeset
|
464 metafile.close() |
497
ef41e35985dc
new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents:
490
diff
changeset
|
465 self.dirty = False |
ef41e35985dc
new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents:
490
diff
changeset
|
466 |
ef41e35985dc
new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents:
490
diff
changeset
|
467 def sync(self, mtime_usecs=None): |
1295
9608758dca9a
Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1181
diff
changeset
|
468 """ No-Op except for that parameter """ |
9608758dca9a
Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1181
diff
changeset
|
469 if not mtime_usecs is None: |
9608758dca9a
Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1181
diff
changeset
|
470 self.__setitem__('mtime', str(mtime_usecs)) |
9608758dca9a
Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1181
diff
changeset
|
471 # otherwise no-op |
497
ef41e35985dc
new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents:
490
diff
changeset
|
472 |
ef41e35985dc
new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents:
490
diff
changeset
|
473 def __getitem__(self, key): |
1295
9608758dca9a
Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1181
diff
changeset
|
474 """ We don't care for cache coherency here. """ |
9608758dca9a
Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1181
diff
changeset
|
475 return dict.__getitem__(self, key) |
497
ef41e35985dc
new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents:
490
diff
changeset
|
476 |
ef41e35985dc
new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents:
490
diff
changeset
|
477 def __setitem__(self, key, value): |
1295
9608758dca9a
Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1181
diff
changeset
|
478 """ Sets a dictionary entry. """ |
9608758dca9a
Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1181
diff
changeset
|
479 if not self.wlock.acquire(5.0): |
9608758dca9a
Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1181
diff
changeset
|
480 raise EnvironmentError("Could not lock in MetaDict") |
497
ef41e35985dc
new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents:
490
diff
changeset
|
481 try: |
1295
9608758dca9a
Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1181
diff
changeset
|
482 self._get_meta() # refresh cache |
9608758dca9a
Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1181
diff
changeset
|
483 try: |
9608758dca9a
Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1181
diff
changeset
|
484 oldvalue = dict.__getitem__(self, key) |
9608758dca9a
Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1181
diff
changeset
|
485 except KeyError: |
9608758dca9a
Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1181
diff
changeset
|
486 oldvalue = None |
9608758dca9a
Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1181
diff
changeset
|
487 if value != oldvalue: |
9608758dca9a
Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1181
diff
changeset
|
488 dict.__setitem__(self, key, value) |
9608758dca9a
Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1181
diff
changeset
|
489 self._put_meta() # sync cache |
9608758dca9a
Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1181
diff
changeset
|
490 finally: |
9608758dca9a
Fixed severe race conditions in the sync tags and the meta dict code. Before, multiple processes could destroy each other data by keeping two meta dicts instantiated and writing to them.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1181
diff
changeset
|
491 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
|
492 |
ef41e35985dc
new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents:
490
diff
changeset
|
493 |
1355
a796d366f176
wikiutil.(un)quoteName for (un)quoting names in wiki markup, fix quoting bug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1339
diff
changeset
|
494 # Quoting of wiki names, file names, etc. (in the wiki markup) ----------------------------------- |
a796d366f176
wikiutil.(un)quoteName for (un)quoting names in wiki markup, fix quoting bug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1339
diff
changeset
|
495 |
2728
59b3d8b8971f
remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2726
diff
changeset
|
496 # don't ever change this - DEPRECATED, only needed for 1.5 > 1.6 migration conversion |
2374
629dea07759f
do not parse single-quoted page names as quoted
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2286
diff
changeset
|
497 QUOTE_CHARS = u'"' |
1355
a796d366f176
wikiutil.(un)quoteName for (un)quoting names in wiki markup, fix quoting bug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1339
diff
changeset
|
498 |
a796d366f176
wikiutil.(un)quoteName for (un)quoting names in wiki markup, fix quoting bug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1339
diff
changeset
|
499 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
500 ############################################################################# |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
501 ### InterWiki |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
502 ############################################################################# |
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
|
503 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
|
504 |
2be8ec7ba817
Now the interwiki code caches the modification time of the interwiki files.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1111
diff
changeset
|
505 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
|
506 """ 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
|
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 # 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
|
509 # 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
|
510 # 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
|
511 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
|
512 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
|
513 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
|
514 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
|
515 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
|
516 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
|
517 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
|
518 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
|
519 |
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 |
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 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
|
522 """ 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
|
523 page page. """ |
1631
9f02d3c64f48
use ItemCache for page local edit-log, speedup InterWikiMap page handling if page does not exist
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1604
diff
changeset
|
524 timestamps = [os.stat(filename).st_mtime for filename in file_list] |
9f02d3c64f48
use ItemCache for page local edit-log, speedup InterWikiMap page handling if page does not exist
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1604
diff
changeset
|
525 if page.exists(): |
9f02d3c64f48
use ItemCache for page local edit-log, speedup InterWikiMap page handling if page does not exist
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1604
diff
changeset
|
526 # exists() is cached and thus cheaper than mtime_usecs() |
9f02d3c64f48
use ItemCache for page local edit-log, speedup InterWikiMap page handling if page does not exist
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1604
diff
changeset
|
527 timestamps.append(version2timestamp(page.mtime_usecs())) |
2607
2e6227a50d27
fix exception when there are no interwiki map files or page
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2576
diff
changeset
|
528 if timestamps: |
2e6227a50d27
fix exception when there are no interwiki map files or page
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2576
diff
changeset
|
529 return max(timestamps) |
2e6227a50d27
fix exception when there are no interwiki map files or page
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2576
diff
changeset
|
530 else: |
2e6227a50d27
fix exception when there are no interwiki map files or page
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2576
diff
changeset
|
531 return 0 # no files / pages there |
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
|
532 |
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
|
533 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
|
534 """ 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
|
535 from MoinMoin.Page import Page |
1088
55ebe3c0867c
Fixed bugs, raise exceptions on locking.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1085
diff
changeset
|
536 |
55ebe3c0867c
Fixed bugs, raise exceptions on locking.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1085
diff
changeset
|
537 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
|
538 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
|
539 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
|
540 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
541 try: |
1551
0d2f2d531e81
using request.cfg.cache more
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1550
diff
changeset
|
542 _interwiki_list = request.cfg.cache.interwiki_list |
0d2f2d531e81
using request.cfg.cache more
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1550
diff
changeset
|
543 old_mtime = request.cfg.cache.interwiki_mtime |
0d2f2d531e81
using request.cfg.cache more
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1550
diff
changeset
|
544 if request.cfg.cache.interwiki_ts + (1*60) < now: # 1 minutes caching 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
|
545 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
|
546 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
|
547 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
|
548 else: |
1551
0d2f2d531e81
using request.cfg.cache more
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1550
diff
changeset
|
549 request.cfg.cache.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
|
550 except AttributeError: |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
551 _interwiki_list = {} |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
552 lines = [] |
931
141083b64fb1
whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
930
diff
changeset
|
553 |
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
|
554 for filename in request.cfg.shared_intermap_files: |
3301
885b7ada47b9
read interwiki files with the right codec (utf-8)
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3263
diff
changeset
|
555 f = codecs.open(filename, "r", config.charset) |
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
|
556 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
|
557 f.close() |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
558 |
1085
2bcb7bdf94a2
Implemented an editable InterWikiMap, updated my CHANGES file.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1082
diff
changeset
|
559 # 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
|
560 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
|
561 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
562 for line in lines: |
1920
b06ef2a53efa
'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1919
diff
changeset
|
563 if not line or line[0] == '#': |
b06ef2a53efa
'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1919
diff
changeset
|
564 continue |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
565 try: |
931
141083b64fb1
whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
930
diff
changeset
|
566 line = "%s %s/InterWiki" % (line, request.getScriptname()) |
1805
ebcebba1afb3
removed some unused attributes, used 'dummy' for dummies
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1796
diff
changeset
|
567 wikitag, urlprefix, dummy = line.split(None, 2) |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
568 except ValueError: |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
569 pass |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
570 else: |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
571 _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
|
572 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
573 del lines |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
574 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
575 # 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
|
576 _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
|
577 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
|
578 _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
|
579 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
580 # save for later |
1551
0d2f2d531e81
using request.cfg.cache more
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1550
diff
changeset
|
581 request.cfg.cache.interwiki_list = _interwiki_list |
0d2f2d531e81
using request.cfg.cache more
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1550
diff
changeset
|
582 request.cfg.cache.interwiki_ts = now |
0d2f2d531e81
using request.cfg.cache more
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1550
diff
changeset
|
583 request.cfg.cache.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
|
584 |
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
|
585 return _interwiki_list |
931
141083b64fb1
whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
930
diff
changeset
|
586 |
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
|
587 def split_wiki(wikiurl): |
2730
a907a61c33b3
* The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2728
diff
changeset
|
588 """ |
a907a61c33b3
* The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2728
diff
changeset
|
589 Split a wiki url. |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
590 |
2728
59b3d8b8971f
remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2726
diff
changeset
|
591 *** DEPRECATED FUNCTION FOR OLD 1.5 SYNTAX - ONLY STILL HERE FOR THE 1.5 -> 1.6 MIGRATION *** |
59b3d8b8971f
remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2726
diff
changeset
|
592 Use split_interwiki(), see below. |
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
|
593 |
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 @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
|
595 @rtype: tuple |
2730
a907a61c33b3
* The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2728
diff
changeset
|
596 @return: (tag, tail) |
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
|
597 """ |
2730
a907a61c33b3
* The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2728
diff
changeset
|
598 # !!! use a regex here! |
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
|
599 try: |
2730
a907a61c33b3
* The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2728
diff
changeset
|
600 wikitag, tail = wikiurl.split(":", 1) |
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
|
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: |
2730
a907a61c33b3
* The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2728
diff
changeset
|
603 wikitag, tail = wikiurl.split("/", 1) |
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
|
604 except ValueError: |
2730
a907a61c33b3
* The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2728
diff
changeset
|
605 wikitag, tail = 'Self', wikiurl |
a907a61c33b3
* The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2728
diff
changeset
|
606 return wikitag, tail |
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
|
607 |
2728
59b3d8b8971f
remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2726
diff
changeset
|
608 def split_interwiki(wikiurl): |
59b3d8b8971f
remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2726
diff
changeset
|
609 """ Split a interwiki name, into wikiname and pagename, e.g: |
59b3d8b8971f
remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2726
diff
changeset
|
610 |
59b3d8b8971f
remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2726
diff
changeset
|
611 'MoinMoin:FrontPage' -> "MoinMoin", "FrontPage" |
59b3d8b8971f
remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2726
diff
changeset
|
612 'FrontPage' -> "Self", "FrontPage" |
59b3d8b8971f
remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2726
diff
changeset
|
613 'MoinMoin:Page with blanks' -> "MoinMoin", "Page with blanks" |
59b3d8b8971f
remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2726
diff
changeset
|
614 'MoinMoin:' -> "MoinMoin", "" |
59b3d8b8971f
remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2726
diff
changeset
|
615 |
59b3d8b8971f
remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2726
diff
changeset
|
616 can also be used for: |
59b3d8b8971f
remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2726
diff
changeset
|
617 |
59b3d8b8971f
remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2726
diff
changeset
|
618 'attachment:filename with blanks.txt' -> "attachment", "filename with blanks.txt" |
59b3d8b8971f
remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2726
diff
changeset
|
619 |
59b3d8b8971f
remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2726
diff
changeset
|
620 @param wikiurl: the url to split |
59b3d8b8971f
remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2726
diff
changeset
|
621 @rtype: tuple |
59b3d8b8971f
remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2726
diff
changeset
|
622 @return: (wikiname, pagename) |
59b3d8b8971f
remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2726
diff
changeset
|
623 """ |
59b3d8b8971f
remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2726
diff
changeset
|
624 try: |
59b3d8b8971f
remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2726
diff
changeset
|
625 wikiname, pagename = wikiurl.split(":", 1) |
59b3d8b8971f
remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2726
diff
changeset
|
626 except ValueError: |
59b3d8b8971f
remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2726
diff
changeset
|
627 wikiname, pagename = 'Self', wikiurl |
59b3d8b8971f
remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2726
diff
changeset
|
628 return wikiname, pagename |
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
|
629 |
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 def resolve_wiki(request, wikiurl): |
2730
a907a61c33b3
* The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2728
diff
changeset
|
631 """ |
a907a61c33b3
* The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2728
diff
changeset
|
632 Resolve an interwiki link. |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
633 |
2728
59b3d8b8971f
remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2726
diff
changeset
|
634 *** DEPRECATED FUNCTION FOR OLD 1.5 SYNTAX - ONLY STILL HERE FOR THE 1.5 -> 1.6 MIGRATION *** |
59b3d8b8971f
remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2726
diff
changeset
|
635 Use resolve_interwiki(), see below. |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
636 |
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
|
637 @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
|
638 @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
|
639 @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
|
640 @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
|
641 """ |
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 _interwiki_list = load_wikimap(request) |
2730
a907a61c33b3
* The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2728
diff
changeset
|
643 # split wiki url |
a907a61c33b3
* The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2728
diff
changeset
|
644 wikiname, pagename = split_wiki(wikiurl) |
a907a61c33b3
* The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2728
diff
changeset
|
645 |
a907a61c33b3
* The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2728
diff
changeset
|
646 # return resolved url |
1868
64507f46beb2
reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1866
diff
changeset
|
647 if wikiname in _interwiki_list: |
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
|
648 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
|
649 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
|
650 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
|
651 |
2728
59b3d8b8971f
remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2726
diff
changeset
|
652 def resolve_interwiki(request, wikiname, pagename): |
59b3d8b8971f
remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2726
diff
changeset
|
653 """ Resolve an interwiki reference (wikiname:pagename). |
59b3d8b8971f
remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2726
diff
changeset
|
654 |
59b3d8b8971f
remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2726
diff
changeset
|
655 @param request: the request object |
59b3d8b8971f
remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2726
diff
changeset
|
656 @param wikiname: interwiki wiki name |
59b3d8b8971f
remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2726
diff
changeset
|
657 @param pagename: interwiki page name |
59b3d8b8971f
remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2726
diff
changeset
|
658 @rtype: tuple |
59b3d8b8971f
remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2726
diff
changeset
|
659 @return: (wikitag, wikiurl, wikitail, err) |
59b3d8b8971f
remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2726
diff
changeset
|
660 """ |
59b3d8b8971f
remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2726
diff
changeset
|
661 _interwiki_list = load_wikimap(request) |
1868
64507f46beb2
reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1866
diff
changeset
|
662 if wikiname in _interwiki_list: |
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
|
663 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
|
664 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
|
665 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
|
666 |
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
|
667 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
|
668 """ |
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
|
669 Add a (url_quoted) page name to an interwiki url. |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
670 |
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
|
671 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
|
672 We just use a utf-8 encoded string with standard URL quoting. |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
673 |
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
|
674 @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
|
675 @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
|
676 @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
|
677 @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
|
678 """ |
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
|
679 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
|
680 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
|
681 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
|
682 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
|
683 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
|
684 |
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 ############################################################################# |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
687 ### 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
|
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 isSystemPage(request, pagename): |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
691 """ Is this a system page? Uses AllSystemPagesGroup internally. |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
692 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
693 @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
|
694 @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
|
695 @rtype: bool |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
696 @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
|
697 """ |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
698 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
|
699 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
|
700 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
701 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
702 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
|
703 """ Is this a template page? |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
704 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
705 @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
|
706 @rtype: bool |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
707 @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
|
708 """ |
3573
124d0ef138aa
change page_*_regex processing, see docs/CHANGES (fixes Xapian category search for non-english)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3516
diff
changeset
|
709 return request.cfg.cache.page_template_regexact.search(pagename) is not None |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
710 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
711 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
712 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
|
713 """ 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
|
714 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
715 @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
|
716 @rtype: bool |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
717 @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
|
718 """ |
3573
124d0ef138aa
change page_*_regex processing, see docs/CHANGES (fixes Xapian category search for non-english)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3516
diff
changeset
|
719 return request.cfg.cache.page_group_regexact.search(pagename) is not None |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
720 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
721 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
722 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
|
723 """ 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
|
724 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
725 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
|
726 getPageList with a filter function. |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
727 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
728 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
|
729 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
|
730 one. |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
731 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
732 @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
|
733 @rtype: list |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
734 @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
|
735 """ |
3573
124d0ef138aa
change page_*_regex processing, see docs/CHANGES (fixes Xapian category search for non-english)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3516
diff
changeset
|
736 func = request.cfg.cache.page_category_regexact.search |
1866
0194beaf511e
reduce reduce, filter and map usage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1832
diff
changeset
|
737 return [pn for pn in pagelist if func(pn)] |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
738 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
739 |
1784
2668d470091f
wikiutil.getSysPage renamed to getLocalizedPage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1775
diff
changeset
|
740 def getLocalizedPage(request, pagename): # was: getSysPage |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
741 """ Get a system page according to user settings and available translations. |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
742 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
743 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
|
744 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
|
745 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
|
746 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
|
747 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
748 @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
|
749 @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
|
750 @rtype: Page object |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
751 @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
|
752 if it exists |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
753 """ |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
754 from MoinMoin.Page import Page |
3143
16ae95df840a
i18n.getText: fixed some callers that had still 'formatted=' kw args
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3133
diff
changeset
|
755 i18n_name = request.getText(pagename) |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
756 pageobj = None |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
757 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
|
758 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
|
759 # 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
|
760 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
|
761 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
|
762 pageobj = i18n_page |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
763 else: |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
764 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
|
765 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
|
766 pageobj = i18n_page |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
767 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
768 # 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
|
769 # 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
|
770 if not pageobj: |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
771 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
|
772 # 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
|
773 pageobj = request.page |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
774 else: |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
775 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
|
776 return pageobj |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
777 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
778 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
779 def getFrontPage(request): |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
780 """ 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
|
781 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
782 @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
|
783 @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
|
784 @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
|
785 """ |
1784
2668d470091f
wikiutil.getSysPage renamed to getLocalizedPage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1775
diff
changeset
|
786 return getLocalizedPage(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
|
787 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
788 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
789 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
|
790 """ |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
791 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
|
792 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
|
793 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
794 DEPRECATED - try to use getInterwikiHomePage (see below) |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
795 |
0
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: Page |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
799 @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
|
800 """ |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
801 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
|
802 # 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
|
803 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
|
804 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
|
805 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
806 # known user? |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
807 if username: |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
808 # Return home page |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
809 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
|
810 if page.exists(): |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
811 return page |
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 return None |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
814 |
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 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
|
817 """ |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
818 Get a user's homepage. |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
819 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
820 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
|
821 '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
|
822 When set to our own interwikiname, it behaves like with 'Self'. |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
823 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
824 'SomeOtherWiki' means we store user homepages in another wiki. |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
825 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
826 @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
|
827 @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
|
828 @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
|
829 @return: (wikiname, pagename) |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
830 """ |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
831 # 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
|
832 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
|
833 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
|
834 if not username: |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
835 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
|
836 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
837 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
|
838 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
|
839 homewiki = 'Self' |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
840 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
841 return homewiki, username |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
842 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
843 |
2706
d2d4e74978bd
remove superfluous request parameter from AbsPageName/RelPageName
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2705
diff
changeset
|
844 def AbsPageName(context, pagename): |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
845 """ |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
846 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
|
847 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
848 @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
|
849 @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
|
850 @rtype: string |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
851 @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
|
852 """ |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
853 if pagename.startswith(PARENT_PREFIX): |
2704
c6b5c2d813b6
fix AbsPageName(), add tests for it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2607
diff
changeset
|
854 while context and pagename.startswith(PARENT_PREFIX): |
c6b5c2d813b6
fix AbsPageName(), add tests for it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2607
diff
changeset
|
855 context = '/'.join(context.split('/')[:-1]) |
c6b5c2d813b6
fix AbsPageName(), add tests for it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2607
diff
changeset
|
856 pagename = pagename[PARENT_PREFIX_LEN:] |
2716
03e4091531be
wikiutil: some PEP8 fixes
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
2706
diff
changeset
|
857 pagename = '/'.join(filter(None, [context, pagename, ])) |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
858 elif pagename.startswith(CHILD_PREFIX): |
2704
c6b5c2d813b6
fix AbsPageName(), add tests for it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2607
diff
changeset
|
859 if context: |
c6b5c2d813b6
fix AbsPageName(), add tests for it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2607
diff
changeset
|
860 pagename = context + '/' + pagename[CHILD_PREFIX_LEN:] |
c6b5c2d813b6
fix AbsPageName(), add tests for it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2607
diff
changeset
|
861 else: |
c6b5c2d813b6
fix AbsPageName(), add tests for it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2607
diff
changeset
|
862 pagename = pagename[CHILD_PREFIX_LEN:] |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
863 return pagename |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
864 |
2706
d2d4e74978bd
remove superfluous request parameter from AbsPageName/RelPageName
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2705
diff
changeset
|
865 def RelPageName(context, pagename): |
2705
4a4d84273ae1
new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2704
diff
changeset
|
866 """ |
4a4d84273ae1
new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2704
diff
changeset
|
867 Return the relative pagename for some context. |
4a4d84273ae1
new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2704
diff
changeset
|
868 |
4a4d84273ae1
new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2704
diff
changeset
|
869 @param context: name of the page where "pagename" appears on |
4a4d84273ae1
new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2704
diff
changeset
|
870 @param pagename: the absolute page name |
4a4d84273ae1
new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2704
diff
changeset
|
871 @rtype: string |
4a4d84273ae1
new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2704
diff
changeset
|
872 @return: the relative page name |
4a4d84273ae1
new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2704
diff
changeset
|
873 """ |
4a4d84273ae1
new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2704
diff
changeset
|
874 if context == '': |
4a4d84273ae1
new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2704
diff
changeset
|
875 # special case, context is some "virtual root" page with name == '' |
4a4d84273ae1
new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2704
diff
changeset
|
876 # every page is a subpage of this virtual root |
4a4d84273ae1
new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2704
diff
changeset
|
877 return CHILD_PREFIX + pagename |
4a4d84273ae1
new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2704
diff
changeset
|
878 elif pagename.startswith(context + CHILD_PREFIX): |
4a4d84273ae1
new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2704
diff
changeset
|
879 # simple child |
4a4d84273ae1
new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2704
diff
changeset
|
880 return pagename[len(context):] |
4a4d84273ae1
new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2704
diff
changeset
|
881 else: |
4a4d84273ae1
new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2704
diff
changeset
|
882 # some kind of sister/aunt |
4a4d84273ae1
new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2704
diff
changeset
|
883 context_frags = context.split('/') # A, B, C, D, E |
4a4d84273ae1
new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2704
diff
changeset
|
884 pagename_frags = pagename.split('/') # A, B, C, F |
4a4d84273ae1
new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2704
diff
changeset
|
885 # first throw away common parents: |
4a4d84273ae1
new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2704
diff
changeset
|
886 common = 0 |
4a4d84273ae1
new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2704
diff
changeset
|
887 for cf, pf in zip(context_frags, pagename_frags): |
4a4d84273ae1
new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2704
diff
changeset
|
888 if cf == pf: |
4a4d84273ae1
new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2704
diff
changeset
|
889 common += 1 |
4a4d84273ae1
new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2704
diff
changeset
|
890 else: |
4a4d84273ae1
new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2704
diff
changeset
|
891 break |
4a4d84273ae1
new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2704
diff
changeset
|
892 context_frags = context_frags[common:] # D, E |
4a4d84273ae1
new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2704
diff
changeset
|
893 pagename_frags = pagename_frags[common:] # F |
4a4d84273ae1
new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2704
diff
changeset
|
894 go_up = len(context_frags) |
4a4d84273ae1
new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2704
diff
changeset
|
895 return PARENT_PREFIX * go_up + '/'.join(pagename_frags) |
4a4d84273ae1
new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2704
diff
changeset
|
896 |
4a4d84273ae1
new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2704
diff
changeset
|
897 |
2773
2bbf611f4f2c
add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2771
diff
changeset
|
898 def pagelinkmarkup(pagename, text=None): |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
899 """ 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
|
900 from MoinMoin.parser.text_moin_wiki import Parser |
2773
2bbf611f4f2c
add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2771
diff
changeset
|
901 if re.match(Parser.word_rule + "$", pagename, re.U|re.X) and \ |
2bbf611f4f2c
add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2771
diff
changeset
|
902 (text is None or text == pagename): |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
903 return pagename |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
904 else: |
2773
2bbf611f4f2c
add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2771
diff
changeset
|
905 if text is None or text == pagename: |
2bbf611f4f2c
add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2771
diff
changeset
|
906 text = '' |
2bbf611f4f2c
add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2771
diff
changeset
|
907 else: |
2bbf611f4f2c
add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2771
diff
changeset
|
908 text = '|%s' % text |
2bbf611f4f2c
add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2771
diff
changeset
|
909 return u'[[%s%s]]' % (pagename, text) |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
910 |
801
1f8976e01c3a
fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
799
diff
changeset
|
911 ############################################################################# |
1f8976e01c3a
fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
799
diff
changeset
|
912 ### mimetype support |
1f8976e01c3a
fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
799
diff
changeset
|
913 ############################################################################# |
1f8976e01c3a
fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
799
diff
changeset
|
914 import mimetypes |
1f8976e01c3a
fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
799
diff
changeset
|
915 |
1f8976e01c3a
fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
799
diff
changeset
|
916 MIMETYPES_MORE = { |
1f8976e01c3a
fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
799
diff
changeset
|
917 # 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
|
918 '.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
|
919 '.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
|
920 '.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
|
921 '.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
|
922 '.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
|
923 '.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
|
924 '.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
|
925 '.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
|
926 '.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
|
927 '.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
|
928 '.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
|
929 '.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
|
930 '.otg': 'application/vnd.oasis.opendocument.graphics-template', |
3093
0f64646b9deb
adding some .ext -> mimetype mappings missing on some systems (like Mac OS X)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3068
diff
changeset
|
931 # some systems (like Mac OS X) don't have some of these: |
0f64646b9deb
adding some .ext -> mimetype mappings missing on some systems (like Mac OS X)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3068
diff
changeset
|
932 '.patch': 'text/x-diff', |
0f64646b9deb
adding some .ext -> mimetype mappings missing on some systems (like Mac OS X)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3068
diff
changeset
|
933 '.diff': 'text/x-diff', |
0f64646b9deb
adding some .ext -> mimetype mappings missing on some systems (like Mac OS X)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3068
diff
changeset
|
934 '.py': 'text/x-python', |
3615
3ec104f63144
wikiutil: MIMETYPES_MORE extended for cfg, conf
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
3573
diff
changeset
|
935 '.cfg': 'text/plain', |
3ec104f63144
wikiutil: MIMETYPES_MORE extended for cfg, conf
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
3573
diff
changeset
|
936 '.conf': 'text/plain', |
801
1f8976e01c3a
fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
799
diff
changeset
|
937 } |
1f8976e01c3a
fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
799
diff
changeset
|
938 [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
|
939 |
1f8976e01c3a
fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
799
diff
changeset
|
940 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
|
941 # 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
|
942 ('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
|
943 ('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
|
944 ('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
|
945 ('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
|
946 } |
1f8976e01c3a
fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
799
diff
changeset
|
947 |
1f8976e01c3a
fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
799
diff
changeset
|
948 MIMETYPES_spoil_mapping = {} # inverse mapping of above |
1920
b06ef2a53efa
'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1919
diff
changeset
|
949 for _key, _value in MIMETYPES_sanitize_mapping.items(): |
b06ef2a53efa
'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1919
diff
changeset
|
950 MIMETYPES_spoil_mapping[_value] = _key |
801
1f8976e01c3a
fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
799
diff
changeset
|
951 |
1f8976e01c3a
fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
799
diff
changeset
|
952 |
657
016a8a3ef354
wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
639
diff
changeset
|
953 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
|
954 """ 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
|
955 |
657
016a8a3ef354
wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
639
diff
changeset
|
956 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
|
957 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
|
958 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
|
959 self.charset = None # this stays None until we know for sure! |
1604
b2322cdabd8a
Added support for parser import with third-party legacy names.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1577
diff
changeset
|
960 self.raw_mimestr = mimestr |
657
016a8a3ef354
wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
639
diff
changeset
|
961 |
016a8a3ef354
wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
639
diff
changeset
|
962 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
|
963 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
|
964 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
|
965 self.parse_filename(filename) |
931
141083b64fb1
whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
930
diff
changeset
|
966 |
657
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 parse_filename(self, filename): |
773
bc1e460db2c8
fix bug in MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
672
diff
changeset
|
968 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
|
969 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
|
970 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
|
971 self.parse_mimetype(mtype) |
931
141083b64fb1
whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
930
diff
changeset
|
972 |
657
016a8a3ef354
wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
639
diff
changeset
|
973 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
|
974 """ 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
|
975 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
|
976 """ |
016a8a3ef354
wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
639
diff
changeset
|
977 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
|
978 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
|
979 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
|
980 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
|
981 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
|
982 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
|
983 else: |
016a8a3ef354
wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
639
diff
changeset
|
984 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
|
985 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
|
986 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
|
987 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
|
988 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
|
989 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
|
990 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
|
991 self.params[key.lower()] = value |
1868
64507f46beb2
reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1866
diff
changeset
|
992 if 'charset' in self.params: |
657
016a8a3ef354
wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
639
diff
changeset
|
993 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
|
994 self.sanitize() |
931
141083b64fb1
whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
930
diff
changeset
|
995 |
657
016a8a3ef354
wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
639
diff
changeset
|
996 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
|
997 """ 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
|
998 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
|
999 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
|
1000 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
|
1001 """ |
016a8a3ef354
wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
639
diff
changeset
|
1002 format = format.lower() |
3339
a07ac5a0811e
moved definition of text mimetype for parsers into config
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
3338
diff
changeset
|
1003 if format in config.parser_text_mimetype: |
657
016a8a3ef354
wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
639
diff
changeset
|
1004 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
|
1005 else: |
016a8a3ef354
wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
639
diff
changeset
|
1006 mapping = { |
016a8a3ef354
wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
639
diff
changeset
|
1007 '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
|
1008 '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
|
1009 } |
016a8a3ef354
wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
639
diff
changeset
|
1010 try: |
016a8a3ef354
wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
639
diff
changeset
|
1011 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
|
1012 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
|
1013 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
|
1014 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
|
1015 |
016a8a3ef354
wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
639
diff
changeset
|
1016 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
|
1017 """ 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
|
1018 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
|
1019 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
|
1020 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
|
1021 """ |
801
1f8976e01c3a
fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
799
diff
changeset
|
1022 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
|
1023 |
016a8a3ef354
wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
639
diff
changeset
|
1024 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
|
1025 """ 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
|
1026 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
|
1027 """ |
801
1f8976e01c3a
fix wrong import, make more use of MimeType class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
799
diff
changeset
|
1028 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
|
1029 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
|
1030 |
016a8a3ef354
wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
639
diff
changeset
|
1031 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
|
1032 """ 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
|
1033 """ |
016a8a3ef354
wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
639
diff
changeset
|
1034 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
|
1035 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
|
1036 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
|
1037 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
|
1038 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
|
1039 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
|
1040 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
|
1041 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
|
1042 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
|
1043 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
|
1044 |
016a8a3ef354
wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
639
diff
changeset
|
1045 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
|
1046 """ 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
|
1047 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
|
1048 |
016a8a3ef354
wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
639
diff
changeset
|
1049 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
|
1050 """ 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
|
1051 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
|
1052 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
|
1053 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
|
1054 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
|
1055 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
|
1056 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
|
1057 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
|
1058 """ |
016a8a3ef354
wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
639
diff
changeset
|
1059 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
|
1060 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
|
1061 fragments = modname.split('_') |
1604
b2322cdabd8a
Added support for parser import with third-party legacy names.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1577
diff
changeset
|
1062 for length in range(len(fragments), 1, -1): |
657
016a8a3ef354
wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
639
diff
changeset
|
1063 yield "_".join(fragments[:length]) |
1604
b2322cdabd8a
Added support for parser import with third-party legacy names.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1577
diff
changeset
|
1064 yield self.raw_mimestr |
b2322cdabd8a
Added support for parser import with third-party legacy names.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1577
diff
changeset
|
1065 yield fragments[0] |
657
016a8a3ef354
wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
639
diff
changeset
|
1066 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
|
1067 |
016a8a3ef354
wikiutil.MimeType class, renamed parsers to mimetype like module names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
639
diff
changeset
|
1068 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1069 ############################################################################# |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1070 ### Plugins |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1071 ############################################################################# |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1072 |
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
|
1073 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
|
1074 """ 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
|
1075 |
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
|
1076 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
|
1077 """ 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
|
1078 |
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
|
1079 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
|
1080 """ 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
|
1081 |
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
|
1082 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1083 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
|
1084 """ Import wiki or builtin plugin |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
1085 |
3802
88b2eecd1fed
wikiutil.importPlugin: support getting whole plugin module object by giving function=None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3615
diff
changeset
|
1086 Returns <function> attr from a plugin module <name>. |
88b2eecd1fed
wikiutil.importPlugin: support getting whole plugin module object by giving function=None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3615
diff
changeset
|
1087 If <function> attr is missing, raise PluginAttributeError. |
88b2eecd1fed
wikiutil.importPlugin: support getting whole plugin module object by giving function=None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3615
diff
changeset
|
1088 If <function> is None, return the whole module object. |
88b2eecd1fed
wikiutil.importPlugin: support getting whole plugin module object by giving function=None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3615
diff
changeset
|
1089 |
88b2eecd1fed
wikiutil.importPlugin: support getting whole plugin module object by giving function=None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3615
diff
changeset
|
1090 If <name> plugin can not be imported, raise PluginMissingError. |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1091 |
639
a80a6c629bc3
remove processor support, use a parser now
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
616
diff
changeset
|
1092 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
|
1093 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
|
1094 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1095 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
|
1096 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
|
1097 directly. |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
1098 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1099 @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
|
1100 @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
|
1101 @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
|
1102 @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
|
1103 @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
|
1104 @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
|
1105 """ |
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
|
1106 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
|
1107 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
|
1108 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
|
1109 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
|
1110 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1111 |
497
ef41e35985dc
new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents:
490
diff
changeset
|
1112 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
|
1113 """ Import plugin from the wiki data directory |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
1114 |
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
|
1115 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
|
1116 """ |
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
|
1117 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
|
1118 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
|
1119 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
|
1120 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
|
1121 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1122 |
497
ef41e35985dc
new scripting method, using 'moin' command. new style migration scripts.
Thomas Waldmann <tw@waldmann-edv.de>
parents:
490
diff
changeset
|
1123 def importBuiltinPlugin(kind, name, function="execute"): |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
1124 """ Import builtin plugin from MoinMoin package |
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
1125 |
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
|
1126 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
|
1127 """ |
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
|
1128 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
|
1129 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
|
1130 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
|
1131 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
|
1132 |
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
|
1133 |
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
|
1134 def importNameFromPlugin(moduleName, name): |
3802
88b2eecd1fed
wikiutil.importPlugin: support getting whole plugin module object by giving function=None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3615
diff
changeset
|
1135 """ Return <name> attr from <moduleName> module, |
88b2eecd1fed
wikiutil.importPlugin: support getting whole plugin module object by giving function=None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3615
diff
changeset
|
1136 raise PluginAttributeError if name does not exist. |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
1137 |
3802
88b2eecd1fed
wikiutil.importPlugin: support getting whole plugin module object by giving function=None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3615
diff
changeset
|
1138 If name is None, return the <moduleName> module object. |
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
|
1139 """ |
3802
88b2eecd1fed
wikiutil.importPlugin: support getting whole plugin module object by giving function=None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3615
diff
changeset
|
1140 if name is None: |
88b2eecd1fed
wikiutil.importPlugin: support getting whole plugin module object by giving function=None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3615
diff
changeset
|
1141 fromlist = [] |
88b2eecd1fed
wikiutil.importPlugin: support getting whole plugin module object by giving function=None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3615
diff
changeset
|
1142 else: |
88b2eecd1fed
wikiutil.importPlugin: support getting whole plugin module object by giving function=None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3615
diff
changeset
|
1143 fromlist = [name] |
88b2eecd1fed
wikiutil.importPlugin: support getting whole plugin module object by giving function=None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3615
diff
changeset
|
1144 module = __import__(moduleName, globals(), {}, fromlist) |
88b2eecd1fed
wikiutil.importPlugin: support getting whole plugin module object by giving function=None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3615
diff
changeset
|
1145 if fromlist: |
88b2eecd1fed
wikiutil.importPlugin: support getting whole plugin module object by giving function=None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3615
diff
changeset
|
1146 # module has the obj for module <moduleName> |
88b2eecd1fed
wikiutil.importPlugin: support getting whole plugin module object by giving function=None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3615
diff
changeset
|
1147 try: |
88b2eecd1fed
wikiutil.importPlugin: support getting whole plugin module object by giving function=None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3615
diff
changeset
|
1148 return getattr(module, name) |
88b2eecd1fed
wikiutil.importPlugin: support getting whole plugin module object by giving function=None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3615
diff
changeset
|
1149 except AttributeError: |
88b2eecd1fed
wikiutil.importPlugin: support getting whole plugin module object by giving function=None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3615
diff
changeset
|
1150 raise PluginAttributeError |
88b2eecd1fed
wikiutil.importPlugin: support getting whole plugin module object by giving function=None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
3615
diff
changeset
|
1151 else: |
3812
30ed528054ed
fix some pep8 failures
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3802
diff
changeset
|
1152 # module now has the toplevel module of <moduleName> (see __import__ docs!) |
30ed528054ed
fix some pep8 failures
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3802
diff
changeset
|
1153 components = moduleName.split('.') |
30ed528054ed
fix some pep8 failures
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3802
diff
changeset
|
1154 for comp in components[1:]: |
30ed528054ed
fix some pep8 failures
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3802
diff
changeset
|
1155 module = getattr(module, comp) |
30ed528054ed
fix some pep8 failures
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3802
diff
changeset
|
1156 return module |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1157 |
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
|
1158 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1159 def builtinPlugins(kind): |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1160 """ Gets a list of modules in MoinMoin.'kind' |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
1161 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1162 @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
|
1163 @rtype: list |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1164 @return: module names |
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 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
|
1167 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
|
1168 |
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 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
|
1171 """ Gets a list of modules in data/plugin/'kind' |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
1172 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1173 @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
|
1174 @rtype: list |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1175 @return: module names |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1176 """ |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1177 # 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
|
1178 modulename = '%s.plugin.%s' % (cfg.siteid, kind) |
2381
b8b87daf7cc4
don't require all plugins to be in the data/plugin dir, cache modules list
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2378
diff
changeset
|
1179 |
b8b87daf7cc4
don't require all plugins to be in the data/plugin dir, cache modules list
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2378
diff
changeset
|
1180 # short-cut if we've loaded the list already |
b8b87daf7cc4
don't require all plugins to be in the data/plugin dir, cache modules list
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2378
diff
changeset
|
1181 # (or already failed to load it) |
b8b87daf7cc4
don't require all plugins to be in the data/plugin dir, cache modules list
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2378
diff
changeset
|
1182 if kind in cfg._site_plugin_lists: |
b8b87daf7cc4
don't require all plugins to be in the data/plugin dir, cache modules list
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2378
diff
changeset
|
1183 return cfg._site_plugin_lists[kind] |
b8b87daf7cc4
don't require all plugins to be in the data/plugin dir, cache modules list
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2378
diff
changeset
|
1184 |
b8b87daf7cc4
don't require all plugins to be in the data/plugin dir, cache modules list
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2378
diff
changeset
|
1185 try: |
b8b87daf7cc4
don't require all plugins to be in the data/plugin dir, cache modules list
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2378
diff
changeset
|
1186 plugins = pysupport.importName(modulename, "modules") |
b8b87daf7cc4
don't require all plugins to be in the data/plugin dir, cache modules list
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2378
diff
changeset
|
1187 cfg._site_plugin_lists[kind] = plugins |
b8b87daf7cc4
don't require all plugins to be in the data/plugin dir, cache modules list
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2378
diff
changeset
|
1188 return plugins |
b8b87daf7cc4
don't require all plugins to be in the data/plugin dir, cache modules list
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2378
diff
changeset
|
1189 except ImportError: |
b8b87daf7cc4
don't require all plugins to be in the data/plugin dir, cache modules list
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2378
diff
changeset
|
1190 cfg._site_plugin_lists[kind] = [] |
b8b87daf7cc4
don't require all plugins to be in the data/plugin dir, cache modules list
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2378
diff
changeset
|
1191 return [] |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1192 |
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 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
|
1195 """ Gets a list of plugin names of kind |
2286
01f05e74aa9c
Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
2267
diff
changeset
|
1196 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1197 @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
|
1198 @rtype: list |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1199 @return: module names |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1200 """ |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1201 # 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
|
1202 all_plugins = builtinPlugins(kind)[:] |
931
141083b64fb1
whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
930
diff
changeset
|
1203 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1204 # 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
|
1205 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
|
1206 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
|
1207 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
|
1208 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1209 return all_plugins |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1210 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1211 |
1520
563bfe02b04f
Removed a lot of ugly MimeType() calls, refactored it into a helper, fixed page rendering for missing parsers.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1355
diff
changeset
|
1212 def searchAndImportPlugin(cfg, type, name, what=None): |
563bfe02b04f
Removed a lot of ugly MimeType() calls, refactored it into a helper, fixed page rendering for missing parsers.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1355
diff
changeset
|
1213 type2classname = {"parser": "Parser", |
563bfe02b04f
Removed a lot of ugly MimeType() calls, refactored it into a helper, fixed page rendering for missing parsers.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1355
diff
changeset
|
1214 "formatter": "Formatter", |
563bfe02b04f
Removed a lot of ugly MimeType() calls, refactored it into a helper, fixed page rendering for missing parsers.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1355
diff
changeset
|
1215 } |
563bfe02b04f
Removed a lot of ugly MimeType() calls, refactored it into a helper, fixed page rendering for missing parsers.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1355
diff
changeset
|
1216 if what is None: |
563bfe02b04f
Removed a lot of ugly MimeType() calls, refactored it into a helper, fixed page rendering for missing parsers.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1355
diff
changeset
|
1217 what = type2classname[type] |
563bfe02b04f
Removed a lot of ugly MimeType() calls, refactored it into a helper, fixed page rendering for missing parsers.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1355
diff
changeset
|
1218 mt = MimeType(name) |
563bfe02b04f
Removed a lot of ugly MimeType() calls, refactored it into a helper, fixed page rendering for missing parsers.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1355
diff
changeset
|
1219 plugin = None |
563bfe02b04f
Removed a lot of ugly MimeType() calls, refactored it into a helper, fixed page rendering for missing parsers.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1355
diff
changeset
|
1220 for module_name in mt.module_name(): |
563bfe02b04f
Removed a lot of ugly MimeType() calls, refactored it into a helper, fixed page rendering for missing parsers.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1355
diff
changeset
|
1221 try: |
563bfe02b04f
Removed a lot of ugly MimeType() calls, refactored it into a helper, fixed page rendering for missing parsers.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1355
diff
changeset
|
1222 plugin = importPlugin(cfg, type, module_name, what) |
563bfe02b04f
Removed a lot of ugly MimeType() calls, refactored it into a helper, fixed page rendering for missing parsers.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1355
diff
changeset
|
1223 break |
563bfe02b04f
Removed a lot of ugly MimeType() calls, refactored it into a helper, fixed page rendering for missing parsers.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1355
diff
changeset
|
1224 except PluginMissingError: |
563bfe02b04f
Removed a lot of ugly MimeType() calls, refactored it into a helper, fixed page rendering for missing parsers.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1355
diff
changeset
|
1225 pass |
563bfe02b04f
Removed a lot of ugly MimeType() calls, refactored it into a helper, fixed page rendering for missing parsers.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1355
diff
changeset
|
1226 else: |
563bfe02b04f
Removed a lot of ugly MimeType() calls, refactored it into a helper, fixed page rendering for missing parsers.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1355
diff
changeset
|
1227 raise PluginMissingError("Plugin not found!") |
563bfe02b04f
Removed a lot of ugly MimeType() calls, refactored it into a helper, fixed page rendering for missing parsers.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1355
diff
changeset
|
1228 return plugin |
563bfe02b04f
Removed a lot of ugly MimeType() calls, refactored it into a helper, fixed page rendering for missing parsers.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1355
diff
changeset
|
1229 |
563bfe02b04f
Removed a lot of ugly MimeType() calls, refactored it into a helper, fixed page rendering for missing parsers.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
1355
diff
changeset
|
1230 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1231 ############################################################################# |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1232 ### Parsers |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1233 ############################################################################# |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1234 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1235 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
|
1236 """ |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1237 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
|
1238 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
|
1239 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
|
1240 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
|
1241 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
|
1242 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1243 @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
|
1244 @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
|
1245 @rtype: class, None |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1246 @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
|
1247 """ |
1550
a4f0632414da
using request.cfg.cache more
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1549
diff
changeset
|
1248 if not hasattr(cfg.cache, 'EXT_TO_PARSER'): |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1249 etp, etd = {}, None |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1250 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
|
1251 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
|
1252 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
|
1253 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
|
1254 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
|
1255 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
|
1256 exts = Parser.extensions |
1181
a7f8dceb4410
remove types module usage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1122
diff
changeset
|
1257 if isinstance(exts, list): |
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
|
1258 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
|
1259 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
|
1260 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
|
1261 etd = Parser |
1550
a4f0632414da
using request.cfg.cache more
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1549
diff
changeset
|
1262 cfg.cache.EXT_TO_PARSER = etp |
a4f0632414da
using request.cfg.cache more
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1549
diff
changeset
|
1263 cfg.cache.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
|
1264 |
1550
a4f0632414da
using request.cfg.cache more
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1549
diff
changeset
|
1265 return cfg.cache.EXT_TO_PARSER.get(extension, cfg.cache.EXT_TO_PARSER_DEFAULT) |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1266 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1267 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1268 ############################################################################# |
671
68d93872d4c9
removed duplicate code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
657
diff
changeset
|
1269 ### Parameter parsing |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1270 ############################################################################# |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1271 |
3399
b6d727809985
introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3371
diff
changeset
|
1272 class BracketError(Exception): |
b6d727809985
introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3371
diff
changeset
|
1273 pass |
b6d727809985
introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3371
diff
changeset
|
1274 |
b6d727809985
introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3371
diff
changeset
|
1275 class BracketUnexpectedCloseError(BracketError): |
b6d727809985
introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3371
diff
changeset
|
1276 def __init__(self, bracket): |
b6d727809985
introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3371
diff
changeset
|
1277 self.bracket = bracket |
b6d727809985
introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3371
diff
changeset
|
1278 BracketError.__init__(self, "Unexpected closing bracket %s" % bracket) |
b6d727809985
introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3371
diff
changeset
|
1279 |
b6d727809985
introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3371
diff
changeset
|
1280 class BracketMissingCloseError(BracketError): |
b6d727809985
introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3371
diff
changeset
|
1281 def __init__(self, bracket): |
b6d727809985
introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3371
diff
changeset
|
1282 self.bracket = bracket |
b6d727809985
introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3371
diff
changeset
|
1283 BracketError.__init__(self, "Missing closing bracket %s" % bracket) |
b6d727809985
introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3371
diff
changeset
|
1284 |
3403
d479e393e318
wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3402
diff
changeset
|
1285 class ParserPrefix: |
d479e393e318
wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3402
diff
changeset
|
1286 """ |
d479e393e318
wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3402
diff
changeset
|
1287 Trivial container-class holding a single character for |
d479e393e318
wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3402
diff
changeset
|
1288 the possible prefixes for parse_quoted_separated_ext |
d479e393e318
wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3402
diff
changeset
|
1289 and implementing rich equal comparison. |
d479e393e318
wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3402
diff
changeset
|
1290 """ |
d479e393e318
wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3402
diff
changeset
|
1291 def __init__(self, prefix): |
d479e393e318
wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3402
diff
changeset
|
1292 self.prefix = prefix |
d479e393e318
wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3402
diff
changeset
|
1293 |
d479e393e318
wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3402
diff
changeset
|
1294 def __eq__(self, other): |
d479e393e318
wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3402
diff
changeset
|
1295 return isinstance(other, ParserPrefix) and other.prefix == self.prefix |
d479e393e318
wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3402
diff
changeset
|
1296 |
d479e393e318
wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3402
diff
changeset
|
1297 def __repr__(self): |
d479e393e318
wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3402
diff
changeset
|
1298 return '<ParserPrefix(%s)>' % self.prefix.encode('utf-8') |
d479e393e318
wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3402
diff
changeset
|
1299 |
3399
b6d727809985
introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3371
diff
changeset
|
1300 def parse_quoted_separated_ext(args, separator=None, name_value_separator=None, |
3403
d479e393e318
wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3402
diff
changeset
|
1301 brackets=None, seplimit=0, multikey=False, |
3405
6f5e09f14525
parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3404
diff
changeset
|
1302 prefixes=None, quotes='"'): |
2507
ea255685d6b0
add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
2457
diff
changeset
|
1303 """ |
3399
b6d727809985
introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3371
diff
changeset
|
1304 Parses the given string according to the other parameters. |
b6d727809985
introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3371
diff
changeset
|
1305 |
3405
6f5e09f14525
parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents:
3404
diff
|