Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes
MoinMoin.script.migration._conv160a_wiki.Converter Class Reference
Inheritance diagram for MoinMoin.script.migration._conv160a_wiki.Converter:
Inheritance graph
[legend]
Collaboration diagram for MoinMoin.script.migration._conv160a_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 _parser_repl
def _pre_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 84 of file _conv160a_wiki.py.


Constructor & Destructor Documentation

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

Definition at line 85 of file _conv160a_wiki.py.

00085 
00086     def __init__(self, request, pagename, raw, renames):
00087         self.pagename = pagename
00088         self.raw = raw
00089         self.renames = renames
00090         self.request = request
00091         self._ = None
00092         self.in_pre = 0
00093 
00094         self.formatting_rules = self.formatting_rules % {'macronames': u'|'.join(['ImageLink', ] + macro.getNames(self.request.cfg))}


Member Function Documentation

Handle InterWiki links.

Definition at line 267 of file _conv160a_wiki.py.

00267 
00268     def _interwiki_repl(self, word):
00269         """Handle InterWiki links."""
00270         wikitag, wikiurl, wikitail, wikitag_bad = wikiutil.resolve_wiki(self.request, word)
00271         if wikitag_bad:
00272             return word
00273         else:
00274             return self.interwiki("wiki:" + word)

Here is the call graph for this function:

Definition at line 182 of file _conv160a_wiki.py.

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

Here is the call graph for this function:

Definition at line 417 of file _conv160a_wiki.py.

00417 
00418     def _parser_repl(self, word):
00419         self.in_pre = 'no_parser'
00420         return word

Definition at line 421 of file _conv160a_wiki.py.

00421 
00422     def _pre_repl(self, word):
00423         w = word.strip()
00424         if w == '{{{' and not self.in_pre:
00425             self.in_pre = 'no_parser'
00426         elif w == '}}}' and self.in_pre:
00427             self.in_pre = None
00428         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 131 of file _conv160a_wiki.py.

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

Here is the caller graph for this function:

Definition at line 170 of file _conv160a_wiki.py.

00170 
00171     def _replace_target(self, target):
00172         target_and_anchor = rsplit(target, '#', 1)
00173         if len(target_and_anchor) > 1:
00174             target, anchor = target_and_anchor
00175             target = self._replace(('PAGE', target))
00176             return '%s#%s' % (target, anchor)
00177         else:
00178             target = self._replace(('PAGE', target))
00179             return target

Here is the call graph for this function:

Here is the caller graph for this function:

Handle bracketed URLs.

Definition at line 365 of file _conv160a_wiki.py.

00365 
00366     def _url_bracket_repl(self, word):
00367         """Handle bracketed URLs."""
00368         word = word[1:-1] # strip brackets
00369 
00370         # Local extended link? [:page name:link text] XXX DEPRECATED
00371         if word[0] == ':':
00372             words = word[1:].split(':', 1)
00373             link, text = (words + ['', ''])[:2]
00374             if link.strip() == text.strip():
00375                 text = ''
00376             link = self._replace_target(link)
00377             if text:
00378                 text = '|' + text
00379             return '[[%s%s]]' % (link, text)
00380 
00381         scheme_and_rest = word.split(":", 1)
00382         if len(scheme_and_rest) == 1: # no scheme
00383             # Traditional split on space
00384             words = word.split(None, 1)
00385             if words[0].startswith('#'): # anchor link
00386                 link, text = (words + ['', ''])[:2]
00387                 if link.strip() == text.strip():
00388                     text = ''
00389                 if text:
00390                     text = '|' + text
00391                 return '[[%s%s]]' % (link, text)
00392         else:
00393             scheme = scheme_and_rest[0]
00394             if scheme == "wiki":
00395                 return self.interwiki(word, pretty_url=1)
00396             if scheme in self.attachment_schemas:
00397                 m = self.attachment(word)
00398                 if scheme == 'attachment':
00399                     # with url_bracket markup, 1.6.0a parser does not embed pictures, but link!
00400                     return '[[%s]]' % m[2:-2]
00401                 else:
00402                     # drawing and inline
00403                     return m
00404 
00405             words = word.split(None, 1)
00406             if len(words) == 1:
00407                 words = words * 2
00408 
00409         target, text = words
00410         if wikiutil.isPicture(text) and re.match(self.url_rule, text):
00411             return '[[%s|{{%s}}]]' % (target, text)
00412         else:
00413             if target == text:
00414                 return '[[%s]]' % target
00415             else:
00416                 return '[[%s|%s]]' % (target, text)

Here is the call graph for this function:

Handle literal URLs including inline images.

Definition at line 350 of file _conv160a_wiki.py.

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

