redirect() , raise raise turbogears.redirect() OR raise cherrypy.HTTPRedirect()

24 views
Skip to first unread message

aspineux

unread,
Sep 26, 2006, 11:00:04 AM9/26/06
to TurboGears
I thing i found a small bug

In tutorial and code generated by quickstart I see

raise turbogears.redirect(url)

but turbogears.redirect(url) is already a call to raise
cherrypy.HTTPRedirect(url) !

def redirect(redirect_path, redirect_params=None, **kw):
"""Redirect (via cherrypy.HTTPRedirect)."""
raise cherrypy.HTTPRedirect(
url(tgpath=redirect_path, tgparams=redirect_params,
**kw))

I thing the good use is just a call to turbogeard.redirect() and not to
use a raise !
Both will do about the same, but why not do it correctly ?

any comment ?

Best regards

Alain

Jorge Vargas

unread,
Sep 26, 2006, 2:17:43 PM9/26/06
to turbo...@googlegroups.com
if you do it as a function call it's not obvious that the code is
doing a redirect. but yes I have to agree it seems redundant.

> Best regards
>
> Alain
>
>
> >
>

aspineux

unread,
Sep 26, 2006, 4:57:36 PM9/26/06
to TurboGears
Ok

So why no just return the object (replace the raise by a return)

def redirect(redirect_path, redirect_params=None, **kw):
"""Redirect (via cherrypy.HTTPRedirect)."""

return cherrypy.HTTPRedirect(
url(tgpath=redirect_path, tgparams=redirect_params,
**kw))

That way the correct usage is now :

raise turbogear.redirect(url)

as like used in tutorial and quickstart generated code.

Jorge Vargas

unread,
Sep 26, 2006, 6:33:41 PM9/26/06
to turbo...@googlegroups.com
On 9/26/06, aspineux <aspi...@gmail.com> wrote:
>
> Ok
>
> So why no just return the object (replace the raise by a return)
>
> def redirect(redirect_path, redirect_params=None, **kw):
> """Redirect (via cherrypy.HTTPRedirect)."""
> return cherrypy.HTTPRedirect(
> url(tgpath=redirect_path, tgparams=redirect_params,
> **kw))
>
> That way the correct usage is now :
>
can you please open a ticket

if you can supply a patch or just tell files/line numbers so we can
look into it closely there may be a reason we are ommiting here.

aspineux

unread,
Sep 26, 2006, 7:34:34 PM9/26/06
to TurboGears
I filled the ticket #1128.
Hope I did it well.

Jorge Vargas

unread,
Sep 26, 2006, 11:56:24 PM9/26/06
to turbo...@googlegroups.com
On 9/26/06, aspineux <aspi...@gmail.com> wrote:
>
> I filled the ticket #1128.
> Hope I did it well.
>
yes tk
>
> >
>

Kevin Dangoor

unread,
Sep 27, 2006, 4:59:17 PM9/27/06
to turbo...@googlegroups.com

This was a "bikeshed" moment from a few months ago. The code should
probably have a comment.

Some people thought that raise felt wrong and wanted to just call a
function. Many others, myself included, liked raise because it was
clearest that control flow is leaving your method immediately. Having
the raise in the redirect function didn't hurt the preferred use
"raise turbogears.redirect(...)" and still allowed the people who
didn't like the raise to do what they wished "turbogears.redirect(...)".

Kevin

Elvelind Grandin

unread,
Sep 28, 2006, 3:53:10 AM9/28/06
to turbo...@googlegroups.com
On 9/27/06, Kevin Dangoor <dan...@gmail.com> wrote:
>
> On Sep 26, 2006, at 4:57 PM, aspineux wrote:
>
> > So why no just return the object (replace the raise by a return)
> >
> > def redirect(redirect_path, redirect_params=None, **kw):
> > """Redirect (via cherrypy.HTTPRedirect)."""
> > return cherrypy.HTTPRedirect(
> > url(tgpath=redirect_path,
> > tgparams=redirect_params,
> > **kw))
> >
> > That way the correct usage is now :
> >
> > raise turbogear.redirect(url)
> >
> > as like used in tutorial and quickstart generated code.
>
> This was a "bikeshed" moment from a few months ago. The code should
> probably have a comment.

It has a comment about it now :)

> Some people thought that raise felt wrong and wanted to just call a
> function. Many others, myself included, liked raise because it was
> clearest that control flow is leaving your method immediately. Having
> the raise in the redirect function didn't hurt the preferred use
> "raise turbogears.redirect(...)" and still allowed the people who
> didn't like the raise to do what they wished "turbogears.redirect(...)".
>
> Kevin
>
> >
>


--
cheers
elvelind grandin

Kevin Dangoor

unread,
Sep 28, 2006, 11:36:32 AM9/28/06
to turbo...@googlegroups.com
On Sep 28, 2006, at 3:53 AM, Elvelind Grandin wrote:

>
> On 9/27/06, Kevin Dangoor <dan...@gmail.com> wrote:
>> This was a "bikeshed" moment from a few months ago. The code should
>> probably have a comment.
>
> It has a comment about it now :)

thanks!

Jorge Vargas

unread,
Sep 28, 2006, 7:17:00 PM9/28/06
to turbo...@googlegroups.com
On 9/28/06, Elvelind Grandin <elve...@gmail.com> wrote:
>
> On 9/27/06, Kevin Dangoor <dan...@gmail.com> wrote:
> >
> > On Sep 26, 2006, at 4:57 PM, aspineux wrote:
> >
> > > So why no just return the object (replace the raise by a return)
> > >
> > > def redirect(redirect_path, redirect_params=None, **kw):
> > > """Redirect (via cherrypy.HTTPRedirect)."""
> > > return cherrypy.HTTPRedirect(
> > > url(tgpath=redirect_path,
> > > tgparams=redirect_params,
> > > **kw))
> > >
> > > That way the correct usage is now :
> > >
> > > raise turbogear.redirect(url)
> > >
> > > as like used in tutorial and quickstart generated code.
> >
> > This was a "bikeshed" moment from a few months ago. The code should
> > probably have a comment.
>
> It has a comment about it now :)
>
so I guess I'll close 1128 as fixed
Reply all
Reply to author
Forward
0 new messages