def __init__(self, dbname): if sys.version < '3': from psycopg2.extensions import register_type, UNICODE register_type(UNICODE) self.dbconn = DbConnection(dbname) self.film = FilmHandler(self.dbconn) self.url_map = Map([ Rule('/', endpoint='index'), Rule('/films', endpoint='film'), Rule('/film/<path:parts>', endpoint='film') ])
def __init__(self, dbname): if sys.version < '3': print("Please run under Python 3.x") sys.exit(1) self.dbconn = DbConnection(dbname) self.film = FilmHandler(self.dbconn) self.url_map = Map([ Rule('/', endpoint='index'), Rule('/films', endpoint='film'), Rule('/film/<path:parts>', endpoint='film') ])
class DatabaseApp(object): def __init__(self, dbname): if sys.version < '3': print("Please run under Python 3.x") sys.exit(1) self.dbconn = DbConnection(dbname) self.film = FilmHandler(self.dbconn) self.url_map = Map([ Rule('/', endpoint='index'), Rule('/films', endpoint='film'), Rule('/film/<path:parts>', endpoint='film') ]) def index(self, request): return render('home.html') def error404(self, msg=''): return render('error/404.html', msg=str(msg)) def dispatch(self, request): adapter = self.url_map.bind_to_environ(request.environ) try: endpoint, values = adapter.match() if endpoint == 'index': return getattr(self, endpoint)(request, **values) else: return self.film.dispatch(request) except NotFound as exc: response = self.error404(exc.description) response.status_code = 404 return response except HTTPException as exc: return exc def wsgi_app(self, environ, start_response): req = Request(environ) response = self.dispatch(req) return response(environ, start_response) def __call__(self, environ, start_response): return self.wsgi_app(environ, start_response)
class DatabaseApp(object): def __init__(self, dbname): if sys.version < '3': from psycopg2.extensions import register_type, UNICODE register_type(UNICODE) self.dbconn = DbConnection(dbname) self.film = FilmHandler(self.dbconn) self.url_map = Map([ Rule('/', endpoint='index'), Rule('/films', endpoint='film'), Rule('/film/<path:parts>', endpoint='film') ]) def index(self, request): return render('home.html') def error404(self, msg=''): return render('error/404.html', msg=str(msg)) def dispatch(self, request): adapter = self.url_map.bind_to_environ(request.environ) try: endpoint, values = adapter.match() if endpoint == 'index': return getattr(self, endpoint)(request, **values) else: return self.film.dispatch(request) except NotFound as exc: response = self.error404(exc.description) response.status_code = 404 return response except HTTPException as exc: return exc def wsgi_app(self, environ, start_response): req = Request(environ) response = self.dispatch(req) return response(environ, start_response) def __call__(self, environ, start_response): return self.wsgi_app(environ, start_response)
class DatabaseApp(object): def __init__(self, dbname): if sys.version < '3': from psycopg2.extensions import register_type, UNICODE register_type(UNICODE) self.dbconn = DbConnection(dbname) self.film = FilmHandler(self.dbconn) def menu(self): while True: for cmd in ['Films', 'Quit']: print(' %s - %s' % (cmd[:1], cmd)) cmd = raw_input("Command? ").upper()[:1] if cmd == 'Q': break elif cmd == 'F': if self.film.menu() == 'Q': break else: print("Invalid choice") self.dbconn.close() print "Done"
class DatabaseApp(object): def __init__(self, dbname): if sys.version < '3': print("Please run under Python 3.x") sys.exit(1) self.dbconn = DbConnection(dbname) self.film = FilmHandler(self.dbconn) def menu(self): while True: for cmd in ['Films', 'Quit']: print(' %s - %s' % (cmd[:1], cmd)) cmd = input("Command? ").upper()[:1] if cmd == 'Q': break elif cmd == 'F': if self.film.menu() == 'Q': break else: print("Invalid choice") self.dbconn.close() print("Done")
def __init__(self, dbname): if sys.version < '3': from psycopg2.extensions import register_type, UNICODE register_type(UNICODE) self.dbconn = DbConnection(dbname) self.film = FilmHandler(self.dbconn)
def __init__(self, dbname): if sys.version < '3': print("Please run under Python 3.x") sys.exit(1) self.dbconn = DbConnection(dbname) self.film = FilmHandler(self.dbconn)