def send_guru(msg_text, msg_type):
if not msg_text: return
- print '<pre id="guru" onclick="this.style.display = \'none\'" class="' + msg_type + '">'
+ print('<pre id="guru" onclick="this.style.display = \'none\'" class="' + msg_type + '">')
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('</pre>')
- # FIXME: This little JS snippet is harder to pass than ACID 3.0
- print("""
- <script language="JavaScript" type="text/javascript">
- var guru = document.getElementById('guru');
- // Firefox 2.0 doesn't take border-color, but returns border-top-color fine
- var color = document.defaultView.getComputedStyle(guru,null).getPropertyValue('border-top-color');
-
- function guruOn() {
- guru.style.setProperty('border-color', color, '');
- setTimeout('guruOff()', 1000);
- }
- function guruOff() {
- guru.style.setProperty('border-color', '#000000', '');
- setTimeout('guruOn()', 1000);
- }
- // Safari 2.0 returns this rgba crap
- // Konqueror 3.5.6 doesn't seem to support computed properties
- if (color && color != 'rgba(0, 0, 0, 0)') {
- //window.alert("enabled! color='" + color + "'");
- guruOn();
- }
- </script>""")
+ print '\n Guru Meditation #DEADBEEF.ABADC0DE'
- print '</pre>'
- print '<script language="JavaScript" type="text/javascript" src="%s" defer="defer"></script>' \
- % relative_url('sys/GuruMeditation.js')
++ print('</pre><script language="JavaScript" type="text/javascript" src="%s" defer="defer"></script>' \
++ % relative_url('sys/GuruMeditation.js'))
def send_title(name, text="Limbo", msg_text=None, msg_type='error', writable=False):
global title_done
send_guru(msg_text, msg_type)
# Navbar
- print '<div class="nav">'
+ print('<div class="nav">')
+ print link_tag('FrontPage', site_icon or 'Home', 'navlink')
if name:
- print ' <b>' + link_tag('?fullsearch=' + name, text, 'navlink') + '</b> '
+ print(' <b>' + link_tag('?fullsearch=' + name, text, 'navlink') + '</b> ')
else:
- print ' <b>' + text + '</b> '
- print ' | ' + link_tag('FindPage', 'Find Page', 'navlink')
+ print(' <b>' + text + '</b> ')
- print(' | ' + link_tag('FrontPage', 'Home', 'navlink'))
+ print(' | ' + link_tag('FindPage', 'Find Page', 'navlink'))
if 'history_url' in globals():
- print ' | <a href="' + relative_url(history_url) + '" class="navlink">Recent Changes</a>'
+ print(' | <a href="' + relative_url(history_url) + '" class="navlink">Recent Changes</a>')
if name:
- print ' | <a href="' + relative_url(history_url + '?a=history;f=' + name) + '" class="navlink">Page History</a>'
+ print(' | <a href="' + relative_url(history_url + '?a=history;f=' + name) + '" class="navlink">Page History</a>')
if name:
- print ' | ' + link_tag('?raw=' + name, 'Raw Text', 'navlink')
+ print(' | ' + link_tag('?raw=' + name, 'Raw Text', 'navlink'))
if privileged_url is not None:
if writable:
- print ' | ' + link_tag('?edit=' + name, 'Edit', 'navlink', privileged=True)
+ print(' | ' + link_tag('?edit=' + name, 'Edit', 'navlink', privileged=True))
else:
- print ' | ' + link_tag(name, 'Login', 'navlink', privileged=True)
+ print(' | ' + link_tag(name, 'Login', 'navlink', privileged=True))
else:
- print ' | <i>Immutable Page</i>'
+ print(' | <i>Immutable Page</i>')
user = remote_user()
if user != 'AnonymousCoward':
- print(' | <span class="login"><i>logged in as <b>' + cgi.escape(user) + '</b></i></span>')
- print ' | <span class="login"><i><b>' + link_tag('User/' + user, user) + '</b></i></span>'
++ print(' | <span class="login"><i><b>' + link_tag('User/' + user, user) + '</b></i></span>')
- print '<hr /></div>'
+ print('<hr /></div>')
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()
hits.sort()
hits.reverse()
- print "<ul>"
+ print("<ul>")
for (count, page_name) in hits:
- print('<li><p>' + Page(page_name).link_to())
- print(' . . . . ' + str(count))
- print '<li><p>' + link_tag(page_name)
- print ' . . . . ' + `count`
- print ['match', 'matches'][count != 1]
- print '</p></li>'
- print "</ul>"
++ print('<li><p>' + link_tag(page_name))
++ print(' . . . . ' + `count`)
+ print(['match', 'matches'][count != 1])
+ print('</p></li>')
+ print("</ul>")
print_search_stats(len(hits), len(all_pages))
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 "<ul>"
+ print("<ul>")
for filename in hits:
- print('<li><p>' + Page(filename).link_to() + "</p></li>")
- print '<li><p>' + link_tag(filename) + "</p></li>"
- print "</ul>"
++ print('<li><p>' + link_tag(filename) + "</p></li>")
+ print("</ul>")
print_search_stats(len(hits), len(all_pages))
text = form['savetext'].value
pg.send_editor(text)
+ # Used by macros/WordIndex and macros/TitleIndex
def make_index_key():
- links = map(lambda ch: '<a href="#%s">%s</a>' % (ch, ch), 'abcdefghijklmnopqrstuvwxyz')
- return '<p style="text-align: center">'+ ' | '.join(links) + '</p>'
+ links = ['<a href="#%s">%s</a>' % (ch, ch) for ch in 'abcdefghijklmnopqrstuvwxyz']
- return '<p><center>'+ ' | '.join(links) + '</center></p>'
++ return '<p style="text-align: center">' + ' | '.join(links) + '</p>'
def page_list(dirname = None, re = word_re):
return sorted(filter(re.match, os.listdir(dirname or data_dir)))
cgi.print_arguments()
cgi.print_form(form)
cgi.print_environ()
- print '''
+ print('''
<div id="footer"><hr />
<p class="copyright">
- <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/"><img class="license" alt="Creative Commons License" src="http://i.creativecommons.org/l/by-sa/3.0/80x15.png" /></a>
+ <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/"><img class="license" alt="Creative Commons License" src="%s" /></a>
<span class="benchmark">generated in %0.3fs</span> by <a href="http://www.codewiz.org/wiki/GeekiGeeki">GeekiGeeki</a> version %s
</p>
- ''' % (clock() - start_time, __version__))
-''' % (relative_url('cc-by-sa.png'), clock() - start_time, __version__)
++''' % (relative_url('cc-by-sa.png'), clock() - start_time, __version__))
if mod_string:
- print '<p class="modified">last modified %s</p>' % mod_string
- print '</div></body></html>'
+ print('<p class="modified">last modified %s</p>' % mod_string)
+ print('</div></body></html>')
class WikiFormatter:
"""Object that turns Wiki markup into HTML.
raise "Can't handle match " + repr(match)
def print_html(self):
- print '<div class="wiki"><p>'
+ print('<div class="wiki"><p>')
- # 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<b>\*\*|'''|//|''|##|``|__|\^\^|,,)"
- + r"|(?P<tit>\={2,6})"
- + r"|(?P<br>\\\\)"
- + r"|(?P<rule>^-{3,})"
- + r"|(?P<hi>\b(FIXME|TODO|DONE)\b)"
+ scan_re = re.compile(r"""(?:
+ # Styles and formatting
+ (?P<b> \*\*|'''|//|''|\#\#|``|__|\^\^|,,)
+ | (?P<tit> \={2,6})
+ | (?P<br> \\\\)
+ | (?P<rule> ^-{3,})
+ | (?P<hi> \b( FIXME | TODO | DONE )\b )
# Links
- + r"|(?P<macro>\<\<([^\s\|\>]+)(?:\s*\|\s*([^\>]+)|)\>\>)"
- + r"|(?P<hurl>\[\[([^\s\|]+)(?:\s*\|\s*([^\]]+)|)\]\])"
+ | (?P<macro> \<\<([^\s\|\>]+)(?:\s*\|\s*([^\>]+)|)\>\>)
+ | (?P<hurl> \[\[([^\s\|]+)(?:\s*\|\s*([^\]]+)|)\]\])
# Inline HTML
- + r"|(?P<html><(/|)(br|hr|div|span|form|iframe|input|textarea|a|img|h[1-5])[^>]*>)"
- + r"|(?P<ent>[<>&])"
+ | (?P<html> <(br|hr|div|span|form|iframe|input|textarea|a|img|h[1-5])\b )
+ | (?P<htmle> ( /\s*> | </(br|hr|div|span|form|iframe|input|textarea|a|img|h[1-5])> ) )
+ | (?P<ent> [<>&] )
# Auto links (LEGACY)
- + r"|(?P<img>\b[a-zA-Z0-9_/-]+\.(png|gif|jpg|jpeg|bmp|ico))"
- + r"|(?P<word>\b(?:[A-Z][a-z]+){2,}\b)"
- + r"|(?P<url>(http|https|ftp|mailto)\:[^\s'\"]+\S)"
- + r"|(?P<email>[-\w._+]+\@[\w.-]+)"
+ | (?P<img> \b[a-zA-Z0-9_/-]+\.(png|gif|jpg|jpeg|bmp|ico|ogm|ogg|mkv|mpg|mpeg|mp4|avi|asf|flv|wmv|qt))
+ | (?P<word> \b(?:[A-Z][a-z]+){2,}\b)
+ | (?P<url> (http|https|ftp|mailto)\:[^\s'\"]+\S)
+ | (?P<email> [-\w._+]+\@[\w.-]+)
# Lists, divs, spans
- + r"|(?P<li>^\s+[\*#] +)"
- + r"|(?P<pre>\{\{\{|\s*\}\}\})"
- + r"|(?P<inl>\{\{([^\s\|]+)(?:\s*\|\s*([^\]]+)|)\}\})"
+ | (?P<li> ^\s+[\*\#]\s+)
+ | (?P<pre> \{\{\{|\s*\}\}\})
+ | (?P<inl> \{\{([^\s\|]+)(?:\s*\|\s*([^\]]+)|)\}\})
# Tables
- + r"|(?P<tr>^\s*\|\|(=|)\s*)"
- + r"|(?P<tre>\s*\|\|(=|)\s*$)"
- + r"|(?P<td>\s*\|\|(=|)\s*)"
- + r")")
- pre_re = re.compile(
- r"(?:"
- + r"(?P<pre>\s*\}\}\})"
- + r"|(?P<ent>[<>&])"
- + r")")
+ | (?P<tr> ^\s*\|\|(=|)\s*)
+ | (?P<tre> \s*\|\|(=|)\s*$)
+ | (?P<td> \s*\|\|(=|)\s*)
+
+ # TODO: highlight search words (look at referrer)
+ )""", re.VERBOSE)
+ pre_re = re.compile("""(?:
+ (?P<pre>\s*\}\}\})
+ | (?P<ent>[<>&])"
+ )""", 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('#'):
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
if 'file' in form:
filename = form['file'].value
- print ('<p><b>Editing ' + self.page_name
+ print(('<p><b>Editing ' + self.page_name
+ ' for ' + cgi.escape(remote_user())
+ ' from ' + cgi.escape(get_hostname(remote_host()))
- + '</b></p>')
- print '<div class="editor"><form name="editform" method="post" enctype="multipart/form-data" action="%s">' % relative_url(self.page_name)
- print '<input type="hidden" name="edit" value="%s">' % (self.page_name)
- print '<input type="input" id="editor" name="changelog" value="Edit page %s" accesskey="c" /><br />' % (self.page_name)
- print '<textarea wrap="off" spellcheck="true" id="editor" name="savetext" rows="17" cols="100" accesskey="e">%s</textarea>' \
- % cgi.escape(preview or self.get_raw_body(default=''))
- print '<label for="file" accesskey="u">Or Upload a file:</label> <input type="file" name="file" value="%s" />' % filename
- print """
+ + '</b></p>'))
+ print('<div class="editor"><form name="editform" method="post" enctype="multipart/form-data" action="%s">' % relative_url(self.page_name))
+ print('<input type="hidden" name="edit" value="%s">' % (self.page_name))
+ print('<input type="input" id="editor" name="changelog" value="Edit page %s" accesskey="c" /><br />' % (self.page_name))
- print('<textarea wrap="off" spellcheck="true" id="editor" name="savetext" rows="17" cols="100" accesskey="e">%s</textarea>' % cgi.escape(preview or self.get_raw_body()))
++ print('<textarea wrap="off" spellcheck="true" id="editor" name="savetext" rows="17" cols="100" accesskey="e">%s</textarea>' \
++ % cgi.escape(preview or self.get_raw_body(default='')))
+ print('<label for="file" accesskey="u">Or Upload a file:</label> <input type="file" name="file" value="%s" />' % filename)
+ print("""
<br />
<input type="submit" name="save" value="Save" accesskey="s">
<input type="submit" name="preview" value="Preview" accesskey="p" />
document.editform.savetext.focus()
//-->
</script>
- """
- print "<p>" + link_tag('EditingTips') + "</p>"
+ """)
- print("<p>" + Page('EditingTips').link_to() + "</p>")
++ print("<p>" + link_tag('EditingTips') + "</p>")
if preview:
- print "<div class='preview'>"
+ print("<div class='preview'>")
WikiFormatter(preview).print_html()
- print "</div>"
+ print("</div>")
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)
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()