projects
/
geekigeeki.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
692a363
)
Factor out file extensions
author
Bernie Innocenti
<bernie@codewiz.org>
Sat, 2 May 2009 11:02:41 +0000
(13:02 +0200)
committer
Bernie Innocenti
<bernie@codewiz.org>
Sat, 2 May 2009 11:03:04 +0000
(13:03 +0200)
geekigeeki.py
patch
|
blob
|
history
diff --git
a/geekigeeki.py
b/geekigeeki.py
index 0b8e422c199a3cd4230e42859e0ed981e3776df9..5b98397af612e174205412d723ed251dfa82ed39 100755
(executable)
--- a/
geekigeeki.py
+++ b/
geekigeeki.py
@@
-26,13
+26,14
@@
title_done = False
import cgi, sys, os, re, errno, stat
import cgi, sys, os, re, errno, stat
-# FIXME: we accept stuff like foo/../bar and we shouldn't
-file_re = re.compile(r"([A-Za-z0-9_\-][A-Za-z0-9_\.\-/]*)")
+image_ext = 'png|gif|jpg|jpeg|bmp|ico'
video_ext = "ogg|ogv|oga" # Not supported by Firefox 3.5: mkv|mpg|mpeg|mp4|avi|asf|flv|wmv|qt
video_ext = "ogg|ogv|oga" # Not supported by Firefox 3.5: mkv|mpg|mpeg|mp4|avi|asf|flv|wmv|qt
-im
g_re = re.compile(r".*\.(png|gif|jpg|jpeg|bmp|ico
|" + video_ext + ")", re.IGNORECASE)
+im
age_re = re.compile(r".*\.(" + image_ext + "
|" + video_ext + ")", re.IGNORECASE)
video_re = re.compile(r".*\.(" + video_ext + ")", re.IGNORECASE)
video_re = re.compile(r".*\.(" + video_ext + ")", re.IGNORECASE)
-url_re = re.compile(r"[a-z]{3,8}://[^\s'\"]+\S")
-ext_re = re.compile(r"\.([^\./]+)$")
+# FIXME: we accept stuff like foo/../bar and we shouldn't
+file_re = re.compile(r"([A-Za-z0-9_\-][A-Za-z0-9_\.\-/]*)")
+url_re = re.compile(r"[a-z]{3,8}://[^\s'\"]+\S")
+ext_re = re.compile(r"\.([^\./]+)$")
# CGI stuff ---------------------------------------------------------
def script_name():
# CGI stuff ---------------------------------------------------------
def script_name():
@@
-198,7
+199,7
@@
def send_httperror(status="403 Not Found", query=""):
def link_tag(dest, text=None, privileged=False, **kvargs):
if text is None:
text = humanlink(dest)
def link_tag(dest, text=None, privileged=False, **kvargs):
if text is None:
text = humanlink(dest)
- elif im
g
_re.match(text):
+ elif im
age
_re.match(text):
text = '<img border="0" src="' + relative_url(text) + '" alt="' + text + '" />'
link_class = kvargs.get('class', kvargs.get('cssclass', None))
text = '<img border="0" src="' + relative_url(text) + '" alt="' + text + '" />'
link_class = kvargs.get('class', kvargs.get('cssclass', None))
@@
-223,7
+224,7
@@
def link_inline(name, descr=None, kvargs={}):
url = relative_url(name)
if video_re.match(name):
return '<video controls="1" src="%s">Your browser does not support the HTML5 video tag</video>' % url
url = relative_url(name)
if video_re.match(name):
return '<video controls="1" src="%s">Your browser does not support the HTML5 video tag</video>' % url
- elif im
g
_re.match(name):
+ elif im
age
_re.match(name):
return '<a href="%s"><img border="0" src="%s" alt="%s" /></a>' % (url, url + url_args(kvargs), descr)
elif file_re.match(name) and not ext_re.search(name): # FIXME: this guesses a wiki page
return Page(name).send_naked()
return '<a href="%s"><img border="0" src="%s" alt="%s" /></a>' % (url, url + url_args(kvargs), descr)
elif file_re.match(name) and not ext_re.search(name): # FIXME: this guesses a wiki page
return Page(name).send_naked()
@@
-550,7
+551,7
@@
class WikiFormatter:
| (?P<ent> [<>&] )
# Auto links (LEGACY)
| (?P<ent> [<>&] )
# Auto links (LEGACY)
- | (?P<img> \b[a-zA-Z0-9_/-]+\.(
png|gif|jpg|jpeg|bmp|ico|ogm|ogg|mkv|mpg|mpeg|mp4|avi|asf|flv|wmv|qt
))
+ | (?P<img> \b[a-zA-Z0-9_/-]+\.(
""" + image_ext + "|" + video_ext + r"""
))
| (?P<word> \b(?:[A-Z][a-z]+){2,}\b)
| (?P<url> (http|https|ftp|mailto)\:[^\s'\"]+\S)
| (?P<email> [-\w._+]+\@[\w.-]+)
| (?P<word> \b(?:[A-Z][a-z]+){2,}\b)
| (?P<url> (http|https|ftp|mailto)\:[^\s'\"]+\S)
| (?P<email> [-\w._+]+\@[\w.-]+)
@@
-650,7
+651,7
@@
class Page:
out += ' ==\n'
for filename in page_list(self._filename(), file_re):
out += ' ==\n'
for filename in page_list(self._filename(), file_re):
- if im
g
_re.match(filename):
+ if im
age
_re.match(filename):
if image_maxwidth:
maxwidth_arg = ' | maxwidth=' + str(image_maxwidth)
out += '{{' + self.page_name + '/' + filename + ' | ' + humanlink(filename) + maxwidth_arg + ' | class=thumbleft}}\n'
if image_maxwidth:
maxwidth_arg = ' | maxwidth=' + str(image_maxwidth)
out += '{{' + self.page_name + '/' + filename + ' | ' + humanlink(filename) + maxwidth_arg + ' | class=thumbleft}}\n'