From: Bernie Innocenti Date: Sat, 11 Apr 2009 15:49:23 +0000 (+0200) Subject: Merge branch 'master' of ssh://bernie@trinity.codewiz.org/~/public_html/wiki/git... X-Git-Tag: v4.0~15 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=3f737b8a960486cd16aaa4acacc83acb24c7d42f;p=geekigeeki.git Merge branch 'master' of ssh://bernie@trinity.codewiz.org/~/public_html/wiki/git/geekigeeki into python3 Conflicts: geekigeeki.py --- 3f737b8a960486cd16aaa4acacc83acb24c7d42f diff --cc geekigeeki.py index 6e1ba6e,f6ba26c..d208bb7 --- a/geekigeeki.py +++ b/geekigeeki.py @@@ -79,35 -89,15 +89,14 @@@ def emit_header(mime_type="text/html") def send_guru(msg_text, msg_type): if not msg_text: return - print '
'
 +    print('
')
      if msg_type == 'error':
 -        print '    Software Failure.  Press left mouse button to continue.\n'
 -    print msg_text
 +        print('    Software Failure.  Press left mouse button to continue.\n')
 +    print(msg_text)
      if msg_type == 'error':
-         print('\n      Guru Meditation #DEADBEEF.ABADC0DE')
-     print('
') - # FIXME: This little JS snippet is harder to pass than ACID 3.0 - print(""" - """) + print '\n Guru Meditation #DEADBEEF.ABADC0DE' - print '
' - print '' \ - % relative_url('sys/GuruMeditation.js') ++ print('' \ ++ % relative_url('sys/GuruMeditation.js')) def send_title(name, text="Limbo", msg_text=None, msg_type='error', writable=False): global title_done @@@ -152,37 -142,37 +141,37 @@@ send_guru(msg_text, msg_type) # Navbar - print '') def send_httperror(status="403 Not Found", query=""): - print "Status: %s" % status + print("Status: %s" % status) send_title(None, msg_text=("%s: on query '%s'" % (status, query))) send_footer() @@@ -218,13 -230,13 +229,13 @@@ def handle_fullsearch(needle) hits.sort() hits.reverse() - print "") print_search_stats(len(hits), len(all_pages)) @@@ -234,12 -246,12 +245,12 @@@ def handle_titlesearch(needle) needle_re = re.compile(needle, re.IGNORECASE) all_pages = page_list() - hits = filter(needle_re.search, all_pages) + hits = list(filter(needle_re.search, all_pages)) - print "") print_search_stats(len(hits), len(all_pages)) @@@ -275,9 -287,10 +286,10 @@@ def handle_edit(pagename) text = form['savetext'].value pg.send_editor(text) + # Used by macros/WordIndex and macros/TitleIndex def make_index_key(): - links = map(lambda ch: '%s' % (ch, ch), 'abcdefghijklmnopqrstuvwxyz') - return '

'+ ' | '.join(links) + '

' + links = ['%s' % (ch, ch) for ch in 'abcdefghijklmnopqrstuvwxyz'] - return '

'+ ' | '.join(links) + '

' ++ return '

' + ' | '.join(links) + '

' def page_list(dirname = None, re = word_re): return sorted(filter(re.match, os.listdir(dirname or data_dir))) @@@ -287,16 -300,16 +299,16 @@@ def send_footer(mod_string=None) cgi.print_arguments() cgi.print_form(form) cgi.print_environ() - print ''' + print(''' ' + print('

last modified %s

' % mod_string) + print('') class WikiFormatter: """Object that turns Wiki markup into HTML. @@@ -497,54 -507,54 +506,53 @@@ raise "Can't handle match " + repr(match) def print_html(self): - print '

' + print('

') - # For each line, we scan through looking for magic - # strings, outputting verbatim any intervening text - # TODO: highlight search words (look at referrer) - scan_re = re.compile( - r"(?:" - # Formatting - + r"(?P\*\*|'''|//|''|##|``|__|\^\^|,,)" - + r"|(?P\={2,6})" - + r"|(?P
\\\\)" - + r"|(?P^-{3,})" - + r"|(?P\b(FIXME|TODO|DONE)\b)" + scan_re = re.compile(r"""(?: + # Styles and formatting + (?P \*\*|'''|//|''|\#\#|``|__|\^\^|,,) + | (?P \={2,6}) + | (?P
\\\\) + | (?P ^-{3,}) + | (?P \b( FIXME | TODO | DONE )\b ) # Links - + r"|(?P\<\<([^\s\|\>]+)(?:\s*\|\s*([^\>]+)|)\>\>)" - + r"|(?P\[\[([^\s\|]+)(?:\s*\|\s*([^\]]+)|)\]\])" + | (?P \<\<([^\s\|\>]+)(?:\s*\|\s*([^\>]+)|)\>\>) + | (?P \[\[([^\s\|]+)(?:\s*\|\s*([^\]]+)|)\]\]) # Inline HTML - + r"|(?P<(/|)(br|hr|div|span|form|iframe|input|textarea|a|img|h[1-5])[^>]*>)" - + r"|(?P[<>&])" + | (?P <(br|hr|div|span|form|iframe|input|textarea|a|img|h[1-5])\b ) + | (?P ( /\s*> | ) ) + | (?P [<>&] ) # Auto links (LEGACY) - + r"|(?P\b[a-zA-Z0-9_/-]+\.(png|gif|jpg|jpeg|bmp|ico))" - + r"|(?P\b(?:[A-Z][a-z]+){2,}\b)" - + r"|(?P(http|https|ftp|mailto)\:[^\s'\"]+\S)" - + r"|(?P[-\w._+]+\@[\w.-]+)" + | (?P \b[a-zA-Z0-9_/-]+\.(png|gif|jpg|jpeg|bmp|ico|ogm|ogg|mkv|mpg|mpeg|mp4|avi|asf|flv|wmv|qt)) + | (?P \b(?:[A-Z][a-z]+){2,}\b) + | (?P (http|https|ftp|mailto)\:[^\s'\"]+\S) + | (?P [-\w._+]+\@[\w.-]+) # Lists, divs, spans - + r"|(?P

  • ^\s+[\*#] +)" - + r"|(?P
    \{\{\{|\s*\}\}\})"
    -             + r"|(?P\{\{([^\s\|]+)(?:\s*\|\s*([^\]]+)|)\}\})"
    +             | (?P
  • ^\s+[\*\#]\s+) + | (?P
       \{\{\{|\s*\}\}\})
    +             | (?P   \{\{([^\s\|]+)(?:\s*\|\s*([^\]]+)|)\}\})
      
                  # Tables
    -             + r"|(?P^\s*\|\|(=|)\s*)"
    -             + r"|(?P\s*\|\|(=|)\s*$)"
    -             + r"|(?P\s*\|\|(=|)\s*)"
    -             + r")")
    -         pre_re = re.compile(
    -             r"(?:"
    -             + r"(?P
    \s*\}\}\})"
    -             + r"|(?P[<>&])"
    -             + r")")
    +             | (?P    ^\s*\|\|(=|)\s*)
    +             | (?P   \s*\|\|(=|)\s*$)
    +             | (?P    \s*\|\|(=|)\s*)
    + 
    +             # TODO: highlight search words (look at referrer)
    +           )""", re.VERBOSE)
    +         pre_re = re.compile("""(?:
    +               (?P
    \s*\}\}\})
    +             | (?P[<>&])"
    +             )""", re.VERBOSE)
              blank_re = re.compile(r"^\s*$")
              indent_re = re.compile(r"^\s*")
              tr_re = re.compile(r"^\s*\|\|")
              eol_re = re.compile(r"\r?\n")
     -
    +         # For each line, we scan through looking for magic strings, outputting verbatim any intervening text
     -        for self.line in eol_re.split(self.raw.expandtabs()):
     +        for self.line in eol_re.split(str(self.raw.expandtabs(), 'utf-8')):
                  # Skip pragmas
                  if self.in_header:
                      if self.line.startswith('#'):
    @@@ -595,19 -605,14 +603,14 @@@ class Page
                      return False
                  raise err
      
    -     def link_to(self):
    -         word = self.page_name
    -         if self.exists():
    -             return link_tag(word, word, 'wikilink')
    -         else:
    -             return link_tag(word, nonexist_pfx + word, 'nonexistent')
    - 
    -     def get_raw_body(self):
    +     def get_raw_body(self, default=None):
              try:
                  return open(self._filename(), 'rb').read()
     -        except IOError, err:
     +        except IOError as err:
                  if err.errno == errno.ENOENT:
    -                 return '' # just doesn't exist, use default
    +                 if default is None:
    +                     default = '//[[?edit=%s|Describe %s]]//' % (self.page_name, self.page_name)
    +                 return default
                  if err.errno == errno.EISDIR:
                      return self.format_dir()
                  raise err
    @@@ -708,16 -713,17 +711,17 @@@
              if 'file' in form:
                  filename = form['file'].value
      
     -        print ('

    Editing ' + self.page_name + print(('

    Editing ' + self.page_name + ' for ' + cgi.escape(remote_user()) + ' from ' + cgi.escape(get_hostname(remote_host())) - + '

    ') - print '
    ' % relative_url(self.page_name) - print '' % (self.page_name) - print '
    ' % (self.page_name) - print '' \ - % cgi.escape(preview or self.get_raw_body(default='')) - print ' ' % filename - print """ + + '

    ')) + print('
    ' % relative_url(self.page_name)) + print('' % (self.page_name)) + print('
    ' % (self.page_name)) - print('' % cgi.escape(preview or self.get_raw_body())) ++ print('' \ ++ % cgi.escape(preview or self.get_raw_body(default=''))) + print(' ' % filename) + print("""
    @@@ -730,23 -736,19 +734,19 @@@ document.editform.savetext.focus() //--> - """ - print "

    " + link_tag('EditingTips') + "

    " + """) - print("

    " + Page('EditingTips').link_to() + "

    ") ++ print("

    " + link_tag('EditingTips') + "

    ") if preview: - print "
    " + print("
    ") WikiFormatter(preview).print_html() - print "
    " + print("
    ") send_footer() - def send_raw(self, mimetype='text/plain'): - if self.can_read(): - body = self.get_raw_body() - emit_header(mimetype) - print(body) - else: + def send_raw(self, mimetype='text/plain', args=[]): + if not self.can_read(): send_title(None, msg_text='Read access denied by ACLs', msg_type='notice') + return - def send_image(self, mimetype, args=[]): if 'maxwidth' in args: import subprocess emit_header(mimetype) @@@ -754,7 -756,9 +754,9 @@@ subprocess.check_call(['gm', 'convert', self._filename(), '-scale', args['maxwidth'].value + ' >', '-']) else: - self.send_raw(mimetype) + body = self.get_raw_body() + emit_header(mimetype) - print body ++ print(body) def _write_file(self, data): tmp_filename = self._tmp_filename() diff --cc macros/WordIndex.py index 613efb5,818a884..6438d0b mode 100644,100755..100644 --- a/macros/WordIndex.py +++ b/macros/WordIndex.py