From: Bernie Innocenti Date: Mon, 15 Dec 2008 03:24:36 +0000 (-0500) Subject: Merge pylint/pychecker cleanups from branch master of trinity X-Git-Tag: v4.0~17 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=7ce906e26b7c2c91e232508ccd0af6fe9ec4aeec;p=geekigeeki.git Merge pylint/pychecker cleanups from branch master of trinity Conflicts: geekigeeki.py --- 7ce906e26b7c2c91e232508ccd0af6fe9ec4aeec diff --cc geekigeeki.py index a9aa019,0ff2e7a..ca16283 --- a/geekigeeki.py +++ b/geekigeeki.py @@@ -116,15 -115,14 +115,14 @@@ def send_title(name, text="Limbo", msg_ # Head emit_header() - print '' - print '' + print('') + print('') - site_name = globals().get('site_name', 'Unconfigured Site') - print "%s: %s" % (site_name, text) - print ' ' + print("%s: %s" % (site_name, text)) + print(' ') if not name: - print ' ' + print(' ') for meta in meta_urls: http_equiv, content = meta @@@ -179,14 -177,14 +177,14 @@@ user = remote_user() if user != 'AnonymousCoward': - print ' | logged in as ' + cgi.escape(user) + '' + print(' | logged in as ' + cgi.escape(user) + '') - print '
' + print('
') 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: @@@ -278,13 -276,13 +276,13 @@@ def handle_edit(pagename) pg.send_editor(text) def make_index_key(): - links = map(lambda ch: '%s' % (ch, ch), 'abcdefghijklmnopqrstuvwxyz') + links = ['%s' % (ch, ch) for ch in 'abcdefghijklmnopqrstuvwxyz'] return '

'+ ' | '.join(links) + '

' - 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) @@@ -371,10 -369,9 +369,9 @@@ class WikiFormatter 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) @@@ -493,9 -490,9 +490,9 @@@ 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) @@@ -547,8 -544,8 +544,8 @@@ 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 @@@ -584,19 -581,19 +581,19 @@@ class Page 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 @@@ -608,49 -605,49 +605,48 @@@ 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) + "
\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) + "
\n" - except IOError, err: ++ #print "bernie: pragmas[" + m.group(1) + "] = " + m.group(2) + "
\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 @@@ -695,9 -692,9 +691,9 @@@ 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) @@@ -707,20 -704,20 +703,20 @@@ send_guru("Write access denied by ACLs", "error") return - file = '' + filename = '' if 'file' in form: - file = form['file'].value + filename = form['file'].value - print ('

Editing ' + self.page_name + print(('

Editing ' + self.page_name + ' for ' + cgi.escape(remote_user()) + ' from ' + cgi.escape(get_hostname(remote_host())) - + '

') - print '
' % relative_url(self.page_name) - print '' % (self.page_name) - print '
' % (self.page_name) - print '' % cgi.escape(preview or self.get_raw_body()) - print ' ' % filename - print """ + + '

')) + print('
' % relative_url(self.page_name)) + print('' % (self.page_name)) + print('
' % (self.page_name)) + print('' % cgi.escape(preview or self.get_raw_body())) - print(' ' % file) ++ print(' ' % filename) + print("""
@@@ -733,13 -730,13 +729,13 @@@ document.editform.savetext.focus() //--> - """ - print "

" + Page('EditingTips').link_to() + "

" + """) + print("

" + Page('EditingTips').link_to() + "

") if preview: - print "
" + print("
") WikiFormatter(preview).print_html() - print "
" + print("
") - send_footer(self.page_name) + send_footer() def send_raw(self, mimetype='text/plain'): if self.can_read(): @@@ -767,8 -764,8 +763,8 @@@ # 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): @@@ -833,6 -824,11 +823,11 @@@ def main() Page(query).format() else: send_httperror("403 Forbidden", query) + + try: - execfile("geekigeeki.conf.py") ++ exec(open("geekigeeki.conf.py").read()) + form = cgi.FieldStorage() + main() except Exception: import traceback msg_text = traceback.format_exc()