Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes
MoinMoin.script.migration._conv160_wiki.Converter Class Reference
Inheritance diagram for MoinMoin.script.migration._conv160_wiki.Converter:
Inheritance graph
[legend]
Collaboration diagram for MoinMoin.script.migration._conv160_wiki.Converter:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def return_word
def interwiki
def attachment
def scan
def replace
def convert

Public Attributes

 pagename
 raw
 renames
 request
 in_pre
 formatting_rules
 lines
 in_processing_instructions

Private Member Functions

def _replace
def _replace_target
def _macro_repl
def _word_repl
def _wikiname_bracket_repl
def _interwiki_repl
def _url_repl
def _url_bracket_repl
def _pre_repl
def _processor_repl

Private Attributes

 _

Static Private Attributes

 _emph_repl = return_word
 _emph_ibb_repl = return_word
 _emph_ibi_repl = return_word
 _emph_ib_or_bi_repl = return_word
 _u_repl = return_word
 _strike_repl = return_word
 _sup_repl = return_word
 _sub_repl = return_word
 _small_repl = return_word
 _big_repl = return_word
 _tt_repl = return_word
 _tt_bt_repl = return_word
 _remark_repl = return_word
 _table_repl = return_word
 _tableZ_repl = return_word
 _rule_repl = return_word
 _smiley_repl = return_word
 _smileyA_repl = return_word
 _ent_repl = return_word
 _ent_numeric_repl = return_word
 _ent_symbolic_repl = return_word
 _heading_repl = return_word
 _email_repl = return_word
 _notword_repl = return_word
 _indent_repl = return_word
 _li_none_repl = return_word
 _li_repl = return_word
 _ol_repl = return_word
 _dl_repl = return_word
 _comment_repl = return_word

Detailed Description

Definition at line 93 of file _conv160_wiki.py.


Constructor & Destructor Documentation

def MoinMoin.script.migration._conv160_wiki.Converter.__init__ (   self,
  request,
  pagename,
  raw,
  renames 
)

Definition at line 94 of file _conv160_wiki.py.

00094 
00095     def __init__(self, request, pagename, raw, renames):
00096         self.pagename = pagename
00097         self.raw = raw
00098         self.renames = renames
00099         self.request = request
00100         self._ = None
00101         self.in_pre = 0
00102 
00103         self.formatting_rules = self.formatting_rules % {'macronames': u'|'.join(['ImageLink', ] + macro.getNames(self.request.cfg))}


Member Function Documentation

Handle InterWiki links.

Definition at line 260 of file _conv160_wiki.py.

00260 
00261     def _interwiki_repl(self, word):
00262         """Handle InterWiki links."""
00263         wikitag, wikiurl, wikitail, wikitag_bad = wikiutil.resolve_wiki(self.request, word)
00264         if wikitag_bad:
00265             return word
00266         else:
00267             wikiname, pagename = word.split(':', 1)
00268             pagename = wikiutil.url_unquote(pagename) # maybe someone has used %20 for blanks in pagename
00269             camelcase = wikiutil.isStrictWikiname(pagename)
00270             if wikiname in ('Self', self.request.cfg.interwikiname):
00271                 pagename = self._replace(('PAGE', pagename))
00272                 if camelcase:
00273                     return '%s' % pagename # optimize special case
00274                 else:
00275                     return '[[%s]]' % pagename # optimize special case
00276             else:
00277                 if ' ' in pagename: # we could get a ' '  by urlunquoting
00278                     return '[[%s:%s]]' % (wikiname, pagename)
00279                 else:
00280                     return '%s:%s' % (wikiname, pagename)

Here is the call graph for this function:

Definition at line 191 of file _conv160_wiki.py.

