annotate MoinMoin/script/migration/_conv160a_wiki.py @ 4636:83483f4e26cb

merged moin/1.8
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 07 Mar 2009 22:38:00 +0100
parents 3caaa8c74c41 b0319cfcb1bc
children 10965bc1ee3c
rev   line source
3925
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
2 """
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
3 MoinMoin - convert content in 1.6.0alpha (rev 1844: 58ebb64243cc) wiki markup to 1.6.0 style
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
4 by using a modified 1.6.0alpha parser as translator.
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
5
4488
a2a05ae3e7ec 1.6.0a mig script/converter: add tests, improve test compliance, clean up
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3925
diff changeset
6 PLEASE NOTE: most moin users will never need to execute this code,
a2a05ae3e7ec 1.6.0a mig script/converter: add tests, improve test compliance, clean up
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3925
diff changeset
7 because it is just for users of 1.6.0alpha version,
a2a05ae3e7ec 1.6.0a mig script/converter: add tests, improve test compliance, clean up
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3925
diff changeset
8 that used modified link markup, but was never released.
a2a05ae3e7ec 1.6.0a mig script/converter: add tests, improve test compliance, clean up
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3925
diff changeset
9 The 1.5.x/1.6.x releases use a different link markup than 1.6.0a.
3925
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
10
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
11 @copyright: 2007 MoinMoin:JohannesBerg,
4488
a2a05ae3e7ec 1.6.0a mig script/converter: add tests, improve test compliance, clean up
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3925
diff changeset
12 2007-2009 MoinMoin:ThomasWaldmann
3925
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
13 @license: GNU GPL, see COPYING for details.
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
14 """
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
15
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
16 import re
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
17
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
18 from MoinMoin import i18n
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
19 i18n.wikiLanguages = lambda: {}
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
20
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
21 from MoinMoin import config, macro, wikiutil
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
22 from MoinMoin.action import AttachFile
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
23 from MoinMoin.Page import Page
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
24 from MoinMoin.support.python_compatibility import rsplit
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
25
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
26 import wikiutil160a
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
27 from text_moin160a_wiki import Parser
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
28
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
29 QUOTE_CHARS = u"'\""
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
30
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
31 def convert_wiki(request, pagename, intext, renames):
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
32 """ Convert content written in wiki markup """
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
33 noeol = False
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
34 if not intext.endswith('\r\n'):
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
35 intext += '\r\n'
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
36 noeol = True
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
37 c = Converter(request, pagename, intext, renames)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
38 result = request.redirectedOutput(c.convert, request)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
39 if noeol and result.endswith('\r\n'):
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
40 result = result[:-2]
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
41 return result
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
42
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
43
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
44 STONEAGE_IMAGELINK = False # True for ImageLink(target,image), False for ImageLink(image,target)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
45
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
46 # copied from moin 1.6.0 macro/ImageLink.py (to be safe in case we remove ImageLink some day)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
47 # ... and slightly modified/refactored for our needs here.
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
48 # hint: using parse_quoted_separated from wikiutil does NOT work here, because we do not have
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
49 # quoted urls when they contain a '=' char in the 1.5 data input.
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
50 def explore_args(args):
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
51 """ explore args for positional and keyword parameters """
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
52 if args:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
53 args = args.split(',')
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
54 args = [arg.strip() for arg in args]
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
55 else:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
56 args = []
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
57
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
58 kw_count = 0
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
59 kw = {} # keyword args
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
60 pp = [] # positional parameters
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
61
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
62 kwAllowed = ('width', 'height', 'alt')
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
63
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
64 for arg in args:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
65 if '=' in arg:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
66 key, value = arg.split('=', 1)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
67 key_lowerstr = str(key.lower())
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
68 # avoid that urls with "=" are interpreted as keyword
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
69 if key_lowerstr in kwAllowed:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
70 kw_count += 1
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
71 kw[key_lowerstr] = value
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
72 elif not kw_count and '://' in arg:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
73 # assuming that this is the image
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
74 pp.append(arg)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
75 else:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
76 pp.append(arg)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
77
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
78 if STONEAGE_IMAGELINK and len(pp) >= 2:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
79 pp[0], pp[1] = pp[1], pp[0]
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
80
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
81 return pp, kw
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
82
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
83
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
84 class Converter(Parser):
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
85 def __init__(self, request, pagename, raw, renames):
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
86 self.pagename = pagename
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
87 self.raw = raw
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
88 self.renames = renames
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
89 self.request = request
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
90 self._ = None
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
91 self.in_pre = 0
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
92
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
93 self.formatting_rules = self.formatting_rules % {'macronames': u'|'.join(['ImageLink', ] + macro.getNames(self.request.cfg))}
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
94
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
95 # no change
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
96 def return_word(self, word):
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
97 return word
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
98 _emph_repl = return_word
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
99 _emph_ibb_repl = return_word
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
100 _emph_ibi_repl = return_word
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
101 _emph_ib_or_bi_repl = return_word
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
102 _u_repl = return_word
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
103 _strike_repl = return_word
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
104 _sup_repl = return_word
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
105 _sub_repl = return_word
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
106 _small_repl = return_word
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
107 _big_repl = return_word
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
108 _tt_repl = return_word
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
109 _tt_bt_repl = return_word
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
110 _remark_repl = return_word
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
111 _table_repl = return_word
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
112 _tableZ_repl = return_word
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
113 _rule_repl = return_word
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
114 _smiley_repl = return_word
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
115 _smileyA_repl = return_word
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
116 _ent_repl = return_word
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
117 _ent_numeric_repl = return_word
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
118 _ent_symbolic_repl = return_word
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
119 _heading_repl = return_word
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
120 _email_repl = return_word
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
121 _notword_repl = return_word
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
122 _indent_repl = return_word
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
123 _li_none_repl = return_word
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
124 _li_repl = return_word
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
125 _ol_repl = return_word
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
126 _dl_repl = return_word
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
127 _comment_repl = return_word
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
128
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
129 # translate pagenames using pagename translation map
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
130
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
131 def _replace(self, key):
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
132 """ replace a item_name if it is in the renames dict
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
133 key is either a 2-tuple ('PAGE', pagename)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
134 or a 3-tuple ('FILE', pagename, filename)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
135 """
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
136 current_page = self.pagename
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
137 item_type, page_name, file_name = (key + (None, ))[:3]
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
138 abs_page_name = wikiutil.AbsPageName(current_page, page_name)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
139 if item_type == 'PAGE':
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
140 key = (item_type, abs_page_name)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
141 new_name = self.renames.get(key)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
142 if new_name is None:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
143 # we don't have an entry in rename map - apply the same magic
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
144 # to the page name as 1.5 did (" " -> "_") and try again:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
145 abs_magic_name = abs_page_name.replace(u' ', u'_')
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
146 key = (item_type, abs_magic_name)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
147 new_name = self.renames.get(key)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
148 if new_name is None:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
149 # we didn't find it under the magic name either -
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
150 # that means we do not rename it!
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
151 new_name = page_name
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
152 if new_name != page_name and abs_page_name != page_name:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
153 # we have to fix the (absolute) new_name to be a relative name (as it was before)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
154 new_name = wikiutil.RelPageName(current_page, new_name)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
155 elif item_type == 'FILE':
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
156 key = (item_type, abs_page_name, file_name)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
157 new_name = self.renames.get(key)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
158 if new_name is None:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
159 # we don't have an entry in rename map - apply the same magic
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
160 # to the page name as 1.5 did (" " -> "_") and try again:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
161 abs_magic_name = abs_page_name.replace(u' ', u'_')
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
162 key = (item_type, abs_magic_name, file_name)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
163 new_name = self.renames.get(key)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
164 if new_name is None:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
165 # we didn't find it under the magic name either -
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
166 # that means we do not rename it!
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
167 new_name = file_name
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
168 return new_name
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
169
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
170 def _replace_target(self, target):
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
171 target_and_anchor = rsplit(target, '#', 1)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
172 if len(target_and_anchor) > 1:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
173 target, anchor = target_and_anchor
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
174 target = self._replace(('PAGE', target))
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
175 return '%s#%s' % (target, anchor)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
176 else:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
177 target = self._replace(('PAGE', target))
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
178 return target
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
179
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
180 # markup conversion
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
181
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
182 def _macro_repl(self, word):
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
183 # we use [[...]] for links now, macros will be <<...>>
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
184 macro_rule = ur"""
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
185 \[\[
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
186 (?P<macro_name>\w+)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
187 (\((?P<macro_args>.*?)\))?
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
188 \]\]
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
189 """
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
190 word = unicode(word) # XXX why is word not unicode before???
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
191 m = re.match(macro_rule, word, re.X|re.U)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
192 macro_name = m.group('macro_name')
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
193 macro_args = m.group('macro_args')
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
194 if macro_name == 'ImageLink':
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
195 fixed, kw = explore_args(macro_args)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
196 #print "macro_args=%r" % macro_args
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
197 #print "fixed=%r, kw=%r" % (fixed, kw)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
198 image, target = (fixed + ['', ''])[:2]
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
199 if image is None:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
200 image = ''
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
201 if target is None:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
202 target = ''
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
203 if '://' not in image:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
204 # if it is not a URL, it is meant as attachment
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
205 image = u'attachment:%s' % image
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
206 if not target:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
207 target = image
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
208 elif target.startswith('inline:'):
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
209 target = 'attachment:' + target[7:] # we don't support inline:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
210 elif target.startswith('wiki:'):
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
211 target = target[5:] # drop wiki:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
212 image_attrs = []
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
213 alt = kw.get('alt') or ''
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
214 width = kw.get('width')
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
215 if width is not None:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
216 image_attrs.append(u"width=%s" % width)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
217 height = kw.get('height')
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
218 if height is not None:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
219 image_attrs.append(u"height=%s" % height)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
220 image_attrs = u", ".join(image_attrs)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
221 if image_attrs:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
222 image_attrs = u'|' + image_attrs
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
223 if alt or image_attrs:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
224 alt = u'|' + alt
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
225 result = u'[[%s|{{%s%s%s}}]]' % (target, image, alt, image_attrs)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
226 else:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
227 if macro_args:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
228 macro_args = u"(%s)" % macro_args
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
229 else:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
230 macro_args = u''
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
231 result = u"<<%s%s>>" % (macro_name, macro_args)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
232 # XXX later check whether some to be renamed pagename is used as macro param
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
233 return result
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
234
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
235 def _word_repl(self, word, text=None):
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
236 """Handle WikiNames."""
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
237 if not text:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
238 if wikiutil.isStrictWikiname(word):
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
239 return word
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
240 else:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
241 return '[[%s]]' % word
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
242 else: # internal use:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
243 return '[[%s|%s]]' % (word, text)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
244
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
245 def _wikiname_bracket_repl(self, text):
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
246 """Handle special-char wikinames with link text, like:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
247 ["Jim O'Brian" Jim's home page] or ['Hello "world"!' a page with doublequotes]
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
248 """
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
249 word = text[1:-1] # strip brackets
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
250 first_char = word[0]
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
251 if first_char in QUOTE_CHARS:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
252 # split on closing quote
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
253 target, linktext = word[1:].split(first_char, 1)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
254 else: # not quoted
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
255 # split on whitespace
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
256 target, linktext = word.split(None, 1)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
257 if target:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
258 target = self._replace(('PAGE', target))
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
259 linktext = linktext.strip()
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
260 if linktext and linktext != target:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
261 return '[[%s|%s]]' % (target, linktext)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
262 else:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
263 return '[[%s]]' % target
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
264 else:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
265 return text
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
266
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
267 def _interwiki_repl(self, word):
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
268 """Handle InterWiki links."""
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
269 wikitag, wikiurl, wikitail, wikitag_bad = wikiutil.resolve_wiki(self.request, word)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
270 if wikitag_bad:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
271 return word
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
272 else:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
273 return self.interwiki("wiki:" + word)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
274
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
275 def interwiki(self, target_and_text, **kw):
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
276 scheme, rest = target_and_text.split(':', 1)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
277 wikiname, pagename, text = wikiutil160a.split_wiki(rest)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
278
4489
a835ada897e0 1.6.0a mig script/converter: fix interwiki tests, cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4488
diff changeset
279 #if (pagename.startswith(wikiutil.CHILD_PREFIX) or # fancy link to subpage [wiki:/SubPage text]
a835ada897e0 1.6.0a mig script/converter: fix interwiki tests, cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4488
diff changeset
280 # Page(self.request, pagename).exists()): # fancy link to local page [wiki:LocalPage text]
a835ada897e0 1.6.0a mig script/converter: fix interwiki tests, cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4488
diff changeset
281 # # XXX OtherWiki:FooPage markup -> checks for local FooPage -sense???
a835ada897e0 1.6.0a mig script/converter: fix interwiki tests, cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4488
diff changeset
282 # pagename = wikiutil.url_unquote(pagename)
a835ada897e0 1.6.0a mig script/converter: fix interwiki tests, cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4488
diff changeset
283 # pagename = self._replace_target(pagename)
a835ada897e0 1.6.0a mig script/converter: fix interwiki tests, cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4488
diff changeset
284 # return '[[%s%s]]' % (pagename, text)
3925
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
285
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
286 if wikiname in ('Self', self.request.cfg.interwikiname, ''): # [wiki:Self:LocalPage text] or [:LocalPage:text]
4489
a835ada897e0 1.6.0a mig script/converter: fix interwiki tests, cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4488
diff changeset
287 orig_pagename = pagename
3925
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
288 pagename = wikiutil.url_unquote(pagename)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
289 pagename = self._replace_target(pagename)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
290 camelcase = wikiutil.isStrictWikiname(pagename)
4489
a835ada897e0 1.6.0a mig script/converter: fix interwiki tests, cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4488
diff changeset
291 if camelcase and (not text or text == orig_pagename):
a835ada897e0 1.6.0a mig script/converter: fix interwiki tests, cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4488
diff changeset
292 return pagename # optimize special case
3925
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
293 else:
4489
a835ada897e0 1.6.0a mig script/converter: fix interwiki tests, cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4488
diff changeset
294 if text:
a835ada897e0 1.6.0a mig script/converter: fix interwiki tests, cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4488
diff changeset
295 text = '|' + text
3925
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
296 return '[[%s%s]]' % (pagename, text)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
297
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
298 wikitag, wikiurl, wikitail, wikitag_bad = wikiutil.resolve_wiki(self.request, wikiname+':')
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
299 if wikitag_bad: # likely we got some /InterWiki as wikitail, we don't want that!
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
300 pagename = wikiutil.url_unquote(pagename)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
301 pagename = self._replace_target(pagename)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
302 wikitail = pagename
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
303 else: # good
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
304 wikitail = wikiutil.url_unquote(pagename)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
305
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
306 # link to self?
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
307 if wikiutil.isPicture(wikitail):
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
308 return '{{%s:%s%s}}' % (wikitag, wikitail, text)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
309 else:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
310 if ' ' not in wikitail and not text:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
311 return '%s:%s' % (wikitag, wikitail)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
312 else:
4489
a835ada897e0 1.6.0a mig script/converter: fix interwiki tests, cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4488
diff changeset
313 if text:
a835ada897e0 1.6.0a mig script/converter: fix interwiki tests, cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4488
diff changeset
314 text = '|' + text
3925
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
315 return '[[%s:%s%s]]' % (wikitag, wikitail, text)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
316
4488
a2a05ae3e7ec 1.6.0a mig script/converter: add tests, improve test compliance, clean up
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3925
diff changeset
317 def attachment(self, target_and_text, **kw):
a2a05ae3e7ec 1.6.0a mig script/converter: add tests, improve test compliance, clean up
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3925
diff changeset
318 """ This gets called on attachment URLs """
a2a05ae3e7ec 1.6.0a mig script/converter: add tests, improve test compliance, clean up
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3925
diff changeset
319 _ = self._
a2a05ae3e7ec 1.6.0a mig script/converter: add tests, improve test compliance, clean up
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3925
diff changeset
320 scheme, fname, text = wikiutil160a.split_wiki(target_and_text)
3925
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
321
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
322 pagename, fname = AttachFile.absoluteName(fname, self.pagename)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
323 from_this_page = pagename == self.pagename
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
324 fname = self._replace(('FILE', pagename, fname))
4569
3caaa8c74c41 wikiutil: replace moin's cgi/urllib wrappers by calls to werkzeug.utils code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4490
diff changeset
325 #fname = wikiutil.url_unquote(fname)
4488
a2a05ae3e7ec 1.6.0a mig script/converter: add tests, improve test compliance, clean up
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3925
diff changeset
326 #fname = self._replace(('FILE', pagename, fname))
3925
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
327 pagename = self._replace(('PAGE', pagename))
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
328 if from_this_page:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
329 name = fname
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
330 else:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
331 name = "%s/%s" % (pagename, fname)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
332
4488
a2a05ae3e7ec 1.6.0a mig script/converter: add tests, improve test compliance, clean up
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3925
diff changeset
333 fn_txt = name
3925
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
334 if text:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
335 fn_txt += '|' + text
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
336
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
337 if scheme == 'drawing':
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
338 return "{{drawing:%s}}" % fn_txt
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
339
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
340 # check for image, and possibly return IMG tag (images are always inlined)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
341 if not kw.get('pretty_url', 0) and wikiutil.isPicture(fname):
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
342 return "{{attachment:%s}}" % fn_txt
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
343
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
344 # inline the attachment
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
345 if scheme == 'inline':
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
346 return '{{attachment:%s}}' % fn_txt
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
347
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
348 return '[[attachment:%s]]' % fn_txt
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
349
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
350 def _url_repl(self, word):
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
351 """Handle literal URLs including inline images."""
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
352 scheme = word.split(":", 1)[0]
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
353
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
354 if scheme == 'wiki':
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
355 return self.interwiki(word)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
356 if scheme in self.attachment_schemas:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
357 return '%s' % self.attachment(word)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
358
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
359 if wikiutil.isPicture(word): # magic will go away in 1.6!
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
360 return '{{%s}}' % word # new markup for inline images
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
361 else:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
362 return word
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
363
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
364
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
365 def _url_bracket_repl(self, word):
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
366 """Handle bracketed URLs."""
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
367 word = word[1:-1] # strip brackets
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
368
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
369 # Local extended link? [:page name:link text] XXX DEPRECATED
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
370 if word[0] == ':':
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
371 words = word[1:].split(':', 1)
4488
a2a05ae3e7ec 1.6.0a mig script/converter: add tests, improve test compliance, clean up
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3925
diff changeset
372 link, text = (words + ['', ''])[:2]
a2a05ae3e7ec 1.6.0a mig script/converter: add tests, improve test compliance, clean up
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3925
diff changeset
373 if link.strip() == text.strip():
a2a05ae3e7ec 1.6.0a mig script/converter: add tests, improve test compliance, clean up
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3925
diff changeset
374 text = ''
a2a05ae3e7ec 1.6.0a mig script/converter: add tests, improve test compliance, clean up
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3925
diff changeset
375 link = self._replace_target(link)
a2a05ae3e7ec 1.6.0a mig script/converter: add tests, improve test compliance, clean up
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3925
diff changeset
376 if text:
a2a05ae3e7ec 1.6.0a mig script/converter: add tests, improve test compliance, clean up
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3925
diff changeset
377 text = '|' + text
a2a05ae3e7ec 1.6.0a mig script/converter: add tests, improve test compliance, clean up
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3925
diff changeset
378 return '[[%s%s]]' % (link, text)
3925
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
379
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
380 scheme_and_rest = word.split(":", 1)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
381 if len(scheme_and_rest) == 1: # no scheme
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
382 # Traditional split on space
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
383 words = word.split(None, 1)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
384 if words[0].startswith('#'): # anchor link
4488
a2a05ae3e7ec 1.6.0a mig script/converter: add tests, improve test compliance, clean up
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3925
diff changeset
385 link, text = (words + ['', ''])[:2]
a2a05ae3e7ec 1.6.0a mig script/converter: add tests, improve test compliance, clean up
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3925
diff changeset
386 if link.strip() == text.strip():
a2a05ae3e7ec 1.6.0a mig script/converter: add tests, improve test compliance, clean up
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3925
diff changeset
387 text = ''
a2a05ae3e7ec 1.6.0a mig script/converter: add tests, improve test compliance, clean up
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3925
diff changeset
388 if text:
a2a05ae3e7ec 1.6.0a mig script/converter: add tests, improve test compliance, clean up
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3925
diff changeset
389 text = '|' + text
a2a05ae3e7ec 1.6.0a mig script/converter: add tests, improve test compliance, clean up
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3925
diff changeset
390 return '[[%s%s]]' % (link, text)
3925
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
391 else:
4488
a2a05ae3e7ec 1.6.0a mig script/converter: add tests, improve test compliance, clean up
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3925
diff changeset
392 scheme = scheme_and_rest[0]
3925
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
393 if scheme == "wiki":
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
394 return self.interwiki(word, pretty_url=1)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
395 if scheme in self.attachment_schemas:
4488
a2a05ae3e7ec 1.6.0a mig script/converter: add tests, improve test compliance, clean up
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3925
diff changeset
396 m = self.attachment(word)
4490
b120d9978144 1.6.0a mig script/converter: fixed inline/drawing conversion, added more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4489
diff changeset
397 if scheme == 'attachment':
b120d9978144 1.6.0a mig script/converter: fixed inline/drawing conversion, added more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4489
diff changeset
398 # with url_bracket markup, 1.6.0a parser does not embed pictures, but link!
b120d9978144 1.6.0a mig script/converter: fixed inline/drawing conversion, added more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4489
diff changeset
399 return '[[%s]]' % m[2:-2]
b120d9978144 1.6.0a mig script/converter: fixed inline/drawing conversion, added more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4489
diff changeset
400 else:
b120d9978144 1.6.0a mig script/converter: fixed inline/drawing conversion, added more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4489
diff changeset
401 # drawing and inline
b120d9978144 1.6.0a mig script/converter: fixed inline/drawing conversion, added more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4489
diff changeset
402 return m
3925
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
403
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
404 words = word.split(None, 1)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
405 if len(words) == 1:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
406 words = words * 2
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
407
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
408 target, text = words
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
409 if wikiutil.isPicture(text) and re.match(self.url_rule, text):
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
410 return '[[%s|{{%s}}]]' % (target, text)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
411 else:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
412 if target == text:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
413 return '[[%s]]' % target
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
414 else:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
415 return '[[%s|%s]]' % (target, text)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
416
4630
b0319cfcb1bc 1.6.0a mig script/converter: fixed converter bug for parser sections, added unit tests for pre and parser sections
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4490
diff changeset
417 def _parser_repl(self, word):
b0319cfcb1bc 1.6.0a mig script/converter: fixed converter bug for parser sections, added unit tests for pre and parser sections
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4490
diff changeset
418 self.in_pre = 'no_parser'
b0319cfcb1bc 1.6.0a mig script/converter: fixed converter bug for parser sections, added unit tests for pre and parser sections
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4490
diff changeset
419 return word
b0319cfcb1bc 1.6.0a mig script/converter: fixed converter bug for parser sections, added unit tests for pre and parser sections
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4490
diff changeset
420
3925
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
421 def _pre_repl(self, word):
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
422 w = word.strip()
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
423 if w == '{{{' and not self.in_pre:
4630
b0319cfcb1bc 1.6.0a mig script/converter: fixed converter bug for parser sections, added unit tests for pre and parser sections
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4490
diff changeset
424 self.in_pre = 'no_parser'
3925
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
425 elif w == '}}}' and self.in_pre:
4630
b0319cfcb1bc 1.6.0a mig script/converter: fixed converter bug for parser sections, added unit tests for pre and parser sections
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4490
diff changeset
426 self.in_pre = None
3925
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
427 return word
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
428
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
429 def scan(self, scan_re, line):
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
430 """ Scans one line - append text before match, invoke replace() with match, and add text after match. """
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
431 result = []
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
432 lastpos = 0
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
433
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
434 for match in scan_re.finditer(line):
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
435 # Add text before the match
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
436 if lastpos < match.start():
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
437 result.append(line[lastpos:match.start()])
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
438 # Replace match with markup
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
439 result.append(self.replace(match))
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
440 lastpos = match.end()
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
441
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
442 # Add remainder of the line
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
443 result.append(line[lastpos:])
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
444 return u''.join(result)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
445
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
446
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
447 def replace(self, match):
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
448 """ Replace match using type name """
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
449 result = []
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
450 for _type, hit in match.groupdict().items():
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
451 if hit is not None and not _type in ["hmarker", ]:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
452 # Get replace method and replace hit
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
453 replace = getattr(self, '_' + _type + '_repl')
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
454 # print _type, hit
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
455 result.append(replace(hit))
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
456 return ''.join(result)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
457 else:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
458 # We should never get here
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
459 import pprint
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
460 raise Exception("Can't handle match %r\n%s\n%s" % (
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
461 match,
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
462 pprint.pformat(match.groupdict()),
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
463 pprint.pformat(match.groups()),
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
464 ))
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
465
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
466 return ""
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
467
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
468 def convert(self, request):
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
469 """ For each line, scan through looking for magic
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
470 strings, outputting verbatim any intervening text.
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
471 """
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
472 self.request = request
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
473 # prepare regex patterns
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
474 rules = self.formatting_rules.replace('\n', '|')
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
475 if self.request.cfg.bang_meta:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
476 rules = ur'(?P<notword>!%(word_rule)s)|%(rules)s' % {
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
477 'word_rule': self.word_rule,
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
478 'rules': rules,
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
479 }
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
480 pre_rules = r'''(?P<pre>\}\}\})'''
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
481 pre_scan_re = re.compile(pre_rules, re.UNICODE)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
482 scan_re = re.compile(rules, re.UNICODE)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
483 eol_re = re.compile(r'\r?\n', re.UNICODE)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
484
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
485 rawtext = self.raw
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
486
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
487 # remove last item because it's guaranteed to be empty
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
488 self.lines = eol_re.split(rawtext)[:-1]
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
489 self.in_processing_instructions = True
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
490
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
491 # Main loop
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
492 for line in self.lines:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
493 # ignore processing instructions
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
494 if self.in_processing_instructions:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
495 found = False
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
496 for pi in ("##", "#format", "#refresh", "#redirect", "#deprecated",
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
497 "#pragma", "#form", "#acl", "#language"):
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
498 if line.lower().startswith(pi):
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
499 self.request.write(line + '\r\n')
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
500 found = True
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
501 break
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
502 if not found:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
503 self.in_processing_instructions = False
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
504 else:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
505 continue # do not parse this line
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
506 if not line.strip():
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
507 self.request.write(line + '\r\n')
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
508 else:
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
509 # Scan line, format and write
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
510 scanning_re = self.in_pre and pre_scan_re or scan_re
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
511 formatted_line = self.scan(scanning_re, line)
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
512 self.request.write(formatted_line + '\r\n')
44d856f8a110 add migration support to migrate from early 1.6.0alpha to 1.6.0 release
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
513