From 6fe435b1dba5647a83349f69fe95eb3c02758997 Mon Sep 17 00:00:00 2001 From: Bernie Innocenti Date: Mon, 15 Dec 2008 04:01:55 +0100 Subject: [PATCH] Fix a bunch of pylint warnings. I'm not ever going to fix the fascist warnings about making all variable names longer than 2 characters. --- geekigeeki.py | 77 +++++++++++++++++++++++++-------------------------- 1 file changed, 38 insertions(+), 39 deletions(-) diff --git a/geekigeeki.py b/geekigeeki.py index 23b05d5..0ff2e7a 100755 --- a/geekigeeki.py +++ b/geekigeeki.py @@ -370,9 +370,8 @@ class WikiFormatter: 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) @@ -495,7 +494,7 @@ class WikiFormatter: 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 '

' @@ -546,7 +545,7 @@ class WikiFormatter: 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 @@ -591,10 +590,10 @@ class Page: 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 @@ -606,12 +605,12 @@ class Page: 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 = '== ' @@ -629,32 +628,32 @@ class Page: 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) + "
\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) + "
\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": @@ -679,7 +678,7 @@ class Page: 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 ] ] @@ -693,9 +692,9 @@ class Page: 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) @@ -765,8 +764,8 @@ class Page: # 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): -- 2.25.1