Here is the call graph for this function:

Handle special-char wikinames with link text, like:
   ["Jim O'Brian" Jim's home page] or ['Hello "world"!' a page with doublequotes]

Definition at line 245 of file _conv160a_wiki.py.

00245 
00246     def _wikiname_bracket_repl(self, text):
00247         """Handle special-char wikinames with link text, like:
00248            ["Jim O'Brian" Jim's home page] or ['Hello "world"!' a page with doublequotes]
00249         """
00250         word = text[1:-1] # strip brackets
00251         first_char = word[0]
00252         if first_char in QUOTE_CHARS:
00253             # split on closing quote
00254             target, linktext = word[1:].split(first_char, 1)
00255         else: # not quoted
00256             # split on whitespace
00257             target, linktext = word.split(None, 1)
00258         if target:
00259             target = self._replace(('PAGE', target))
00260             linktext = linktext.strip()
00261             if linktext and linktext != target:
00262                 return '[[%s|%s]]' % (target, linktext)
00263             else:
00264                 return '[[%s]]' % target
00265         else:
00266             return text

Here is the call graph for this function:

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

Definition at line 235 of file _conv160a_wiki.py.

00235 
00236     def _word_repl(self, word, text=None):
00237         """Handle WikiNames."""
00238         if not text:
00239             if wikiutil.isStrictWikiname(word):
00240                 return word
00241             else:
00242                 return '[[%s]]' % word
00243         else: # internal use:
00244             return '[[%s|%s]]' % (word, text)

def MoinMoin.script.migration._conv160a_wiki.Converter.attachment (   self,
  target_and_text,
  kw 
)
This gets called on attachment URLs 

Definition at line 317 of file _conv160a_wiki.py.

00317 
00318     def attachment(self, target_and_text, **kw):
00319         """ This gets called on attachment URLs """
00320         _ = self._
00321         scheme, fname, text = wikiutil160a.split_wiki(target_and_text)
00322 
00323         pagename, fname = AttachFile.absoluteName(fname, self.pagename)
00324         from_this_page = pagename == self.pagename
00325         fname = self._replace(('FILE', pagename, fname))
00326         #fname = wikiutil.url_unquote(fname)
00327         #fname = self._replace(('FILE', pagename, fname))
00328         pagename = self._replace(('PAGE', pagename))
00329         if from_this_page:
00330             name = fname
00331         else:
00332             name = "%s/%s" % (pagename, fname)
00333 
00334         fn_txt = name
00335         if text:
00336             fn_txt += '|' + text
00337 
00338         if scheme == 'drawing':
00339             return "{{drawing:%s}}" % fn_txt
00340 
00341         # check for image, and possibly return IMG tag (images are always inlined)
00342         if not kw.get('pretty_url', 0) and wikiutil.isPicture(fname):
00343             return "{{attachment:%s}}" % fn_txt
00344 
00345         # inline the attachment
00346         if scheme == 'inline':
00347             return '{{attachment:%s}}' % fn_txt
00348 
00349         return '[[attachment:%s]]' % fn_txt

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 468 of file _conv160a_wiki.py.

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

Here is the call graph for this function:

def MoinMoin.script.migration._conv160a_wiki.Converter.interwiki (   self,
  target_and_text,
  kw 
)

Definition at line 275 of file _conv160a_wiki.py.

00275 
00276     def interwiki(self, target_and_text, **kw):
00277         scheme, rest = target_and_text.split(':', 1)
00278         wikiname, pagename, text = wikiutil160a.split_wiki(rest)
00279 
00280         #if (pagename.startswith(wikiutil.CHILD_PREFIX) or # fancy link to subpage [wiki:/SubPage text]
00281         #    Page(self.request, pagename).exists()): # fancy link to local page [wiki:LocalPage text]
00282         #    # XXX OtherWiki:FooPage markup -> checks for local FooPage -sense???
00283         #    pagename = wikiutil.url_unquote(pagename)
00284         #    pagename = self._replace_target(pagename)
00285         #    return '[[%s%s]]' % (pagename, text)
00286 
00287         if wikiname in ('Self', self.request.cfg.interwikiname, ''): # [wiki:Self:LocalPage text] or [:LocalPage:text]
00288             orig_pagename = pagename
00289             pagename = wikiutil.url_unquote(pagename)
00290             pagename = self._replace_target(pagename)
00291             camelcase = wikiutil.isStrictWikiname(pagename)
00292             if camelcase and (not text or text == orig_pagename):
00293                 return pagename # optimize special case
00294             else:
00295                 if text:
00296                     text = '|' + text
00297                 return '[[%s%s]]' % (pagename, text)
00298 
00299         wikitag, wikiurl, wikitail, wikitag_bad = wikiutil.resolve_wiki(self.request, wikiname+':')
00300         if wikitag_bad: # likely we got some /InterWiki as wikitail, we don't want that!
00301             pagename = wikiutil.url_unquote(pagename)
00302             pagename = self._replace_target(pagename)
00303             wikitail = pagename
00304         else: # good
00305             wikitail = wikiutil.url_unquote(pagename)
00306 
00307         # link to self?
00308         if wikiutil.isPicture(wikitail):
00309             return '{{%s:%s%s}}' % (wikitag, wikitail, text)
00310         else:
00311             if ' ' not in wikitail and not text:
00312                 return '%s:%s' % (wikitag, wikitail)
00313             else:
00314                 if text:
00315                     text = '|' + text
00316                 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 447 of file _conv160a_wiki.py.

00447 
00448     def replace(self, match):
00449         """ Replace match using type name """
00450         result = []
00451         for _type, hit in match.groupdict().items():
00452             if hit is not None and not _type in ["hmarker", ]:
00453                 # Get replace method and replace hit
00454                 replace = getattr(self, '_' + _type + '_repl')
00455                 # print _type, hit
00456                 result.append(replace(hit))
00457                 return ''.join(result)
00458         else:
00459             # We should never get here
00460             import pprint
00461             raise Exception("Can't handle match %r\n%s\n%s" % (
00462                 match,
00463                 pprint.pformat(match.groupdict()),
00464                 pprint.pformat(match.groups()),
00465             ))
00466 
00467         return ""

Here is the caller graph for this function:

Definition at line 96 of file _conv160a_wiki.py.

00096 
00097     def return_word(self, word):
        return word
def MoinMoin.script.migration._conv160a_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 429 of file _conv160a_wiki.py.

00429 
00430     def scan(self, scan_re, line):
00431         """ Scans one line - append text before match, invoke replace() with match, and add text after match.  """
00432         result = []
00433         lastpos = 0
00434 
00435         for match in scan_re.finditer(line):
00436             # Add text before the match
00437             if lastpos < match.start():
00438                 result.append(line[lastpos:match.start()])
00439             # Replace match with markup
00440             result.append(self.replace(match))
00441             lastpos = match.end()
00442 
00443         # Add remainder of the line
00444         result.append(line[lastpos:])
00445         return u''.join(result)
00446 

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 90 of file _conv160a_wiki.py.

Definition at line 107 of file _conv160a_wiki.py.

Definition at line 127 of file _conv160a_wiki.py.

Definition at line 126 of file _conv160a_wiki.py.

Definition at line 120 of file _conv160a_wiki.py.

Definition at line 101 of file _conv160a_wiki.py.

Definition at line 99 of file _conv160a_wiki.py.

Definition at line 100 of file _conv160a_wiki.py.

Definition at line 98 of file _conv160a_wiki.py.

Definition at line 117 of file _conv160a_wiki.py.

Definition at line 116 of file _conv160a_wiki.py.

Definition at line 118 of file _conv160a_wiki.py.

Definition at line 119 of file _conv160a_wiki.py.

Definition at line 122 of file _conv160a_wiki.py.

Definition at line 123 of file _conv160a_wiki.py.

Definition at line 124 of file _conv160a_wiki.py.

Definition at line 121 of file _conv160a_wiki.py.

Definition at line 125 of file _conv160a_wiki.py.

Definition at line 110 of file _conv160a_wiki.py.

Definition at line 113 of file _conv160a_wiki.py.

Definition at line 106 of file _conv160a_wiki.py.

Definition at line 114 of file _conv160a_wiki.py.

Definition at line 115 of file _conv160a_wiki.py.

Definition at line 103 of file _conv160a_wiki.py.

Definition at line 105 of file _conv160a_wiki.py.

Definition at line 104 of file _conv160a_wiki.py.

Definition at line 111 of file _conv160a_wiki.py.

Definition at line 112 of file _conv160a_wiki.py.

Definition at line 109 of file _conv160a_wiki.py.

Definition at line 108 of file _conv160a_wiki.py.

Definition at line 102 of file _conv160a_wiki.py.

Definition at line 93 of file _conv160a_wiki.py.

Definition at line 91 of file _conv160a_wiki.py.

Definition at line 489 of file _conv160a_wiki.py.

Definition at line 488 of file _conv160a_wiki.py.

Definition at line 86 of file _conv160a_wiki.py.

Definition at line 87 of file _conv160a_wiki.py.

Definition at line 88 of file _conv160a_wiki.py.

Definition at line 89 of file _conv160a_wiki.py.


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