annotate MoinMoin/script/migration/_conv160a_wiki.py @ 5067:10965bc1ee3c

don't overwrite i18n.wikiLanguages in tests
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Tue, 18 Aug 2009 18:03:36 +0200
parents 83483f4e26cb
children 6cdf52df1219
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
44d856f8a110 add migration 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 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
21 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
22 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
23 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
24
44d856f8a110 add migration 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 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
26 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
27
44d856f8a110 add migration 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 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
29
44d856f8a110 add migration 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 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
31 """ 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
32 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
33 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
34 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
35 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
36 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
37 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
38 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
39 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
40 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
41
44d856f8a110 add migration 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 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
44
44d856f8a110 add migration 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 # 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
46 # ... 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
47 # 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
48 # 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
49 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
50 """ 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
51 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
52 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
53 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
54 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
55 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
56
44d856f8a110 add migration 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 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
58 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
59 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
60
44d856f8a110 add migration 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 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
62
44d856f8a110 add migration 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 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
64 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
65 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
66 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
67 # 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
68 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
69 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
70 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
71 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
72 # 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
73 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
74 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
75 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
76
44d856f8a110 add migration 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 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
78 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
79
44d856f8a110 add migration 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 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
81
44d856f8a110 add migration 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 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
84 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
85 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
86 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
87 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
88 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
89 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
90 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
91
44d856f8a110 add migration 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 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
93
44d856f8a110 add migration 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 # 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
95 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
96 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
97 _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
98 _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
99 _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
100 _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
101 _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
102 _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
103 _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
104 _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
105 _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
106 _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
107 _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
108 _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
109 _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
110 _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
111 _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
112 _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
113 _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
114 _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
115 _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
116 _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
117 _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
118 _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
119 _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
120 _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
121 _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
122 _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
123 _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
124 _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
125 _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
126 _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
127
44d856f8a110 add migration 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 # 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
129
44d856f8a110 add migration 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 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
131 """ 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
132 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
133 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
134 """
44d856f8a110 add migration 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 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
136 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
137 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
138 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
139 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
140 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
141 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
142 # 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
143 # 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
144 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
145 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
146 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
147 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
148 # 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
149 # 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
150 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
151 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
152 # 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
153 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
154 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
155 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
156 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
157 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
158 # 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
159 # 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
160 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
161 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
162 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
163 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
164 # 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
165 # 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
166 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
167 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
168
44d856f8a110 add migration 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 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
170 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
171 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
172 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
173 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
174 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
175 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
176 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
177 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
178
44d856f8a110 add migration 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 # 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
180
44d856f8a110 add migration 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 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
182 # 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
183 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
184 \[\[
44d856f8a110 add migration 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 (?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
186 (\((?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
187 \]\]
44d856f8a110 add migration 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 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
190 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
191 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
192 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
193 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
194 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
195 #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
196 #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
197 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
198 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
199 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
200 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
201 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
202 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
203 # 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
204 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
205 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
206 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
207 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
208 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
209 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
210 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
211 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
212 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
213 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
214 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
215 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
216 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
217 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
218 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
219 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
220 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
221 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
222 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
223 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
224 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
225 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
226 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
227 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
228 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
229 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
230 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
231 # 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
232 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
233
44d856f8a110 add migration 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 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
235 """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
236 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
237 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
238 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
239 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
240 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
241 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
242 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
243
44d856f8a110 add migration 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 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
245 """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
246 ["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
247 """
44d856f8a110 add migration 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 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
249 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
250 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
251 # 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
252 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
253 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
254 # 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
255 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
256 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
257 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
258 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
259 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
260 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
261 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
262 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
263 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
264 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
265
44d856f8a110 add migration 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 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
267 """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
268 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
269 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
270 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
271 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
272 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
273
44d856f8a110 add migration 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 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
275 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
276 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
277
4489
a835ada897e0 1.6.0a mig script/converter: fix interwiki tests, cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4488
diff changeset
278 #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
279 # 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
280 # # 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
281 # 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
282 # 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
283 # 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
284
44d856f8a110 add migration 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 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
286 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
287 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
288 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
289 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
290 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
291 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
292 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
293 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
294 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
295 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
296
44d856f8a110 add migration 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 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
298 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
299 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
300 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
301 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
302 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
303 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
304
44d856f8a110 add migration 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 # 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
306 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
307 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
308 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
309 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
310 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
311 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
312 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
313 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
314 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
315
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
316 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
317 """ 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
318 _ = 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
319 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
320
44d856f8a110 add migration 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 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
322 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
323 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
324 #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
325 #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
326 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
327 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
328 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
329 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
330 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
331
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
332 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
333 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
334 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
335
44d856f8a110 add migration 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 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
337 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
338
44d856f8a110 add migration 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 # 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
340 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
341 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
342
44d856f8a110 add migration 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 # 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
344 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
345 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
346
44d856f8a110 add migration 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 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
348
44d856f8a110 add migration 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 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
350 """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
351 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
352
44d856f8a110 add migration 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 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
354 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
355 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
356 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
357
44d856f8a110 add migration 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 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
359 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
360 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
361 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
362
44d856f8a110 add migration 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 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
365 """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
366 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
367
44d856f8a110 add migration 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 # 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
369 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
370 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
371 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
372 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
373 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
374 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
375 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
376 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
377 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
378
44d856f8a110 add migration 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 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
380 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
381 # 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
382 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
383 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
384 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
385 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
386 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
387 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
388 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
389 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
390 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
391 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
392 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
393 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
394 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
395 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
396 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
397 # 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
398 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
399 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
400 # 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
401 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
402
44d856f8a110 add migration 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 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
404 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
405 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
406
44d856f8a110 add migration 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 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
408 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
409 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
410 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
411 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
412 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
413 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
414 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
415
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
416 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
417 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
418 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
419
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
420 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
421 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
422 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
423 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
424 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
425 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
426 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
427
44d856f8a110 add migration 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 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
429 """ 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
430 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
431 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
432
44d856f8a110 add migration 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 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
434 # 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
435 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
436 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
437 # 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
438 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
439 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
440
44d856f8a110 add migration 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 # 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
442 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
443 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
444
44d856f8a110 add migration 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 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
447 """ 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
448 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
449 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
450 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
451 # 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
452 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
453 # 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
454 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
455 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
456 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
457 # 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
458 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
459 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
460 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
461 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
462 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
463 ))
44d856f8a110 add migration 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 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
466
44d856f8a110 add migration 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 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
468 """ 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
469 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
470 """
44d856f8a110 add migration 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 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
472 # 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
473 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
474 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
475 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
476 '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
477 '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
478 }
44d856f8a110 add migration 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 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
480 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
481 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
482 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
483
44d856f8a110 add migration 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 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
485
44d856f8a110 add migration 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 # 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
487 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
488 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
489
44d856f8a110 add migration 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 # 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
491 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
492 # 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
493 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
494 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
495 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
496 "#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
497 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
498 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
499 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
500 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
501 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
502 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
503 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
504 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
505 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
506 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
507 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
508 # 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
509 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
510 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
511 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
512