X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=geekigeeki.py;h=470752de0d44076f31272693a206bf0a1ed9cdc2;hb=0a5c27be02429f5fb00be79c4e11b70666713530;hp=4d50a3af5c0fd4aa29c24ec1918e59f801a2d047;hpb=41e94725555d64df1b6e56ffd29a733c28e0bfdf;p=geekigeeki.git
diff --git a/geekigeeki.py b/geekigeeki.py
index 4d50a3a..470752d 100755
--- a/geekigeeki.py
+++ b/geekigeeki.py
@@ -79,7 +79,7 @@ def permalink(s):
return re.sub(' ', '-', re.sub('[^a-z0-9_ ]', '', s.lower()).strip())
def humanlink(s):
- return re.search('([^:/\.]+)(?:\.[^/:]+|)$', s).group(1).replace('_', ' ')
+ return re.sub(r'([^:/\.]+)(?:\.[^/:]+|)$', r'\1', s.replace('_', ' '))
# Split arg lists like "blah| blah blah| width=100 | align = center",
# return a list containing anonymous arguments and a map containing the named arguments
@@ -87,10 +87,10 @@ def parse_args(s):
args = []
kwargs = {}
for arg in s.strip('<[{}]>').split('|'):
- try:
- key, val = arg.split('=', 1)
- kwargs[key.strip()] = val.strip()
- except ValueError:
+ m = re.match('\s*(\w+)\s*=\s*(.+)\s*', arg)
+ if m is not None:
+ kwargs[m.group(1)] = m.group(2)
+ else:
args.append(arg.strip())
return (args, kwargs)
@@ -161,24 +161,24 @@ def send_title(name, text="Limbo", msg_text=None, msg_type='error', writable=Fal
# Navbar
print('
')
- print link_tag('FrontPage', site_icon or 'Home', 'navlink')
+ print link_tag('FrontPage', site_icon or 'Home', cssclass='navlink')
if name:
- print('
' + link_tag('?fullsearch=' + name, text, 'navlink') + ' ')
+ print('
' + link_tag('?fullsearch=' + name, text, cssclass='navlink') + ' ')
else:
print('
' + text + ' ')
- print(' | ' + link_tag('FindPage', 'Find Page', 'navlink'))
+ print(' | ' + link_tag('FindPage', 'Find Page', cssclass='navlink'))
if 'history_url' in globals():
print(' |
Recent Changes')
if name:
print(' |
Page History')
if name:
- print(' | ' + link_tag('?raw=' + name, 'Raw Text', 'navlink'))
+ print(' | ' + link_tag(name + '?a=raw', 'Raw Text', cssclass='navlink'))
if privileged_url is not None:
if writable:
- print(' | ' + link_tag('?a=edit&q=' + name, 'Edit', 'navlink', privileged=True))
+ print(' | ' + link_tag('?a=edit&q=' + name, 'Edit', cssclass='navlink', privileged=True))
else:
- print(' | ' + link_tag(name, 'Login', 'navlink', privileged=True))
+ print(' | ' + link_tag(name, 'Login', cssclass='navlink', privileged=True))
else:
print(' |
Immutable Page')
@@ -194,27 +194,28 @@ def send_httperror(status="403 Not Found", query=""):
send_title(None, msg_text=("%s: on query '%s'" % (status, query)))
send_footer()
-def link_tag(params, text=None, link_class=None, privileged=False, **kvargs):
+def link_tag(dest, text=None, privileged=False, **kvargs):
if text is None:
- text = humanlink(params)
+ text = humanlink(dest)
elif img_re.match(text):
text = '
'
+ link_class = kvargs.get('class', kvargs.get('cssclass', None))
if not link_class:
- if is_external_url(params):
+ if is_external_url(dest):
link_class = 'external'
- elif file_re.match(params) and Page(params).exists():
+ elif file_re.match(dest) and Page(dest).exists():
link_class = 'wikilink'
else:
- params = nonexist_pfx + params
+ text = nonexist_pfx + text
link_class = 'nonexistent'
- classattr = 'class="%s" ' % link_class
# Prevent crawlers from following links potentially added by spammers or to generated pages
+ nofollow = ''
if link_class == 'external' or link_class == 'navlink':
- classattr += 'rel="nofollow"'
+ nofollow = 'rel="nofollow" '
- return '
%s' % (classattr, relative_url(params, privileged=privileged), text)
+ return '
%s' % (link_class, nofollow, relative_url(dest, privileged=privileged), text)
def link_inline(name, descr=None, kvargs={}):
if not descr: descr = humanlink(name)
@@ -323,7 +324,7 @@ def make_index_key():
links = ['
%s' % (ch, ch) for ch in 'abcdefghijklmnopqrstuvwxyz']
return '
' + ' | '.join(links) + '
'
-def page_list(dirname = None, re = None):
+def page_list(dirname=None, re=None):
if re is None:
# FIXME: WikiWord is too restrictive now!
re = re.compile(r"^\b((([A-Z][a-z0-9]+){2,}/)*([A-Z][a-z0-9]+){2,})\b$")
@@ -622,7 +623,7 @@ class Page:
try:
os.stat(self._filename())
return True
- except OSError as err:
+ except OSError, err:
if err.errno == errno.ENOENT:
return False
raise err
@@ -630,7 +631,7 @@ class Page:
def get_raw_body(self, default=None):
try:
return open(self._filename(), 'rb').read()
- except IOError as err:
+ except IOError, err:
if err.errno == errno.ENOENT:
if default is None:
default = '//[[%s|Describe %s|action=edit]]//' % (self.page_name, self.page_name)
@@ -668,7 +669,7 @@ class Page:
break
self._pragmas[m.group(1)] = m.group(2).strip()
#print "bernie: pragmas[" + m.group(1) + "] = " + m.group(2) + "
\n"
- except IOError as err:
+ except IOError, err:
if err.errno != errno.ENOENT and err.errno != errno.EISDIR:
raise er
return self._pragmas
@@ -719,7 +720,7 @@ class Page:
try:
from time import localtime, strftime
modtime = localtime(os.stat(self._filename())[stat.ST_MTIME])
- except OSError as err:
+ except OSError, err:
if err.errno != errno.ENOENT:
raise err
return None
@@ -790,7 +791,7 @@ class Page:
# Bad Bill! POSIX rename ought to replace. :-(
try:
os.remove(name)
- except OSError as err:
+ except OSError, err:
if err.errno != errno.ENOENT: raise err
os.rename(tmp_filename, name)