# Head
emit_header()
- print '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'
- print ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
- print '<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">'
+ print('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"')
+ print(' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">')
+ print('<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">')
- site_name = globals().get('site_name', 'Unconfigured Site')
- print "<head><title>%s: %s</title>" % (site_name, text)
- print ' <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />'
+ print("<head><title>%s: %s</title>" % (site_name, text))
+ print(' <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />')
if not name:
- print ' <meta name="robots" content="noindex,nofollow" />'
+ print(' <meta name="robots" content="noindex,nofollow" />')
for meta in meta_urls:
http_equiv, content = meta
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>logged in as <b>' + cgi.escape(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(None)
+ send_footer()
def link_tag(params, text=None, ss_class=None, privileged=False):
if text is None:
pg.send_editor(text)
def make_index_key():
- links = map(lambda ch: '<a href="#%s">%s</a>' % (ch, ch), 'abcdefghijklmnopqrstuvwxyz')
+ links = ['<a href="#%s">%s</a>' % (ch, ch) for ch in 'abcdefghijklmnopqrstuvwxyz']
return '<p><center>'+ ' | '.join(links) + '</center></p>'
- def page_list(dir = None, re = word_re):
- return sorted(filter(re.match, os.listdir(dir or data_dir)))
+ def page_list(dirname = None, re = word_re):
+ return sorted(filter(re.match, os.listdir(dirname or data_dir)))
- def send_footer(name, mod_string=None):
+ def send_footer(mod_string=None):
if globals().get('debug_cgi', False):
cgi.print_arguments()
cgi.print_form(form)
macro = globals().get('_macro_' + name)
if not macro:
try:
- execfile("macros/" + name + ".py", globals())
- except IOError, err:
+ exec(open("macros/" + name + ".py").read(), globals())
- except IOError as er:
- if er.errno == errno.ENOENT:
- pass
++ except IOError as err:
+ if err.errno == errno.ENOENT: pass
macro = globals().get('_macro_' + name)
if macro:
return macro(argv)
return res
def replace(self, match):
- for type, hit in list(match.groupdict().items()):
- for rule, hit in match.groupdict().items():
++ for rule, hit in list(match.groupdict().items()):
if hit:
- return getattr(self, '_' + type + '_repl')(hit)
+ return getattr(self, '_' + rule + '_repl')(hit)
else:
raise "Can't handle match " + repr(match)
indent_re = re.compile(r"^\s*")
tr_re = re.compile(r"^\s*\|\|")
eol_re = re.compile(r"\r?\n")
- for self.line in eol_re.split(str(self.raw).expandtabs()):
- # Skip ACLs
- for self.line in eol_re.split(self.raw.expandtabs()):
++ for self.line in eol_re.split(str(self.raw.expandtabs())):
+ # Skip pragmas
if self.in_header:
if self.line.startswith('#'):
continue
return re.sub('([a-z])([A-Z])', r'\1 \2', self.page_name)
def _filename(self):
- return path.join(data_dir, self.page_name)
+ return os.path.join(data_dir, self.page_name)
def _tmp_filename(self):
- return path.join(data_dir, ('#' + self.page_name.replace('/','_') + '.' + repr(os.getpid()) + '#'))
- return os.path.join(data_dir, ('#' + self.page_name.replace('/','_') + '.' + `os.getpid()` + '#'))
++ return os.path.join(data_dir, ('#' + self.page_name.replace('/','_') + '.' + repr(os.getpid()) + '#'))
def exists(self):
try:
os.stat(self._filename())
return True
- except OSError as er:
- if er.errno == errno.ENOENT:
- except OSError, err:
++ except OSError as err:
+ if err.errno == errno.ENOENT:
return False
- raise er
+ raise err
def link_to(self):
word = self.page_name
def get_raw_body(self):
try:
return open(self._filename(), 'rb').read()
- except IOError as er:
- if er.errno == errno.ENOENT:
- except IOError, err:
++ except IOError as err:
+ if err.errno == errno.ENOENT:
return '' # just doesn't exist, use default
- if er.errno == errno.EISDIR:
+ if err.errno == errno.EISDIR:
return self.format_dir()
- raise er
+ raise err
def format_dir(self):
out = '== '
- path = ''
- for dir in self.page_name.split('/'):
- path = (path + '/' + dir) if path else dir
- out += '[[' + path + '|' + dir + ']]/'
+ pathname = ''
+ for dirname in self.page_name.split('/'):
+ pathname = (pathname + '/' + dirname) if pathname else dirname
+ out += '[[' + pathname + '|' + dirname + ']]/'
out += ' ==\n'
- for file in page_list(self._filename(), file_re):
- if img_re.match(file):
+ for filename in page_list(self._filename(), file_re):
+ if img_re.match(filename):
if image_maxwidth:
maxwidth_arg = '|maxwidth=' + str(image_maxwidth)
- out += '{{' + self.page_name + '/' + file + '|' + file + maxwidth_arg + '}}\n'
+ out += '{{' + self.page_name + '/' + filename + '|' + filename + maxwidth_arg + '}}\n'
else:
- out += ' * [[' + self.page_name + '/' + file + ']]\n'
+ out += ' * [[' + self.page_name + '/' + filename + ']]\n'
return out
- def get_attrs(self):
- if 'attrs' in self.__dict__:
- return self.attrs
- self.attrs = {}
- try:
- file = open(self._filename(), 'rt')
- attr_re = re.compile(r"^#(\S*)(.*)$")
- for line in file:
- m = attr_re.match(line)
- if not m:
- break
- self.attrs[m.group(1)] = m.group(2).strip()
- #print "bernie: attrs[" + m.group(1) + "] = " + m.group(2) + "<br>\n"
- except IOError as er:
- if er.errno != errno.ENOENT and er.errno != errno.EISDIR:
- raise er
- return self.attrs
-
- def get_attr(self, name, default):
- return self.get_attrs().get(name, default)
+
+ def pragmas(self):
+ if not '_pragmas' in self.__dict__:
- self._pragmas = {}
+ try:
- f = open(self._filename(), 'rt')
++ file = open(self._filename(), 'rt')
+ attr_re = re.compile(r"^#(\S*)(.*)$")
- for line in f:
++ for line in file:
+ m = attr_re.match(line)
+ if not m:
+ break
+ self._pragmas[m.group(1)] = m.group(2).strip()
- #print "bernie: _pragmas[" + m.group(1) + "] = " + m.group(2) + "<br>\n"
- except IOError, err:
++ #print "bernie: pragmas[" + m.group(1) + "] = " + m.group(2) + "<br>\n"
++ except IOError as err:
+ if err.errno != errno.ENOENT and err.errno != errno.EISDIR:
- raise err
++ raise er
+ return self._pragmas
+
+ def pragma(self, name, default):
+ return self.pragmas().get(name, default)
def can(self, action, default=True):
acl = None
try:
from time import localtime, strftime
modtime = localtime(os.stat(self._filename())[stat.ST_MTIME])
- except OSError as er:
- if er.errno != errno.ENOENT:
- raise er
- except OSError, err:
++ except OSError as err:
+ if err.errno != errno.ENOENT:
+ raise err
return None
return strftime(datetime_fmt, modtime)
send_guru("Write access denied by ACLs", "error")
return
- file = ''
+ filename = ''
if 'file' in form:
- file = form['file'].value
+ 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())
- 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('<label for="file" accesskey="u">Or Upload a file:</label> <input type="file" name="file" value="%s" />' % file)
++ 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>" + Page('EditingTips').link_to() + "</p>"
+ """)
+ print("<p>" + Page('EditingTips').link_to() + "</p>")
if preview:
- print "<div class='preview'>"
+ print("<div class='preview'>")
WikiFormatter(preview).print_html()
- print "</div>"
+ print("</div>")
- send_footer(self.page_name)
+ send_footer()
def send_raw(self, mimetype='text/plain'):
if self.can_read():
# Bad Bill! POSIX rename ought to replace. :-(
try:
os.remove(name)
- except OSError as er:
- if er.errno != errno.ENOENT: raise er
- except OSError, err:
++ except OSError as err:
+ if err.errno != errno.ENOENT: raise err
os.rename(tmp_filename, name)
def save(self, newdata, changelog):
Page(query).format()
else:
send_httperror("403 Forbidden", query)
- execfile("geekigeeki.conf.py")
+
+ try:
++ exec(open("geekigeeki.conf.py").read())
+ form = cgi.FieldStorage()
+ main()
except Exception:
import traceback
msg_text = traceback.format_exc()