00191 
00192     def _macro_repl(self, word):
00193         # we use [[...]] for links now, macros will be <<...>>
00194         macro_rule = ur"""
00195             \[\[
00196             (?P<macro_name>\w+)
00197             (\((?P<macro_args>.*?)\))?
00198             \]\]
00199         """
00200         word = unicode(word) # XXX why is word not unicode before???
00201         m = re.match(macro_rule, word, re.X|re.U)
00202         macro_name = m.group('macro_name')
00203         macro_args = m.group('macro_args')
00204         if macro_name == 'ImageLink':
00205             fixed, kw = explore_args(macro_args)
00206             #print "macro_args=%r" % macro_args
00207             #print "fixed=%r, kw=%r" % (fixed, kw)
00208             image, target = (fixed + ['', ''])[:2]
00209             if image is None:
00210                 image = ''
00211             if target is None:
00212                 target = ''
00213             if '://' not in image:
00214                 # if it is not a URL, it is meant as attachment
00215                 image = u'attachment:%s' % image
00216             if not target:
00217                 target = image
00218             elif target.startswith('inline:'):
00219                 target = 'attachment:' + target[7:] # we don't support inline:
00220             elif target.startswith('wiki:'):
00221                 target = target[5:] # drop wiki:
00222             image_attrs = []
00223             alt = kw.get('alt') or ''
00224             width = kw.get('width')
00225             if width is not None:
00226                 image_attrs.append(u"width=%s" % width)
00227             height = kw.get('height')
00228             if height is not None:
00229                 image_attrs.append(u"height=%s" % height)
00230             image_attrs = u", ".join(image_attrs)
00231             if image_attrs:
00232                 image_attrs = u'|' + image_attrs
00233             if alt or image_attrs:
00234                 alt = u'|' + alt
00235             result = u'[[%s|{{%s%s%s}}]]' % (target, image, alt, image_attrs)
00236         else:
00237             if macro_args:
00238                 macro_args = u"(%s)" % macro_args
00239             else:
00240                 macro_args = u''
00241             result = u"<<%s%s>>" % (macro_name, macro_args)
00242         # XXX later check whether some to be renamed pagename is used as macro param
00243         return result

Here is the call graph for this function:

Definition at line 427 of file _conv160_wiki.py.

00427 
00428     def _pre_repl(self, word):
00429         w = word.strip()
00430         if w == '{{{' and not self.in_pre:
00431             self.in_pre = True
00432         elif w == '}}}' and self.in_pre:
00433             self.in_pre = False
00434         return word

Definition at line 435 of file _conv160_wiki.py.

00435 
00436     def _processor_repl(self, word):
00437         self.in_pre = True
00438         return word

replace a item_name if it is in the renames dict
    key is either a 2-tuple ('PAGE', pagename)
    or a 3-tuple ('FILE', pagename, filename)

Definition at line 140 of file _conv160_wiki.py.

00140 
00141     def _replace(self, key):
00142         """ replace a item_name if it is in the renames dict
00143             key is either a 2-tuple ('PAGE', pagename)
00144             or a 3-tuple ('FILE', pagename, filename)
00145         """
00146         current_page = self.pagename
00147         item_type, page_name, file_name = (key + (None, ))[:3]
00148         abs_page_name = wikiutil.AbsPageName(current_page, page_name)
00149         if item_type == 'PAGE':
00150             key = (item_type, abs_page_name)
00151             new_name = self.renames.get(key)
00152             if new_name is None:
00153                 # we don't have an entry in rename map - apply the same magic
00154                 # to the page name as 1.5 did (" " -> "_") and try again:
00155                 abs_magic_name = abs_page_name.replace(u' ', u'_')
00156                 key = (item_type, abs_magic_name)
00157                 new_name = self.renames.get(key)
00158                 if new_name is None:
00159                     # we didn't find it under the magic name either -
00160                     # that means we do not rename it!
00161                     new_name = page_name
00162             if new_name != page_name and abs_page_name != page_name:
00163                 # we have to fix the (absolute) new_name to be a relative name (as it was before)
00164                 new_name = wikiutil.RelPageName(current_page, new_name)
00165         elif item_type == 'FILE':
00166             key = (item_type, abs_page_name, file_name)
00167             new_name = self.renames.get(key)
00168             if new_name is None:
00169                 # we don't have an entry in rename map - apply the same magic
00170                 # to the page name as 1.5 did (" " -> "_") and try again:
00171                 abs_magic_name = abs_page_name.replace(u' ', u'_')
00172                 key = (item_type, abs_magic_name, file_name)
00173                 new_name = self.renames.get(key)
00174                 if new_name is None:
00175                     # we didn't find it under the magic name either -
00176                     # that means we do not rename it!
00177                     new_name = file_name
00178         return new_name

Here is the caller graph for this function:

Definition at line 179 of file _conv160_wiki.py.

00179 
00180     def _replace_target(self, target):
00181         target_and_anchor = rsplit(target, '#', 1)
00182         if len(target_and_anchor) > 1:
00183             target, anchor = target_and_anchor
00184             target = self._replace(('PAGE', target))
00185             return '%s#%s' % (target, anchor)
00186         else:
00187             target = self._replace(('PAGE', target))
00188             return target

Here is the call graph for this function:

Here is the caller graph for this function:

Handle bracketed URLs.

