#
# Copyright 1999, 2000 Martin Pool <mbp@humbug.org.au>
# Copyright 2002 Gerardo Poggiali
-# Copyright 2007, 2008 Bernardo Innocenti <bernie@codewiz.org>
+# Copyright 2007, 2008 Bernie Innocenti <bernie@codewiz.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
links = map(lambda ch: '<a href="#%s">%s</a>' % (ch, ch), 'abcdefghijklmnopqrstuvwxyz')
return '<p><center>'+ ' | '.join(links) + '</center></p>'
-def page_list():
- return filter(word_re.match, os.listdir(data_dir))
+def page_list(dir = None, re = word_re):
+ return filter(re.match, os.listdir(dir or data_dir))
def send_footer(name, mod_string=None):
if globals().get('debug_cgi', False):
+ r"|(?P<ent>[<>&])"
# Auto links
- + r"|(?P<img>\b[a-zA-Z0-9_-]+\.(png|gif|jpg|jpeg|bmp))" # LEGACY
+ + r"|(?P<img>\b[a-zA-Z0-9_/-]+\.(png|gif|jpg|jpeg|bmp))" # LEGACY
+ r"|(?P<word>\b(?:[A-Z][a-z]+){2,}\b)" # LEGACY
+ r"|(?P<url>(http|https|ftp|mailto)\:[^\s'\"]+\S)" # LEGACY
+ r"|(?P<email>[-\w._+]+\@[\w.-]+)" # LEGACY
# look for the end of words and the start of a new word and insert a space there
return re.sub('([a-z])([A-Z])', r'\1 \2', self.page_name)
- def _text_filename(self):
+ def _filename(self):
return path.join(data_dir, self.page_name)
def _tmp_filename(self):
def exists(self):
try:
- os.stat(self._text_filename())
+ os.stat(self._filename())
return True
except OSError, er:
if er.errno == errno.ENOENT:
def get_raw_body(self):
try:
- return open(self._text_filename(), 'rb').read()
+ return open(self._filename(), 'rb').read()
except IOError, er:
if er.errno == errno.ENOENT:
return '' # just doesn't exist, use default
if er.errno == errno.EISDIR:
- return 'DIR'
+ return self.format_dir()
raise er
+ def format_dir(self):
+ out = ''
+ for file in page_list(self._filename(), file_re):
+ if img_re.match(file):
+ out += ' * {{' + self.page_name + '/' + file + '}}\n'
+ else:
+ out += ' * [[' + self.page_name + '/' + file + ']]\n'
+ return out
def get_attrs(self):
if 'attrs' in self.__dict__:
return self.attrs
self.attrs = {}
try:
- file = open(self._text_filename(), 'rt')
+ file = open(self._filename(), 'rt')
attr_re = re.compile(r"^#(\S*)(.*)$")
for line in file:
m = attr_re.match(line)
def _last_modified(self):
try:
from time import localtime, strftime
- modtime = localtime(os.stat(self._text_filename())[stat.ST_MTIME])
+ modtime = localtime(os.stat(self._filename())[stat.ST_MTIME])
except OSError, er:
if er.errno != errno.ENOENT:
raise er
def _write_file(self, data):
tmp_filename = self._tmp_filename()
open(tmp_filename, 'wb').write(data)
- name = self._text_filename()
+ name = self._filename()
if os.name == 'nt':
# Bad Bill! POSIX rename ought to replace. :-(
try: