[cvs-annodex] commit (annodex): cmmlwiki/trunk/cgi-bin/cmmlwiki.cgi
cmmlwiki/trunk/cmmlwiki/handler.py
cmmlwiki/trunk/cmmlwiki/redirect.py
cmmlwiki/trunk/cmmlwiki/response.py cmmlwiki/trunk/cmmlwiki/story.py
cmmlwiki/trunk/cmmlwiki/utils.py
+cmmlwiki/trunk/cmmlwiki/location.py
conrad
nobody at lists.annodex.net
Fri May 12 17:59:35 EST 2006
Update of /var/local/lib/svn/annodex (new revision 2252)
Added files:
cmmlwiki/trunk/cmmlwiki/location.py
Modified files:
cmmlwiki/trunk/cgi-bin/cmmlwiki.cgi
cmmlwiki/trunk/cmmlwiki/handler.py
cmmlwiki/trunk/cmmlwiki/redirect.py
cmmlwiki/trunk/cmmlwiki/response.py
cmmlwiki/trunk/cmmlwiki/story.py
cmmlwiki/trunk/cmmlwiki/utils.py
Log Message:
add a Location class that can be handled by Response, use for all redirects
Modified: cmmlwiki/trunk/cgi-bin/cmmlwiki.cgi
===================================================================
--- cmmlwiki/trunk/cgi-bin/cmmlwiki.cgi 2006-05-12 07:39:01 UTC (rev 2251)
+++ cmmlwiki/trunk/cgi-bin/cmmlwiki.cgi 2006-05-12 07:59:34 UTC (rev 2252)
@@ -75,7 +75,8 @@
o = handler.list_images ()
sys.stdout.write(Response(o).__str__())
elif (command == "Search"):
- handler.query ()
+ o = handler.query ()
+ sys.stdout.write(Response(o).__str__())
elif (command == "Story"):
try:
story_id = path_bits[1]
@@ -104,7 +105,8 @@
o = HTMLPage(StoryEdit(handler, story_id))
sys.stdout.write(Response(o).__str__())
elif (command == "SaveStory"):
- story.save (handler)
+ o = story.save (handler)
+ sys.stdout.write(Response(o).__str__())
elif (command == "DeleteStory"):
try:
story_id = path_bits[1]
@@ -114,14 +116,16 @@
o = handler.main_page ()
sys.stdout.write(Response(o).__str__())
elif (command == "SaveMedia"):
- handler.save_media ()
+ o = handler.save_media ()
+ sys.stdout.write(Response(o).__str__())
elif (command == "DeleteItem"):
o = handler.delete_item ()
sys.stdout.write(Response(o).__str__())
elif (command == "RenameItem"):
try:
iname = path_bits[1]
- handler.rename_item (iname)
+ o = handler.rename_item (iname)
+ sys.stdout.write(Response(o).__str__())
except:
o = handler.error ('Request %s failed' % (command))
sys.stdout.write(Response(o).__str__())
@@ -132,7 +136,8 @@
o = handler.delete_clip()
sys.stdout.write(Response(o).__str__())
elif (command == "AnchorURL"):
- handler.update_field ('a_href')
+ o = handler.update_field ('a_href')
+ sys.stdout.write(Response(o).__str__())
else:
o = handler.error ('Invalid request %s' % (command))
sys.stdout.write(Response(o).__str__())
@@ -182,7 +187,10 @@
path0 = ""
ext = ""
- if (not redirect (path0, ext)):
+ o = redirect (path0, ext)
+ if (o):
+ sys.stdout.write(Response(o).__str__())
+ else:
cmd_bits = split (path0, ':')
Modified: cmmlwiki/trunk/cmmlwiki/handler.py
===================================================================
--- cmmlwiki/trunk/cmmlwiki/handler.py 2006-05-12 07:39:01 UTC (rev 2251)
+++ cmmlwiki/trunk/cmmlwiki/handler.py 2006-05-12 07:59:34 UTC (rev 2252)
@@ -27,9 +27,10 @@
from cmmlwiki.environment import Environment
from cmmlwiki.html import html_head, html_foot, listpanel_head, listpanel_foot
from cmmlwiki.http404 import HTTP404
+from cmmlwiki.location import Location
from cmmlwiki.time import time2npt, parseTimestamp, sql2httpdate
from cmmlwiki.redirect import redirect_add
-from cmmlwiki.utils import content_type, content_type_html, location, xmlescape, wikiurl, iname2html, iname2play
+from cmmlwiki.utils import content_type, content_type_html, xmlescape, wikiurl, iname2html, iname2play
from cmmlwiki.response import Response
from cmmlwiki.htmlpage import HTMLPage
@@ -93,12 +94,12 @@
query_type = 'Go'
if (query_type == 'Go'):
- location (iname2html (query))
+ return Location (iname2html (query))
else:
s = Search(self.inspector, query, start)
- sys.stdout.write(Response(HTMLPage(s)).__str__())
+ return HTMLPage(s)
except KeyError:
- location (wikiurl())
+ return Location (wikiurl())
def create_item (self):
s = """
@@ -162,7 +163,7 @@
cmmlwiki.item.add (env, self.iname, filename, autoscan=True)
- location (iname2html (self.iname))
+ return Location (iname2html (self.iname))
def delete_item (self):
@@ -239,7 +240,7 @@
try:
newname = self.form['newname'].value
redirect_add (oldname, newname)
- location (iname2html (newname))
+ return Location (iname2html (newname))
except KeyError:
s = """
@@ -268,7 +269,7 @@
</form>
""" % (wikiurl('Edit:RenameItem/%s' % oldname), oldname, oldname)
- sys.stdout.write(Response(HTMLPage(s, title="Rename Item")).__str__())
+ return HTMLPage(s, title="Rename Item")
def edit(self):
@@ -376,7 +377,7 @@
con.commit()
con.close()
- location (wikiurl('Edit:Clip/%s?ixc=%s' % (self.iname, values['ixc'])))
+ return Location (wikiurl('Edit:Clip/%s?ixc=%s' % (self.iname, values['ixc'])))
def delete_clip (self):
vals = {}
Added: cmmlwiki/trunk/cmmlwiki/location.py
===================================================================
--- cmmlwiki/trunk/cmmlwiki/location.py 2006-05-12 07:39:01 UTC (rev 2251)
+++ cmmlwiki/trunk/cmmlwiki/location.py 2006-05-12 07:59:34 UTC (rev 2252)
@@ -0,0 +1,24 @@
+# -*- coding: iso8859-1 -*-
+#
+# Copyright (C) 2005 CSIRO Australia
+# All rights reserved.
+#
+# This software is licensed as described in the file COPYING, which
+# you should have received as part of this distribution.
+#
+# This software consists of voluntary contributions made by many
+# individuals. For exact contribution history, see the revision
+# history and logs.
+#
+# Author: Conrad Parker <conrad at annodex.net>
+
+class Location (object):
+
+ def __init__ (self, location):
+ self.url = location
+
+ def status (self):
+ return '303 See Other'
+
+ def location (self):
+ return self.url
Modified: cmmlwiki/trunk/cmmlwiki/redirect.py
===================================================================
--- cmmlwiki/trunk/cmmlwiki/redirect.py 2006-05-12 07:39:01 UTC (rev 2251)
+++ cmmlwiki/trunk/cmmlwiki/redirect.py 2006-05-12 07:59:34 UTC (rev 2252)
@@ -17,7 +17,7 @@
from cmmlwiki.database import inspect
from cmmlwiki.environment import Environment
-from cmmlwiki.utils import location
+from cmmlwiki.location import Location
def redirect (wikiname, ext):
def wiki_redirect (oldname, newname):
@@ -41,7 +41,7 @@
query_string = '?' + query_string
new_location = method + server_name + server_port + script_name + '/' + newname + ext + query_string
- location(new_location)
+ return Location(new_location)
# Begin
inspector = inspect ()
@@ -55,11 +55,9 @@
oldname = row['oldname']
newname = row['newname']
- wiki_redirect (oldname, newname)
-
- return True
+ return wiki_redirect (oldname, newname)
except:
- return False
+ return None
def redirect_add (oldname, newname):
Modified: cmmlwiki/trunk/cmmlwiki/response.py
===================================================================
--- cmmlwiki/trunk/cmmlwiki/response.py 2006-05-12 07:39:01 UTC (rev 2251)
+++ cmmlwiki/trunk/cmmlwiki/response.py 2006-05-12 07:59:34 UTC (rev 2252)
@@ -23,17 +23,26 @@
def __str__(self):
s = ''
+ try:
+ s += 'Status: ' + self.o.status() + '\n'
+ except AttributeError:
+ pass
+
+ try:
+ s += 'Location: ' + self.o.location() + '\n'
+
+ # Return early if this is a redirection
+ s += '\n'
+ return s
+ except AttributeError:
+ pass
+
content_type = self.o.content_type()
content = self.o.__str__()
content_length = len(content)
etag = base64.encodestring(md5(content).digest())[:-1]
try:
- s += 'Status: ' + self.o.status() + '\n'
- except AttributeError:
- pass
-
- try:
s += 'Last-Modified: ' + self.o.last_modified() + '\n'
except AttributeError:
pass
Modified: cmmlwiki/trunk/cmmlwiki/story.py
===================================================================
--- cmmlwiki/trunk/cmmlwiki/story.py 2006-05-12 07:39:01 UTC (rev 2251)
+++ cmmlwiki/trunk/cmmlwiki/story.py 2006-05-12 07:59:34 UTC (rev 2252)
@@ -18,9 +18,10 @@
from cmmlwiki.autocomplete import AutoItemsForm
from cmmlwiki.environment import Environment
+from cmmlwiki.location import Location
from cmmlwiki.pagenumbers import PageNumbers
from cmmlwiki.time import sql2httpdate
-from cmmlwiki.utils import content_type_html, wikiurl, location, iname2frame, url2html, url2play, xmlescape
+from cmmlwiki.utils import content_type_html, wikiurl, iname2frame, url2html, url2play, xmlescape
def dict_map (f, dict):
new_dict = {}
@@ -169,7 +170,7 @@
con.commit()
con.close()
- location (wikiurl ('Special:Story/%s' % id))
+ return Location (wikiurl ('Special:Story/%s' % id))
class Story(object):
def __init__(self, handler, story_id):
Modified: cmmlwiki/trunk/cmmlwiki/utils.py
===================================================================
--- cmmlwiki/trunk/cmmlwiki/utils.py 2006-05-12 07:39:01 UTC (rev 2251)
+++ cmmlwiki/trunk/cmmlwiki/utils.py 2006-05-12 07:59:34 UTC (rev 2252)
@@ -30,11 +30,6 @@
def content_type_html (flush=True):
content_type ("text/html; charset=utf-8", flush)
-def location (loc):
- print "Status: 303 See Other"
- print "Location: %s" % loc
- flush_headers()
-
def xmlescape (str):
try:
s = escape (str)
--
conrad
More information about the cvs-annodex
mailing list