Definition at line 371 of file _conv160_wiki.py.

00371 
00372     def _url_bracket_repl(self, word):
00373         """Handle bracketed URLs."""
00374         word = word[1:-1] # strip brackets
00375 
00376         # Local extended link?
00377         if word[0] == ':':
00378             words = word[1:].split(':', 1)
00379             link, text = (words + ['', ''])[:2]
00380             if link.strip() == text.strip():
00381                 text = ''
00382             link = self._replace_target(link)
00383             if text:
00384                 text = '|' + text
00385             return '[[%s%s]]' % (link, text)
00386 
00387         # Traditional split on space
00388         words = word.split(None, 1)
00389         if words[0][0] == '#':
00390             # anchor link
00391             link, text = (words + ['', ''])[:2]
00392             if link.strip() == text.strip():
00393                 text = ''
00394             #link = self._replace_target(link)
00395             if text:
00396                 text = '|' + text
00397             return '[[%s%s]]' % (link, text)
00398 
00399         scheme = words[0].split(":", 1)[0]
00400         if scheme == "wiki":
00401             return self.interwiki(words)
00402             #scheme, wikiname, pagename, text = self.interwiki(word)
00403             #print "%r %r %r %r" % (scheme, wikiname, pagename, text)
00404             #if wikiname in ('Self', self.request.cfg.interwikiname, ''):
00405             #    if text:
00406             #        text = '|' + text
00407             #    return '[[%s%s]]' % (pagename, text)
00408             #else:
00409             #    if text:
00410             #        text = '|' + text
00411             #    return "[[%s:%s%s]]" % (wikiname, pagename, text)
00412         if scheme in self.attachment_schemas:
00413             m = self.attachment(words)
00414             if m.startswith('{{') and m.endswith('}}'):
00415                 # with url_bracket markup, 1.5.8 parser does not embed, but link!
00416                 m = '[[%s]]' % m[2:-2]
00417             return m
00418 
00419         target, desc = (words + ['', ''])[:2]
00420         if wikiutil.isPicture(desc) and re.match(self.url_rule, desc):
00421             #return '[[%s|{{%s|%s}}]]' % (words[0], words[1], words[0])
00422             return '[[%s|{{%s}}]]' % (target, desc)
00423         else:
00424             if desc:
00425                 desc = '|' + desc
00426             return '[[%s%s]]' % (target, desc)

Here is the call graph for this function:

Handle literal URLs including inline images.

Definition at line 357 of file _conv160_wiki.py.

00357 
00358     def _url_repl(self, word):
00359         """Handle literal URLs including inline images."""
00360         scheme = word.split(":", 1)[0]
00361 
00362         if scheme == 'wiki':
00363             return self.interwiki([word])
00364         if scheme in self.attachment_schemas:
00365             return '%s' % self.attachment([word])
00366 
00367         if wikiutil.isPicture(word): # magic will go away in 1.6!
00368             return '{{%s}}' % word # new markup for inline images
00369         else:
00370             return word

Here is the call graph for this function:

Handle special-char wikinames.

Definition at line 251 of file _conv160_wiki.py.

00251 
00252     def _wikiname_bracket_repl(self, word):
00253         """Handle special-char wikinames."""
00254         pagename = word[2:-2]
00255         if pagename:
00256             pagename = self._replace(('PAGE', pagename))
00257             return '[[%s]]' % pagename
00258         else:
00259             return word

Here is the call graph for this function:

def MoinMoin.script.migration._conv160_wiki.Converter._word_repl (   self,
  word,
  text = None 
) [private]
Handle WikiNames.

Definition at line 244 of file _conv160_wiki.py.

00244 
00245     def _word_repl(self, word, text=None):
00246         """Handle WikiNames."""
00247         if not text:
00248             return word
00249         else: # internal use:
00250             return '[[%s|%s]]' % (word, text)

This gets called on attachment URLs. 

Definition at line 320 of file _conv160_wiki.py.

