X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=geekigeeki.py;h=a1c99a02742b3a862e2590af9b64addcd40fe6a3;hb=4b551793f87baab929ddac359aa48b3eac34ac54;hp=e110d8dafe256395a021980b7d8813eb0fa5d58c;hpb=1549a288ad7fa65066b0b52739618c011898d2a3;p=geekigeeki.git diff --git a/geekigeeki.py b/geekigeeki.py index e110d8d..a1c99a0 100755 --- a/geekigeeki.py +++ b/geekigeeki.py @@ -1,8 +1,9 @@ -#! /usr/bin/env python +#!/usr/bin/python +# -*- coding: utf-8 -*- # # Copyright 1999, 2000 Martin Pool # Copyright 2002 Gerardo Poggiali -# Copyright 2007 Bernardo Innocenti +# Copyright 2007, 2008 Bernardo Innocenti # # 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 @@ -27,8 +28,8 @@ from os import path, environ # Regular expression defining a WikiWord # (but this definition is also assumed in other places) -file_re = re.compile(r"^\b([A-Za-z0-9_\.\-]+)\b$") -word_re = re.compile(r"^\b([A-Z][a-z]+){2,}\b$") +file_re = re.compile(r"^\b([A-Za-z0-9_\.\-/]+)\b$") +word_re = re.compile(r"^\b((([A-Z][a-z]+){2,}/)*([A-Z][a-z]+){2,})\b$") img_re = re.compile(r"^.*\.(png|gif|jpg|jpeg)$", re.IGNORECASE) url_re = re.compile(r"^[a-z]{3,8}://[^\s'\"]+\S$") @@ -59,6 +60,15 @@ def get_hostname(addr): except: return addr +def relative_url(path, privileged=False): + if not (url_re.match(path) or path.startswith('/')): + if privileged: + url = privileged_path() + else: + url = script_name() + path = url + '/' + path + return path + # Formatting stuff -------------------------------------------------- def emit_header(type="text/html"): @@ -74,7 +84,7 @@ def send_guru(msg, msg_type): if msg_type == 'error': print ' Guru Meditation #DEADBEEF.ABADC0DE' print '' - # FIXME: This simple JS snippet is harder to pass than ACID 3.0 + # FIXME: This little JS snippet is harder to pass than ACID 3.0 print """