if not macro:
try:
execfile("macros/" + name + ".py", globals())
- except IOError, er:
- if er.errno == errno.ENOENT:
- pass
+ except IOError, err:
+ if err.errno == errno.ENOENT: pass
macro = globals().get('_macro_' + name)
if macro:
return macro(argv)
if hit:
return getattr(self, '_' + rule + '_repl')(hit)
else:
- raise "Can't handle match " + `match`
+ raise "Can't handle match " + repr(match)
def print_html(self):
print '<div class="wiki"><p>'
tr_re = re.compile(r"^\s*\|\|")
eol_re = re.compile(r"\r?\n")
for self.line in eol_re.split(self.raw.expandtabs()):
- # Skip ACLs
+ # Skip pragmas
if self.in_header:
if self.line.startswith('#'):
continue
try:
os.stat(self._filename())
return True
- except OSError, er:
- if er.errno == errno.ENOENT:
+ except OSError, 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, er:
- if er.errno == errno.ENOENT:
+ except IOError, 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 = '== '
else:
out += ' * [[' + self.page_name + '/' + filename + ']]\n'
return out
- def get_attrs(self):
- if 'attrs' in self.__dict__:
- return self.attrs
- self.attrs = {}
- try:
- f = open(self._filename(), 'rt')
- attr_re = re.compile(r"^#(\S*)(.*)$")
- for line in f:
- 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, 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')
+ attr_re = re.compile(r"^#(\S*)(.*)$")
+ for line in f:
+ 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:
+ if err.errno != errno.ENOENT and err.errno != errno.EISDIR:
+ raise err
+ return self._pragmas
+
+ def pragma(self, name, default):
+ return self.pragmas().get(name, default)
def can(self, action, default=True):
acl = None
try:
#acl SomeUser:read,write All:read
- acl = self.get_attr("acl", None)
+ acl = self.pragma("acl", None)
for rule in acl.split():
(user, perms) = rule.split(':')
if user == remote_user() or user == "All":
def format(self):
#css foo.css
- value = self.get_attr("css", None)
+ value = self.pragma("css", None)
if value:
global link_urls
link_urls += [ [ "stylesheet", value ] ]
try:
from time import localtime, strftime
modtime = localtime(os.stat(self._filename())[stat.ST_MTIME])
- except OSError, er:
- if er.errno != errno.ENOENT:
- raise er
+ except OSError, err:
+ if err.errno != errno.ENOENT:
+ raise err
return None
return strftime(datetime_fmt, modtime)
# Bad Bill! POSIX rename ought to replace. :-(
try:
os.remove(name)
- except OSError, er:
- if er.errno != errno.ENOENT: raise er
+ except OSError, err:
+ if err.errno != errno.ENOENT: raise err
os.rename(tmp_filename, name)
def save(self, newdata, changelog):