2 # -*- coding: utf-8 -*-
4 # Copyright 1999, 2000 Martin Pool <mbp@humbug.org.au>
5 # Copyright 2002 Gerardo Poggiali
6 # Copyright 2007, 2008, 2009 Bernie Innocenti <bernie@codewiz.org>
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 __version__ = '4.0-' + '$Id$'[4:11]
23 from time import clock
27 import cgi, sys, os, re, errno, stat, glob
29 image_ext = 'png|gif|jpg|jpeg|bmp|ico'
30 video_ext = "ogg|ogv|oga" # Not supported by Firefox 3.5: mkv|mpg|mpeg|mp4|avi|asf|flv|wmv|qt
31 image_re = re.compile(r".*\.(" + image_ext + "|" + video_ext + ")", re.IGNORECASE)
32 video_re = re.compile(r".*\.(" + video_ext + ")", re.IGNORECASE)
33 # FIXME: we accept stuff like foo/../bar and we shouldn't
34 file_re = re.compile(r"([A-Za-z0-9_\-][A-Za-z0-9_\.\-/]*)")
35 url_re = re.compile(r"[a-z]{3,8}://[^\s'\"]+\S")
36 ext_re = re.compile(r"\.([^\./]+)$")
38 # CGI stuff ---------------------------------------------------------
39 def config_get(key, default=None):
40 return globals().get(key, default)
43 return os.environ.get('SCRIPT_NAME', '')
46 path_info = os.environ.get('PATH_INFO', '')
47 if len(path_info) and path_info[0] == '/':
48 return path_info[1:] or 'FrontPage'
50 return os.environ.get('QUERY_STRING', '') or 'FrontPage'
52 def privileged_path():
53 return config_get('privileged_url') or script_name()
56 user = os.environ.get('REMOTE_USER', '')
57 if user is None or user == '' or user == 'anonymous':
58 user = 'AnonymousCoward'
62 return os.environ.get('REMOTE_ADDR', '')
64 def get_hostname(addr):
66 from socket import gethostbyaddr
67 return gethostbyaddr(addr)[0] + ' (' + addr + ')'
71 def is_external_url(pathname):
72 return (url_re.match(pathname) or pathname.startswith('/'))
74 def relative_url(pathname, privileged=False):
75 if not is_external_url(pathname):
77 url = privileged_path()
80 pathname = url + '/' + pathname
81 return cgi.escape(pathname, quote=True)
84 return re.sub(' ', '-', re.sub('[^a-z0-9_ ]', '', s.lower()).strip())
87 return re.sub(r'(?:.*[/:]|)([^:/\.]+)(?:\.[^/:]+|)$', r'\1', s.replace('_', ' '))
89 # Split arg lists like "blah|blah blah| width=100 | align = center",
90 # return a list containing anonymous arguments and a map containing the named arguments
94 for arg in s.strip('<[{}]>').split('|'):
95 m = re.match('\s*(\w+)\s*=\s*(.+)\s*', arg)
97 kvargs[m.group(1)] = m.group(2)
99 args.append(arg.strip())
100 return (args, kvargs)
102 def url_args(kvargs):
104 for k, v in kvargs.items():
105 argv.append(k + '=' + v)
107 return '?' + '&'.join(argv)
110 # Formatting stuff --------------------------------------------------
111 def emit_header(mime_type="text/html"):
112 print("Content-type: " + mime_type + "; charset=utf-8\n")
114 def send_guru(msg_text, msg_type):
115 if not msg_text: return
116 print('<pre id="guru" onclick="this.style.display = \'none\'" class="' + msg_type + '">')
117 if msg_type == 'error':
118 print(' Software Failure. Press left mouse button to continue.\n')
119 print(cgi.escape(msg_text))
120 if msg_type == 'error':
121 print '\n Guru Meditation #DEADBEEF.ABADC0DE'
122 print('</pre><script language="JavaScript" type="text/javascript" src="%s" defer="defer"></script>' \
123 % relative_url('sys/GuruMeditation.js'))
125 def send_title(name, text="Limbo", msg_text=None, msg_type='error', writable=False):
127 if title_done: return
131 print('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"')
132 print(' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">')
133 print('<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">')
135 print("<head><title>%s: %s</title>" % (config_get('site_name', "Unconfigured Wiki"), text))
136 print(' <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />')
138 print(' <meta name="robots" content="noindex,nofollow" />')
140 for http_equiv, content in config_get('meta_urls', {}):
141 print(' <meta http-equiv="%s" content="%s" />' % (http_equiv, relative_url(content)))
143 for link in config_get('link_urls', {}):
145 print(' <link rel="%s" href="%s" />' % (rel, relative_url(href)))
147 editable = name and writable and config_get('privileged_url') is not None
149 print(' <link rel="alternate" type="application/x-wiki" title="Edit this page" href="%s" />' \
150 % (privileged_path() + '?a=edit&q=' + name))
152 history = config_get('history_url')
153 if history is not None:
154 print(' <link rel="alternate" type="application/rss+xml" title="RSS" href="%s" />' \
155 % relative_url(history + '?a=rss'))
161 print('<body ondblclick="location.href=\'' + privileged_path() + '?a=edit&q=' + name + '\'">')
166 send_guru(msg_text, msg_type)
169 print('<div class="nav">')
170 print link_tag('FrontPage', config_get('site_icon', 'Home'), cssclass='navlink')
172 print(' <b>' + link_tag('?fullsearch=' + name, text, cssclass='navlink') + '</b> ')
174 print(' <b>' + text + '</b> ')
175 print(' | ' + link_tag('FindPage', 'Find Page', cssclass='navlink'))
177 print(' | <a href="' + relative_url(history) + '" class="navlink">Recent Changes</a>')
179 print(' | <a href="' + relative_url(history + '?a=history;f=' + name) + '" class="navlink">Page History</a>')
182 print(' | ' + link_tag(name + '?a=raw', 'Raw Text', cssclass='navlink'))
183 if config_get('privileged_url') is not None:
185 print(' | ' + link_tag('?a=edit&q=' + name, 'Edit', cssclass='navlink', privileged=True))
187 print(' | ' + link_tag(name, 'Login', cssclass='navlink', privileged=True))
190 print(' | <i>Immutable Page</i>')
193 if user != 'AnonymousCoward':
194 print(' | <span class="login"><i><b>' + link_tag('User/' + user, user) + '</b></i></span>')
196 print('<hr /></div>')
198 def send_httperror(status="403 Not Found", query=""):
199 print("Status: %s" % status)
200 send_title(None, msg_text=("%s: on query '%s'" % (status, query)))
203 def link_tag(dest, text=None, privileged=False, **kvargs):
205 text = humanlink(dest)
206 elif image_re.match(text):
207 text = '<img border="0" src="' + relative_url(text) + '" alt="' + text + '" />'
209 link_class = kvargs.get('class', kvargs.get('cssclass', None))
211 if is_external_url(dest):
212 link_class = 'external'
213 elif file_re.match(dest) and Page(dest).exists():
214 link_class = 'wikilink'
216 text = config_get('nonexist_pfx', '') + text
217 link_class = 'nonexistent'
219 # Prevent crawlers from following links potentially added by spammers or to generated pages
221 if link_class == 'external' or link_class == 'navlink':
222 nofollow = 'rel="nofollow" '
224 return '<a class="%s" %shref="%s">%s</a>' % (link_class, nofollow, relative_url(dest, privileged=privileged), text)
226 def link_inline(name, descr=None, kvargs={}):
227 if not descr: descr = humanlink(name)
228 url = relative_url(name)
229 if video_re.match(name):
230 return '<video controls="1" src="%s">Your browser does not support HTML5 video</video>' % url
231 elif image_re.match(name):
232 return '<a href="%s"><img border="0" src="%s" alt="%s" /></a>' % (url, url + url_args(kvargs), descr)
233 elif file_re.match(name) and not ext_re.search(name): # FIXME: this guesses a wiki page
234 return Page(name).send_naked(kvargs)
236 return '<iframe width="100%%" scrolling="auto" frameborder="0" src="%s"><a href="%s">%s</a></iframe>' \
239 def link_inline_glob(pattern, descr=None, kvargs={}):
240 os.chdir(config_get('data_dir', 'data'))
242 for name in glob.glob(pattern):
243 s += link_inline(name, descr, kvargs)
246 # Search ---------------------------------------------------
248 def print_search_stats(hits, searched):
249 print("<p>%d hits out of %d pages searched.</p>" % (hits, searched))
251 def handle_fullsearch(query, form):
252 needle = form['q'].value
253 send_title(None, 'Full text search for "' + needle + '"')
255 needle_re = re.compile(needle, re.IGNORECASE)
257 all_pages = page_list()
258 for page_name in all_pages:
259 body = Page(page_name).get_raw_body()
260 count = len(needle_re.findall(body))
262 hits.append((count, page_name))
264 # The default comparison for tuples compares elements in order,
265 # so this sorts by number of hits
270 for (count, page_name) in hits:
271 print('<li><p>' + link_tag(page_name))
272 print(' . . . . ' + `count`)
273 print(['match', 'matches'][count != 1])
277 print_search_stats(len(hits), len(all_pages))
279 def handle_titlesearch(query, form):
280 needle = form['q'].value
281 send_title(None, 'Title search for "' + needle + '"')
283 needle_re = re.compile(needle, re.IGNORECASE)
284 all_pages = page_list()
285 hits = list(filter(needle_re.search, all_pages))
288 for filename in hits:
289 print('<li><p>' + link_tag(filename) + "</p></li>")
292 print_search_stats(len(hits), len(all_pages))
294 def handle_raw(pagename, form):
295 if not file_re.match(pagename):
296 send_httperror("403 Forbidden", pagename)
299 Page(pagename).send_raw()
301 def handle_edit(pagename, form):
302 if not file_re.match(pagename):
303 send_httperror("403 Forbidden", pagename)
306 pg = Page(form['q'].value)
308 if form['file'].value:
309 pg.save(form['file'].file.read(), form['changelog'].value)
311 pg.save(form['savetext'].value.replace('\r\n', '\n'), form['changelog'].value)
313 elif 'cancel' in form:
314 pg.msg_text = 'Editing canceled'
315 pg.msg_type = 'notice'
317 else: # preview or edit
319 if 'preview' in form:
320 text = form['savetext'].value
323 def handle_get(pagename, form):
324 if file_re.match(pagename):
325 # FIMXE: this is all bullshit, MimeTypes bases its guess on the extension!
326 from mimetypes import MimeTypes
327 mimetype, encoding = MimeTypes().guess_type(pagename)
329 Page(pagename).send_raw(mimetype=mimetype, args=form)
331 Page(pagename).format()
333 send_httperror("403 Forbidden", pagename)
335 # Used by macros/WordIndex and macros/TitleIndex
336 def make_index_key():
337 links = ['<a href="#%s">%s</a>' % (ch, ch) for ch in 'abcdefghijklmnopqrstuvwxyz']
338 return '<p style="text-align: center">' + ' | '.join(links) + '</p>'
340 def page_list(dirname=None, search_re=None):
341 if search_re is None:
342 # FIXME: WikiWord is too restrictive now!
343 search_re = re.compile(r"^\b((([A-Z][a-z0-9]+){2,}/)*([A-Z][a-z0-9]+){2,})\b$")
344 return sorted(filter(search_re.match, os.listdir(dirname or config_get('data_dir', 'data'))))
346 def send_footer(mod_string=None):
347 if config_get('debug_cgi', False):
348 cgi.print_arguments()
351 link_inline("sys/footer", kvargs = { 'LAST_MODIFIED': mod_string })
352 print("</body></html>")
354 def _macro_ELAPSED_TIME(*args, **kvargs):
355 return "%03f" % (clock() - start_time)
357 def _macro_VERSION(*args, **kvargs):
361 """Object that turns Wiki markup into HTML.
363 All formatting commands can be parsed one line at a time, though
364 some state is carried over between lines.
366 def __init__(self, raw, kvargs=None):
368 self.kvargs = kvargs or {}
370 self.in_pre = self.in_html = self.in_table = self.in_li = False
371 self.in_header = True
372 self.list_indents = []
380 "--": ["del", False],
381 "^^": ["sup", False],
382 ",,": ["sub", False],
383 "''": ["em", False], # LEGACY
384 "'''": ["b", False], # LEGACY
385 "``": ["tt", False], # LEGACY
388 def _b_repl(self, word):
389 style = self.styles[word]
390 style[1] = not style[1]
391 return ['</', '<'][style[1]] + style[0] + '>'
393 def _glyph_repl(self, word):
396 def _tit_repl(self, word):
398 result = '</h%d><p>\n' % self.h_level
401 self.h_level = len(word) - 1
402 link = permalink(self.line)
403 result = '\n</p><h%d id="%s"><a class="heading" href="#%s">¶</a> ' % (self.h_level, link, link)
406 def _br_repl(self, word):
409 def _rule_repl(self, word):
410 return self._undent() + '\n<hr size="%d" noshade="noshade" />\n' % (len(word) - 2)
412 def _macro_repl(self, word):
414 args, kvargs = parse_args(word)
415 if args[0] in self.kvargs:
416 return self.kvargs[args[0]]
417 macro = globals().get('_macro_' + args[0])
419 exec(open("macros/" + args[0] + ".py").read(), globals())
420 macro = globals().get('_macro_' + args[0])
421 return macro(*args, **kvargs)
423 msg = cgi.escape(word) + ": " + cgi.escape(e.message)
425 msg = '<strong class="error">' + msg + '</strong>'
428 def _hurl_repl(self, word):
429 args, kvargs = parse_args(word)
430 return link_tag(*args, **kvargs)
432 def _inl_repl(self, word):
433 args, kvargs = parse_args(word)
437 # This double div nonsense works around a limitation of the HTML block model
438 return '<div class="' + kvargs.get('class', 'thumb') + '">' \
439 + '<div class="innerthumb">' \
440 + link_inline_glob(name, descr, kvargs) \
441 + '<div class="caption">' + descr + '</div></div></div>'
443 return link_inline_glob(name, None, kvargs)
445 def _html_repl(self, word):
446 if not self.in_html and word.startswith('<div'): word = '</p>' + word
448 return word; # Pass through
450 def _htmle_repl(self, word):
452 if not self.in_html and word.startswith('</div'): word += '<p>'
453 return word; # Pass through
455 def _ent_repl(self, s):
457 return s; # Pass through
458 return {'&': '&',
462 def _img_repl(self, word): # LEGACY
463 return self._inl_repl('{{' + word + '}}')
465 def _word_repl(self, word): # LEGACY
466 if self.in_html: return word # pass through
467 return link_tag(word)
469 def _url_repl(self, word): # LEGACY
470 if self.in_html: return word # pass through
471 return link_tag(word)
473 def _email_repl(self, word): # LEGACY
474 if self.in_html: return word # pass through
475 return '<a href="mailto:%s">%s</a>' % (word, word)
477 def _li_repl(self, match):
484 def _pre_repl(self, word):
485 if word == '{{{' and not self.in_pre:
493 def _hi_repl(self, word):
494 return '<strong class="highlight ' + word + '">' + word + '</strong>'
496 def _tr_repl(self, word):
498 if not self.in_table:
501 out = '</p><table><tbody>\n'
503 out = out + '<tr class="' + ['even', 'odd'][self.tr_cnt % 2] + '">'
504 return out + ['<td>', '<th>'][word.strip() == '||=']
506 def _td_repl(self, word):
508 return ['</td><td>', '</th><th>'][word.strip() == '||=']
511 def _tre_repl(self, word):
513 return ['</td></tr>', '</th></tr>'][word.strip() == '||=']
516 def _indent_level(self):
517 return len(self.list_indents) and self.list_indents[-1]
519 def _indent_to(self, new_level):
520 if self._indent_level() == new_level:
523 while self._indent_level() > new_level:
524 del(self.list_indents[-1])
527 self.in_li = False # FIXME
529 while self._indent_level() < new_level:
530 self.list_indents.append(new_level)
537 res += '</ul>' * len(self.list_indents)
539 self.list_indents = []
542 def replace(self, match):
543 for rule, hit in list(match.groupdict().items()):
545 return getattr(self, '_' + rule + '_repl')(hit)
547 raise Exception("Can't handle match " + repr(match))
549 def print_html(self):
550 print('<div class="wiki"><p>')
552 scan_re = re.compile(r"""(?:
553 # Styles and formatting ("--" must cling to a word to disambiguate it from the dash)
554 (?P<b> \*\* | // | \#\# | __ | --\b | \b-- | \^\^ | ,, | ''' | '' | `` )
558 | (?P<hi> \b( FIXME | TODO | DONE )\b )
562 | (?P<macro> \<\<([^\s\|\>]+)(?:\s*\|\s*([^\>]+)|)\>\>)
563 | (?P<hurl> \[\[([^\s\|]+)(?:\s*\|\s*([^\]]+)|)\]\])
566 | (?P<html> <(br|hr|div|span|form|iframe|input|textarea|a|img|h[1-5])\b )
567 | (?P<htmle> ( /\s*> | </(br|hr|div|span|form|iframe|input|textarea|a|img|h[1-5])> ) )
570 # Auto links (LEGACY)
571 | (?P<img> \b[a-zA-Z0-9_/-]+\.(""" + image_ext + "|" + video_ext + r"""))
572 | (?P<word> \b(?:[A-Z][a-z]+){2,}\b)
573 | (?P<url> (http|https|ftp|mailto)\:[^\s'\"]+\S)
574 | (?P<email> [-\w._+]+\@[\w.-]+)
576 # Lists, divs, spans and inline objects
577 | (?P<li> ^\s+[\*\#]\s+)
578 | (?P<pre> \{\{\{|\s*\}\}\})
579 | (?P<inl> \{\{([^\s\|]+)(?:\s*\|\s*([^\]]+)|)\}\})
582 | (?P<tr> ^\s*\|\|(=|)\s*)
583 | (?P<tre> \s*\|\|(=|)\s*$)
584 | (?P<td> \s*\|\|(=|)\s*)
586 # TODO: highlight search words (look at referrer)
588 pre_re = re.compile("""(?:
592 blank_re = re.compile(r"^\s*$")
593 indent_re = re.compile(r"^\s*")
594 tr_re = re.compile(r"^\s*\|\|")
595 eol_re = re.compile(r"\r?\n")
596 # For each line, we scan through looking for magic strings, outputting verbatim any intervening text
597 #3.0: for self.line in eol_re.split(str(self.raw.expandtabs(), 'utf-8')):
598 for self.line in eol_re.split(str(self.raw.expandtabs())):
601 if self.line.startswith('#'):
603 self.in_header = False
606 print(re.sub(pre_re, self.replace, self.line))
608 if self.in_table and not tr_re.match(self.line):
609 self.in_table = False
610 print('</tbody></table><p>')
612 if blank_re.match(self.line):
615 indent = indent_re.match(self.line)
616 #3.0: print(self._indent_to(len(indent.group(0))), end=' ')
617 print(self._indent_to(len(indent.group(0))))
618 print(re.sub(scan_re, self.replace, self.line))
620 if self.in_pre: print('</pre>')
621 if self.in_table: print('</tbody></table><p>')
622 print(self._undent())
626 def __init__(self, page_name):
627 self.page_name = page_name
629 self.msg_type = 'error'
631 def split_title(self):
632 # look for the end of words and the start of a new word and insert a space there
633 return re.sub('([a-z])([A-Z])', r'\1 \2', self.page_name)
636 return os.path.join(config_get('data_dir', 'data'), self.page_name)
638 def _tmp_filename(self):
639 return os.path.join(config_get('data_dir', 'data'), ('#' + self.page_name.replace('/','_') + '.' + str(os.getpid()) + '#'))
643 os.stat(self._filename())
646 if err.errno == errno.ENOENT:
650 def get_raw_body(self, default=None):
652 return open(self._filename(), 'rb').read()
654 if err.errno == errno.ENOENT:
656 default = '//[[?a=edit&q=%s|Describe %s]]//' % (self.page_name, self.page_name)
658 if err.errno == errno.EISDIR:
659 return self.format_dir()
662 def format_dir(self):
665 for dirname in self.page_name.strip('/').split('/'):
666 pathname = (pathname + '/' + dirname) if pathname else dirname
667 out += '[[' + pathname + '|' + dirname + ']]/'
670 for filename in page_list(self._filename(), file_re):
671 if image_re.match(filename):
672 maxwidth = config_get(image_maxwidth, '')
674 maxwidth = ' | maxwidth=' + str(maxwidth)
675 out += '{{' + self.page_name + '/' + filename + ' | ' + humanlink(filename) + maxwidth + ' | class=thumbleft}}\n'
677 out += ' * [[' + self.page_name + '/' + filename + ']]\n'
681 if not '_pragmas' in self.__dict__:
684 file = open(self._filename(), 'rt')
685 attr_re = re.compile(r"^#(\S*)(.*)$")
687 m = attr_re.match(line)
690 self._pragmas[m.group(1)] = m.group(2).strip()
691 #print "bernie: pragmas[" + m.group(1) + "] = " + m.group(2) + "<br>\n"
693 if err.errno != errno.ENOENT and err.errno != errno.EISDIR:
697 def pragma(self, name, default):
698 return self.pragmas().get(name, default)
700 def can(self, action, default=True):
703 #acl SomeUser:read,write All:read
704 acl = self.pragma("acl", None)
705 for rule in acl.split():
706 (user, perms) = rule.split(':')
707 if user == remote_user() or user == "All":
708 return action in perms.split(',')
712 self.msg_text = 'Illegal acl line: ' + acl
716 return self.can("write", True)
719 return self.can("read", True)
721 def send_naked(self, kvargs=None):
723 WikiFormatter(self.get_raw_body(), kvargs).print_html()
725 send_guru("Read access denied by ACLs", "notice")
729 value = self.pragma("css", None)
732 link_urls += [ [ "stylesheet", value ] ]
734 send_title(self.page_name, self.split_title(),
735 msg_text=self.msg_text, msg_type=self.msg_type, writable=self.can_write())
737 send_footer(self._last_modified())
739 def _last_modified(self):
741 from time import localtime, strftime
742 modtime = localtime(os.stat(self._filename())[stat.ST_MTIME])
744 if err.errno != errno.ENOENT:
747 return strftime(config_get(datetime_fmt, '%a %d %b %Y %I:%M %p'), modtime)
749 def send_editor(self, preview=None):
750 send_title(None, 'Edit ' + self.split_title(), msg_text=self.msg_text, msg_type=self.msg_type)
751 if not self.can_write():
752 send_guru("Write access denied by ACLs", "error")
756 preview = self.get_raw_body(default='')
758 link_inline("sys/EditPage", kvargs = {
759 'EDIT_BODY': cgi.escape(preview),
760 #'EDIT_PREVIEW': WikiFormatter(preview).print_html(),
764 print("<div class='preview'>")
765 WikiFormatter(preview).print_html()
769 def send_raw(self, mimetype='text/plain', args=[]):
770 if not self.can_read():
771 send_title(None, msg_text='Read access denied by ACLs', msg_type='notice')
774 if 'maxwidth' in args:
776 emit_header(mimetype)
778 subprocess.check_call(['gm', 'convert', self._filename(),
779 '-scale', args['maxwidth'].value + ' >', '-'])
781 body = self.get_raw_body()
782 emit_header(mimetype)
785 def _write_file(self, data):
786 tmp_filename = self._tmp_filename()
787 open(tmp_filename, 'wb').write(data)
788 name = self._filename()
790 # Bad Bill! POSIX rename ought to replace. :-(
794 if err.errno != errno.ENOENT: raise err
795 path = os.path.split(name)[0]
796 if not os.path.exists(path):
798 os.rename(tmp_filename, name)
800 def save(self, newdata, changelog):
801 if not self.can_write():
802 self.msg_text = 'Write access denied by ACLs'
803 self.msg_type = 'error'
806 self._write_file(newdata)
808 if config_get('post_edit_hook'):
811 config_get('post_edit_hook'),
812 os.path.join(config_get('data_dir', 'data'), self.page_name), remote_user(),
813 remote_host(), changelog ]
814 child = subprocess.Popen(cmd, stdout=subprocess.PIPE, close_fds=True)
815 output = child.stdout.read()
818 self.msg_text += "Post-editing hook returned %d. Command was:\n'%s'\n" % (rc, "' '".join(cmd))
820 self.msg_text += 'Output follows:\n' + output
822 self.msg_text = 'Thank you for your contribution. Your attention to detail is appreciated.'
823 self.msg_type = 'success'
826 exec(open("geekigeeki.conf.py").read())
827 form = cgi.FieldStorage()
828 action = form.getvalue('a', 'get')
829 handler = globals().get('handle_' + action)
831 handler(query_string(), form)
833 send_httperror("403 Forbidden", query_string())
837 msg_text = traceback.format_exc()
839 send_guru(msg_text, "error")
841 send_title(None, msg_text=msg_text)