00320 
00321     def attachment(self, url_and_text):
00322         """ This gets called on attachment URLs. """
00323         if len(url_and_text) == 1:
00324             url = url_and_text[0]
00325             text = ''
00326         else:
00327             url, text = url_and_text
00328             text = '|' + text
00329 
00330         scheme, fname = url.split(":", 1)
00331         #scheme, fname, text = wikiutil.split_wiki(target_and_text)
00332 
00333         pagename, fname = AttachFile.absoluteName(fname, self.pagename)
00334         from_this_page = pagename == self.pagename
00335         fname = self._replace(('FILE', pagename, fname))
00336         fname = wikiutil.url_unquote(fname)
00337         fname = self._replace(('FILE', pagename, fname))
00338         pagename = self._replace(('PAGE', pagename))
00339         if from_this_page:
00340             name = fname
00341         else:
00342             name = "%s/%s" % (pagename, fname)
00343 
00344         if scheme == 'drawing':
00345             return "{{drawing:%s%s}}" % (name, text)
00346 
00347         # check for image URL, and possibly return IMG tag
00348         # (images are always inlined, just like for other URLs)
00349         if wikiutil.isPicture(name):
00350             return "{{attachment:%s%s}}" % (name, text)
00351 
00352         # inline the attachment
00353         if scheme == 'inline':
00354             return '{{attachment:%s%s}}' % (name, text)
00355         else: # 'attachment'
00356             return '[[attachment:%s%s]]' % (name, text)

Here is the call graph for this function:

Here is the caller graph for this function:

For each line, scan through looking for magic
    strings, outputting verbatim any intervening text.

Definition at line 478 of file _conv160_wiki.py.

00478 
00479     def convert(self, request):
00480         """ For each line, scan through looking for magic
00481             strings, outputting verbatim any intervening text.
00482         """
00483         self.request = request
00484         # prepare regex patterns
00485         rules = self.formatting_rules.replace('\n', '|')
00486         if self.request.cfg.bang_meta:
00487             rules = ur'(?P<notword>!%(word_rule)s)|%(rules)s' % {
00488                 'word_rule': self.word_rule,
00489                 'rules': rules,
00490             }
00491         pre_rules = r'''(?P<pre>\}\}\})'''
00492         pre_scan_re = re.compile(pre_rules, re.UNICODE)
00493         scan_re = re.compile(rules, re.UNICODE)
00494         eol_re = re.compile(r'\r?\n', re.UNICODE)
00495 
00496         rawtext = self.raw
00497 
00498         # remove last item because it's guaranteed to be empty
00499         self.lines = eol_re.split(rawtext)[:-1]
00500         self.in_processing_instructions = True
00501 
00502         # Main loop
00503         for line in self.lines:
00504             # ignore processing instructions
00505             if self.in_processing_instructions:
00506                 found = False
00507                 for pi in ("##", "#format", "#refresh", "#redirect", "#deprecated",
00508                            "#pragma", "#form", "#acl", "#language"):
00509                     if line.lower().startswith(pi):
00510                         self.request.write(line + '\r\n')
00511                         found = True
00512                         break
00513                 if not found:
00514                     self.in_processing_instructions = False
00515                 else:
00516                     continue # do not parse this line
00517             if not line.strip():
00518                 self.request.write(line + '\r\n')
00519             else:
00520                 # Scan line, format and write
00521                 scanning_re = self.in_pre and pre_scan_re or scan_re
00522                 formatted_line = self.scan(scanning_re, line)
00523                 self.request.write(formatted_line + '\r\n')
00524 

Here is the call graph for this function:

Definition at line 281 of file _conv160_wiki.py.

00281 
00282     def interwiki(self, url_and_text):
00283         if len(url_and_text) == 1:
00284             url = url_and_text[0]
00285             text = ''
00286         else:
00287             url, text = url_and_text
00288             text = '|' + text
00289 
00290         # keep track of whether this is a self-reference, so links
00291         # are always shown even the page doesn't exist.
00292         scheme, url = url.split(':', 1)
00293         wikiname, pagename = wikiutil.split_wiki(url)
00294         if (url.startswith(wikiutil.CHILD_PREFIX) or # fancy link to subpage [wiki:/SubPage text]
00295             Page(self.request, url).exists()): # fancy link to local page [wiki:LocalPage text]
00296             pagename = wikiutil.url_unquote(url)
00297             pagename = self._replace_target(pagename)
00298             return '[[%s%s]]' % (pagename, text)
00299         if wikiname in ('Self', self.request.cfg.interwikiname, ''): # [wiki:Self:LocalPage text] or [:LocalPage:text]
00300             pagename = wikiutil.url_unquote(pagename)
00301             pagename = self._replace_target(pagename)
00302             return '[[%s%s]]' % (pagename, text)
00303 
00304         wikitag, wikiurl, wikitail, wikitag_bad = wikiutil.resolve_wiki(self.request, url)
00305         if wikitag_bad: # likely we got some /InterWiki as wikitail, we don't want that!
00306             pagename = wikiutil.url_unquote(pagename)
00307             pagename = self._replace_target(pagename)
00308             wikitail = pagename
00309         else: # good
00310             wikitail = wikiutil.url_unquote(wikitail)
00311 
00312         # link to self?
00313         if wikiutil.isPicture(wikitail):
00314             return '{{%s:%s%s}}' % (wikitag, wikitail, text)
00315         else:
00316             if ' ' not in wikitail and not text:
00317                 return '%s:%s' % (wikitag, wikitail)
00318             else:
00319                 return '[[%s:%s%s]]' % (wikitag, wikitail, text)

