Re: Multiple controller calls

2007-11-21 Thread Justin

  def test(self, var):
  id = var
  if int(id)  5:
  return 'GREATER THAN'
  else:
  return 'LESS THAN'

 You'll run into trouble here if var is '' or contains non-numeric
 characters.  Your default value in the routing rule is novar, which
 would raise a ValueError exception and ultimately a 500 Internal
 Server Error.  Since we can't trust users to always put numeric
 values, you should trap the case thus:

Yeah, I know. The novar default was left over from passing strings
to the page via querystring. Like I said I'm just throwing stuff at
the framework right now to kind of feel it out and get a grip on how
it handles stuff.

Just to rule out the possibility that I did somthing wierd I created a
new project, added a new controller (changed nothing, its index action
returns 'Hello World', and just add the line to by BaseController to
print out the class name and received almost the same result:

CtestController
TemplateController
ErrorController
TemplateController
ErrorController
TemplateController
ErrorController
TemplateController
ErrorController

 Does it make a difference if you omit the trailing slash?

Nope.

 You mean the error controller itself is failing to return a page?

Here's my new test BaseController on the old project:

fp = open('dump.txt', 'w')

class BaseController(WSGIController):

def __call__(self, environ, start_response):
Invoke the Controller
# WSGIController.__call__ dispatches to the Controller method
# the request is routed to. This routing information is
# available in environ['pylons.routes_dict']
fp.write(self.__class__.__name__ + ':\n\n')
try:
result = WSGIController.__call__(self, environ,
start_response)
fp.write('\n'.join(result) + '\n\n')
return result
finally:
Session.remove()

And here's the output file (sorry about the length):

HelloController:


GREATER THAN

TemplateController:

html

  headtitleNot Found/title/head

  body

h1Not Found/h1

pThe resource could not be found.

br/

!--  --/p

hr noshade

div align=rightWSGI Server/div

  /body

/html



TemplateController:

html

  headtitleNot Found/title/head

  body

h1Not Found/h1

pThe resource could not be found.

br/

!--  --/p

hr noshade

div align=rightWSGI Server/div

  /body

/html



TemplateController:

html

  headtitleNot Found/title/head

  body

h1Not Found/h1

pThe resource could not be found.

br/

!--  --/p

hr noshade

div align=rightWSGI Server/div

  /body

/html



ErrorController:


!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN http://
www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd
html xmlns=http://www.w3.org/1999/xhtml; xml:lang=en lang=en
head
 titleServer Error 404/title

style type=text/css
body {
  font-family: Helvetica, sans-serif;
}

table {
  width: 100%;
}

tr.header {
  background-color: #006;
  color: #fff;
}

tr.even {
  background-color: #ddd;
}

table.variables td {
  verticle-align: top;
  overflow: auto;
}

a.button {
  background-color: #ccc;
  border: 2px outset #aaa;
  color: #000;
  text-decoration: none;
}

a.button:hover {
  background-color: #ddd;
}

code.source {
  color: #006;
}

a.switch_source {
  color: #0990;
  text-decoration: none;
}

a.switch_source:hover {
  background-color: #ddd;
}

.source-highlight {
  background-color: #ff9;
}

/style

!-- CSS Imports --
link rel=stylesheet href=/error/style/orange.css type=text/css
media=screen /

!-- Favorite Icons --
link rel=icon href=/error/img/icon-16.png type=image/png /

style type=text/css
.red {
color:#FF;
}
.bold {
font-weight: bold;
}
/style

/head

body id=documentation
!-- We are only using a table to ensure old browsers see the message
correctly --

noscript
div style=border-bottom: 1px solid #808080
div style=border-bottom: 1px solid #404040
table width=100% border=0 cellpadding=0
bgcolor=#E1trtd valign=middleimg src=/error/img/
warning.gif alt=Warning //tdtdnbsp;/tdtdspan
style=padding: 0px; margin: 0px; font-family: Tahoma, sans-serif;
font-size: 11pxWarning, your browser does not support JavaScript so
you will not be able to use the interactive debugging on this page./
span/td/tr/table
/div
/div
/noscript

!-- Top anchor --
a name=top/a

!-- Logo --
h1 id=logoa class=no-underline href=http://
www.pylonshq.comimg class=no-border src=/error/img/logo.gif
alt=Pylons title=Pylons//a/h1
p class=invisiblea href=#contentSkip to content/a/p

!-- Main Content --

div id=nav-bar

!-- Section Navigation --
h4 class=invisibleSection Links/h4

ul id=navlist
li class=activea href=# accesskey=1
class=activeError 404/a/li
/ul
/div
div id=main-content

div class=hrhr class=hr //div

div class=content-padding

div id=main_data
 

Re: Multiple controller calls

2007-11-21 Thread Mike Orr

On Nov 21, 2007 5:35 AM, Justin [EMAIL PROTECTED] wrote:
 Just to rule out the possibility that I did somthing wierd I created a
 new project, added a new controller (changed nothing, its index action
 returns 'Hello World', and just add the line to by BaseController to
 print out the class name and received almost the same result:

 CtestController
 TemplateController
 ErrorController
 TemplateController
 ErrorController
 TemplateController
 ErrorController
 TemplateController
 ErrorController

 And here's the output file (sorry about the length):

As far as I can tell, the output looks correct.  TemplateController
returns a Not Found page which passes through the base controller and
is intercepted by the ErrorDocuments middleware, which makes its own
request for a fancy error page.

But as to your original question, why TemplateController is being
invoked at all, I can't tell.

There's a TransLogger middleware you can use to get an Apache-style
access log.  You can enable it in middleware like this:

from paste.translogger import TransLogger
app = TransLogger(app, setup_console_handler=True)

I've only had luck putting this *below* the error middleware, although
intuitively it seems it should be above.  The problem is that in one
position you don't get the original statuses and URLs, you get the
ones the error middleware has changed them to, which is not helpful
for debugging.

Anyway, if you setup the TransLogger and it shows multiple requests
for the same successful browser request, that will give a little more
light on what Template URL is being requested and why.

Alternatively, you could dump environ['PATH_INFO'] to your 'fp' file.
It may be worth dumping the entire environment actually, something
like:

import pprint;  fp.write(pprint.pformat(request.environ))

Things to look for are the URL and routing args that were in effect
when TemplateController was called.  The referer would also prove the
previous request called this one.  Then the mystery becomes, what in
the previous request caused this one?

You don't need to dump the output anymore, since it looks correct for
the controllers that were called.

-- 
Mike Orr [EMAIL PROTECTED]

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: Multiple controller calls

2007-11-21 Thread Philip Jenvey


 On Nov 21, 2007, at 5:35 AM, Justin wrote:

 def test(self, var):
 id = var
 if int(id)  5:
 return 'GREATER THAN'
 else:
 return 'LESS THAN'

 You'll run into trouble here if var is '' or contains non-numeric
 characters.  Your default value in the routing rule is novar, which
 would raise a ValueError exception and ultimately a 500 Internal
 Server Error.  Since we can't trust users to always put numeric
 values, you should trap the case thus:

 Yeah, I know. The novar default was left over from passing strings
 to the page via querystring. Like I said I'm just throwing stuff at
 the framework right now to kind of feel it out and get a grip on how
 it handles stuff.

 Just to rule out the possibility that I did somthing wierd I created a
 new project, added a new controller (changed nothing, its index action
 returns 'Hello World', and just add the line to by BaseController to
 print out the class name and received almost the same result:

 CtestController
 TemplateController
 ErrorController
 TemplateController
 ErrorController
 TemplateController
 ErrorController
 TemplateController
 ErrorController


Again, print out the PATH_INFO of the requested URLs and you'll  
figure out what's being requested from your browser.

If you still don't believe me that your browser is making those  
requests, load live http headers or the like and watch what it's  
doing. =]

Also try hitting the page with a simple HTTP client (curl -O http:// 
localhost:5000/): you'll see just one request.

--
Philip Jenvey

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Multiple controller calls

2007-11-20 Thread Justin

Just out of curiosity I put a line in BaseController to print out the
name of the current controller class when called and was suprised to
see 7 seperate controller calls for a single url:

my test controller
template.TemplateController
template.TemplateController
error.ErrorController
template.TemplateController
error.ErrorController
error.ErrorController


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: Multiple controller calls

2007-11-20 Thread Justin

Sorry, I got cut off.. Anyway, the order is as follows:

1. my test controller
2. template.TemplateController
3. template.TemplateController
4. error.ErrorController
5. template.TemplateController
6. error.ErrorController
7. error.ErrorController

This is for a test view that just returns a simple string to the
browser and the page is returned as is should be without error. Is
this normal? What is the purpose of all these controller calls? Right
now I'm just evaluating pylons but this strikes me as inefficient and
obtuse.

Thanks,

- Justin
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: Multiple controller calls

2007-11-20 Thread Philip Jenvey


On Nov 20, 2007, at 11:05 AM, Justin wrote:


 Sorry, I got cut off.. Anyway, the order is as follows:

 1. my test controller
 2. template.TemplateController
 3. template.TemplateController
 4. error.ErrorController
 5. template.TemplateController
 6. error.ErrorController
 7. error.ErrorController

 This is for a test view that just returns a simple string to the
 browser and the page is returned as is should be without error. Is
 this normal? What is the purpose of all these controller calls? Right
 now I'm just evaluating pylons but this strikes me as inefficient and
 obtuse.

Pylons is going to construct a Controller and call the specified  
action once per request. If that controller returns an error HTTP  
response code, Pylons will route the request to the error page (so  
you get a pretty 404 or whatever page). Triggering the error page  
means construction of an ErrorController and a call to its error page  
action.

Assuming you're using the default TemplateController and its  
accompanying catch-all route, this means your browser is actually  
hitting TemplateController 3 times. The default TemplateController  
simply abort()s, hence the ErrorControllers.

One of the requests is most likely for the favicon, I don't know  
about the other one (it probably has to do with the rendered error  
page). You can see what URL path was requested by printing out  
request.path_info.

--
Philip Jenvey



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: Multiple controller calls

2007-11-20 Thread Mike Orr

On Nov 20, 2007 11:05 AM, Justin [EMAIL PROTECTED] wrote:

 Sorry, I got cut off.. Anyway, the order is as follows:

 1. my test controller
 2. template.TemplateController
 3. template.TemplateController
 4. error.ErrorController
 5. template.TemplateController
 6. error.ErrorController
 7. error.ErrorController

 This is for a test view that just returns a simple string to the
 browser and the page is returned as is should be without error. Is
 this normal? What is the purpose of all these controller calls? Right
 now I'm just evaluating pylons but this strikes me as inefficient and
 obtuse.

Are you sure it's not making all those requests, perhaps for images or
stylesheets?  I tried what you said, putting

print Controller is, self.__class__.__name__

at the beginning of BaseController.__call__() in one of my
applications,  It prints the expected controller, not the extra lines.
 But if I go to a nonexistent page, I get this:

Controller is TemplateController
Controller is ErrorController
Controller is ErrorController
Controller is ErrorController
Controller is ErrorController
Controller is ErrorController
Controller is ErrorController
Controller is ErrorController

TemplateController is the one in your last routing rule, which matches
if no other routes have matched.  By default it always reports 404
Not Found.  This is caught by the ErrorDocuments middleware, which
makes a subrequest for the error page -- the first ErrorController
call.  The other ErrorController calls are stylesheets and images for
that page.

If you still can't figure it out, show us your controller class, any
changes you've made to the routing, and the URL you're requesting, and
maybe that will clear it up.

-- 
Mike Orr [EMAIL PROTECTED]

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: Multiple controller calls

2007-11-20 Thread Justin

Thank you both for your responses. Right now, I'm just evaluating the
framework to see if it seems like a good fit so the controller doesn't
do much (the the output above was from calling the test action that
I was using to test accessing route variables):

class HelloController(BaseController):

def index(self):
# Return a rendered template
#   return render('/some/template.mako')
# or, Return a response
return 'Hello World!'

def test(self, var):
id = var
if int(id)  5:
return 'GREATER THAN'
else:
return 'LESS THAN'

My routes:

def make_map():
Create, configure and return the routes Mapper
map = Mapper(directory=config['pylons.paths']['controllers'],
 always_scan=config['debug'])

# The ErrorController route (handles 404/500 error pages); it
should
# likely stay at the top, ensuring it can always be resolved
map.connect('error/:action/:id', controller='error')

# CUSTOM ROUTES HERE

map.connect('hello/test/:var', controller='hello', action='test',
var=novar)
map.connect(':controller/:action/:id')
map.connect('*url', controller='template', action='view')

return map

Requested url:

http://localhost:5000/hello/test/10/

Base controller:

class BaseController(WSGIController):

def __call__(self, environ, start_response):
Invoke the Controller
# WSGIController.__call__ dispatches to the Controller method
# the request is routed to. This routing information is
# available in environ['pylons.routes_dict']
try:
return WSGIController.__call__(self, environ,
start_response)
finally:
Session.remove()
print self.__class__

I also printed out the return value of each controller called and the
error controllers are returning a 404 page each time. However, the
browser returns GREATER THAN as expected.

On Nov 20, 2:45 pm, Mike Orr [EMAIL PROTECTED] wrote:
 On Nov 20, 2007 11:05 AM, Justin [EMAIL PROTECTED] wrote:





  Sorry, I got cut off.. Anyway, the order is as follows:

  1. my test controller
  2. template.TemplateController
  3. template.TemplateController
  4. error.ErrorController
  5. template.TemplateController
  6. error.ErrorController
  7. error.ErrorController

  This is for a test view that just returns a simple string to the
  browser and the page is returned as is should be without error. Is
  this normal? What is the purpose of all these controller calls? Right
  now I'm just evaluating pylons but this strikes me as inefficient and
  obtuse.

 Are you sure it's not making all those requests, perhaps for images or
 stylesheets?  I tried what you said, putting

 print Controller is, self.__class__.__name__

 at the beginning of BaseController.__call__() in one of my
 applications,  It prints the expected controller, not the extra lines.
  But if I go to a nonexistent page, I get this:

 Controller is TemplateController
 Controller is ErrorController
 Controller is ErrorController
 Controller is ErrorController
 Controller is ErrorController
 Controller is ErrorController
 Controller is ErrorController
 Controller is ErrorController

 TemplateController is the one in your last routing rule, which matches
 if no other routes have matched.  By default it always reports 404
 Not Found.  This is caught by the ErrorDocuments middleware, which
 makes a subrequest for the error page -- the first ErrorController
 call.  The other ErrorController calls are stylesheets and images for
 that page.

 If you still can't figure it out, show us your controller class, any
 changes you've made to the routing, and the URL you're requesting, and
 maybe that will clear it up.

 --
 Mike Orr [EMAIL PROTECTED]
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: Multiple controller calls

2007-11-20 Thread Mike Orr

On Nov 20, 2007 12:02 PM, Justin [EMAIL PROTECTED] wrote:
 Thank you both for your responses. Right now, I'm just evaluating the
 framework to see if it seems like a good fit so the controller doesn't
 do much

We like troubleshooting small, simple examples. :)

 def test(self, var):
 id = var
 if int(id)  5:
 return 'GREATER THAN'
 else:
 return 'LESS THAN'

You'll run into trouble here if var is '' or contains non-numeric
characters.  Your default value in the routing rule is novar, which
would raise a ValueError exception and ultimately a 500 Internal
Server Error.  Since we can't trust users to always put numeric
values, you should trap the case thus:

if not var.isdigit():
return Third URL component must be numeric.

 map.connect('hello/test/:var', controller='hello', action='test',
 var=novar)


 Requested url:

 http://localhost:5000/hello/test/10/

Does it make a difference if you omit the trailing slash?

 I also printed out the return value of each controller called and the
 error controllers are returning a 404 page each time.

You mean the error controller itself is failing to return a page?

-- 
Mike Orr [EMAIL PROTECTED]

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---