diff --git a/web/controller.py b/web/controller.py index 2275733..5320d6e 100644 --- a/web/controller.py +++ b/web/controller.py @@ -7,7 +7,8 @@ import cherrypy from web.model import latest_per_day, \ build_centerpkg_list, \ - get_atom + get_atom, \ + NotValidAtom from web.lib.headers import lastmodified_httpheader, \ lastmodified_rightcontent from web.lib.query_filter import sanitize_query_string @@ -380,7 +381,11 @@ class Root(object): cat = args[0] pn = args[1] cpvstr = '%s/%s' % (cat, pn) - cpvtmp = get_atom(cpvstr) + try: + cpvtmp = get_atom(cpvstr) + except NotValidAtom: + raise cherrypy.HTTPRedirect("/") + pn = cpvtmp.package cat = cpvtmp.category pagetitle = "/package/%s/%s" % (cat, pn) diff --git a/web/model.py b/web/model.py index 68ce012..97c4f1d 100644 --- a/web/model.py +++ b/web/model.py @@ -20,6 +20,12 @@ from web.lib.links import viewcvs_link, \ # We use short variable names! # pylint: disable-msg=C0103 +class NotValidAtom(Exception): + def __init__(self, value): + self.value = value + def __str__(self): + return repr('Not a valid package atom at all: %s' % self.value) + def get_atom(cpvstr): """Nasty hack to work around not knowing if an atom is versioned or not""" v_atom = u_atom = None @@ -41,7 +47,7 @@ def get_atom(cpvstr): if u_atom: return u_atom - raise Exception('Not a valid package atom at all: %s' % (cpvstr)) + raise NotValidAtom(cpvstr) def caller_name(): """Return the name of the function that this was called from"""