Here is the call graph for this function:

Here is the caller graph for this function:

Replace match using type name 

Definition at line 457 of file _conv160_wiki.py.

00457 
00458     def replace(self, match):
00459         """ Replace match using type name """
00460         result = []
00461         for _type, hit in match.groupdict().items():
00462             if hit is not None and not _type in ["hmarker", ]:
00463                 # Get replace method and replace hit
00464                 replace = getattr(self, '_' + _type + '_repl')
00465                 # print _type, hit
00466                 result.append(replace(hit))
00467                 return ''.join(result)
00468         else:
00469             # We should never get here
00470             import pprint
00471             raise Exception("Can't handle match %r\n%s\n%s" % (
00472                 match,
00473                 pprint.pformat(match.groupdict()),
00474                 pprint.pformat(match.groups()),
00475             ))
00476 
00477         return ""

Here is the caller graph for this function:

Definition at line 105 of file _conv160_wiki.py.

00105 
00106     def return_word(self, word):
        return word
def MoinMoin.script.migration._conv160_wiki.Converter.scan (   self,
  scan_re,
  line 
)
Scans one line - append text before match, invoke replace() with match, and add text after match.  

Definition at line 439 of file _conv160_wiki.py.

00439 
00440     def scan(self, scan_re, line):
00441         """ Scans one line - append text before match, invoke replace() with match, and add text after match.  """
00442         result = []
00443         lastpos = 0
00444 
00445         for match in scan_re.finditer(line):
00446             # Add text before the match
00447             if lastpos < match.start():
00448                 result.append(line[lastpos:match.start()])
00449             # Replace match with markup
00450             result.append(self.replace(match))
00451             lastpos = match.end()
00452 
00453         # Add remainder of the line
00454         result.append(line[lastpos:])
00455         return u''.join(result)
00456 

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 99 of file _conv160_wiki.py.

Definition at line 116 of file _conv160_wiki.py.

Definition at line 136 of file _conv160_wiki.py.

Definition at line 135 of file _conv160_wiki.py.

Definition at line 129 of file _conv160_wiki.py.

Definition at line 110 of file _conv160_wiki.py.

Definition at line 108 of file _conv160_wiki.py.

Definition at line 109 of file _conv160_wiki.py.

Definition at line 107 of file _conv160_wiki.py.

Definition at line 126 of file _conv160_wiki.py.

Definition at line 125 of file _conv160_wiki.py.

Definition at line 127 of file _conv160_wiki.py.

Definition at line 128 of file _conv160_wiki.py.

Definition at line 131 of file _conv160_wiki.py.

Definition at line 132 of file _conv160_wiki.py.

Definition at line 133 of file _conv160_wiki.py.

Definition at line 130 of file _conv160_wiki.py.

Definition at line 134 of file _conv160_wiki.py.

Definition at line 119 of file _conv160_wiki.py.

Definition at line 122 of file _conv160_wiki.py.

Definition at line 115 of file _conv160_wiki.py.

Definition at line 123 of file _conv160_wiki.py.

Definition at line 124 of file _conv160_wiki.py.

Definition at line 112 of file _conv160_wiki.py.

Definition at line 114 of file _conv160_wiki.py.

Definition at line 113 of file _conv160_wiki.py.

Definition at line 120 of file _conv160_wiki.py.

Definition at line 121 of file _conv160_wiki.py.

Definition at line 118 of file _conv160_wiki.py.

Definition at line 117 of file _conv160_wiki.py.

Definition at line 111 of file _conv160_wiki.py.

Definition at line 102 of file _conv160_wiki.py.

Definition at line 100 of file _conv160_wiki.py.

Definition at line 499 of file _conv160_wiki.py.

Definition at line 498 of file _conv160_wiki.py.

Definition at line 95 of file _conv160_wiki.py.

Definition at line 96 of file _conv160_wiki.py.

Definition at line 97 of file _conv160_wiki.py.

Definition at line 98 of file _conv160_wiki.py.


The documentation for this class was generated from the following file: