@@ -19,6 +19,7 @@ def __init__(self, db, urls):
1919
2020 def __call__ (self , environ , start_response ):
2121 headers = [('Content-type' , 'text/html' )]
22+ import pdb ; pdb .set_trace ( )
2223 try :
2324 path = environ .get ('PATH_INFO' , None )
2425 if path is None :
@@ -44,9 +45,9 @@ def __call__(self, environ, start_response):
4445 def books (self ):
4546 core = ['<h1>Book Database</h1>' ,
4647 '<ul>' ]
47- tmpl = '<li><a href="http://github.com/book/%s">%s</a></li>'
48- for book_id , book_data in self .db .items ():
49- core .append (tmpl % ( book_id , book_data [ 'title' ]) )
48+ tmpl = '<li><a href="http://github.com/book/%%3Cspan%20class="x x-first x-last">(id) s">%(title) s</a></li>'
49+ for data in self .db .titles ():
50+ core .append (tmpl % data )
5051 core .append ('</ul>' )
5152 body = "\n " .join (core )
5253 context = {'page_title' : "Book Database" ,
@@ -66,9 +67,10 @@ def book(self, id):
6667</dl>
6768<p><a href="../">More Books</a></p>
6869"""
69- book = self .db .get (id , None )
70- if book is None :
71- raise NameError
70+ try :
71+ book = self .db .title_info (id )
72+ except KeyError :
73+ raise NameError ('book not found' )
7274 title = "Book Database: %s" % book ['isbn' ]
7375 context = {'page_title' : title ,
7476 'page_body' : tmpl % book }
@@ -99,7 +101,7 @@ def _get_callable(self, path):
99101 # this block will be called when the script is run directly
100102 from wsgiref .simple_server import make_server
101103 import bookdb
102- application = MyApplication (bookdb .database , URLS )
104+ application = MyApplication (bookdb .BookDB () , URLS )
103105 srv = make_server ('localhost' , 8080 , application )
104106 srv .serve_forever ()
105107else :
@@ -114,4 +116,4 @@ def _get_callable(self, path):
114116 import sys
115117 sys .path .append ('/path/to/directory/containing/bookdb/on/server' )
116118 import bookdb
117- application = MyApplication (bookdb .database , URLS )
119+ application = MyApplication (bookdb .BookDB () , URLS )
0 commit comments