[Tutor] Why is this not an error?

2005-03-20 Thread Steve N
This code runs, but it seems to me it should generate
a syntax error.  Can someone explain what's going on?

x = [1,2,3,4]
z = 4
if z in x:
print 'found:', z
for i in x:
print 'in the loop with', i
else:
print 'not found:', z

>>> 
found: 4
in the loop with 1
in the loop with 2
in the loop with 3
in the loop with 4
not found: 4
>>> 

--
Steve




__ 
Do you Yahoo!? 
Yahoo! Mail - Easier than ever with enhanced search. Learn more. 
http://info.mail.yahoo.com/mail_250
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] CGI request handler bug?

2007-03-02 Thread Steve N
Hi all,
I was playing with some simple HTTP CGI server code
and discovered what I think may be a bug in
CGIHTTPServer.CGIHTTPRequestHandler. A "GET" request
without a leading '/' from a telnet session displays
the CGI script rather than the script's output. If the
request includes the leading '/', the script is run as
expected. Is this a bug?
Windows 2000
Python 2.4.3


import os, sys, socket
from BaseHTTPServer import HTTPServer
from CGIHTTPServer import CGIHTTPRequestHandler
os.chdir('docs')
myip = '127.0.0.1'
serv = HTTPServer((myip, 8000), CGIHTTPRequestHandler)
serv.serve_forever()



print 'Content-type: text/html\n'
print 'Hello'
print 'Hello'


Telnet without a leading '/' in the request displays
the script:

telnet localhost 8000
GET cgi-bin/hello.py

print 'Content-type: text/html\n'
print 'Hello'
print 'Hello'


Connection to host lost.


Telnet with a leading '/' in the request runs the
script:

telnet localhost 8000
GET /cgi-bin/hello.py

Content-type: text/html

  
Hello
  
   Hello


Connection to host lost.


--
SteveN



 

8:00? 8:25? 8:40? Find a flick in no time 
with the Yahoo! Search movie showtime shortcut.
http://tools.search.yahoo.com/shortcuts/#news
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] CGI request handler bug?

2007-03-02 Thread Steve N
> I was playing with some simple HTTP CGI server code
> and discovered what I think may be a bug in
> CGIHTTPServer.CGIHTTPRequestHandler. A "GET" request
> without a leading '/' from a telnet session displays
> the CGI script rather than the script's output. If >
the
> request includes the leading '/', the script is run
as
> expected. Is this a bug?

I think I've solved my problem by adding subclassing
CGIHTTPRequestHandler and adding this at the start of
the is_cgi() method:

if not self.path.startswith('/'):
self.path = '/' + self.path
--
SteveN



 

Have a burning question?  
Go to www.Answers.yahoo.com and get answers from real people who know.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor