Python Code Auditing Tool
Does anybody know of a tool that can tell me all possible exceptions that might occur in each line of code? What I'm hoping to find is something like the following: given all necessary python source and a given line ( my.py:40 ) it would generate a list of possible exception classes sorted by function (preferably in a tree). Example: -- my.py:40 |parsestring(genstring()) Possible Exceptions: -def parsestring(): InvalidCharacterException EmptyStringException -class string, def split(): (All Exceptions that might occur directly in string.split() that are not caught by parsestring()) (All functions called by string.split() and their exceptions and sub- functions) -def genstring(): SomeException ... This would be extremely useful for deciding how to write try: except blocks and in figuring out what all possible errors that might occur would be. -Robey Holderith -- http://mail.python.org/mailman/listinfo/python-list
Re: curl and popen2
On Tue, 01 Feb 2005 17:48:53 -0800, lists04 wrote: > Hi, > > I have a problem with a curl request and running it under popen2. > > If I run this request from the command line: > curl -i http://www.yahoo.com/test --stderr errfile > (also tried redirecting stdderr to a file 2>, nothing) the file errfile > is empty indicating no error with the request. > > However, when I do something similar in python: >>>> cmd="curl -i http://www.yahoo.com/test"; >>>> output, input, err = popen2.popen3(cmd) >>>> error = err.readlines() >>>> error > [' % Total% Received % Xferd Average Speed Time > Curr.\n', ' Dload Upload Total > Current LeftSpeed\n', '\r100 9810 9810 0 24525 > 0 --:--:-- 0:00:00 --:--:-- 24525\r100 24840 24840 0 > 62100 0 --:--:-- 0:00:00 --:--:-- 1467k\n'] > > I looked in the man page for curl, it doesnt say that it writes some > bandwidth statistics to stderr. Am I missing something or is this > better directed to some other newsgroup? > Many of the more "sophisticated" command line applications use stderr to write things that are intended directly for the user's eyes. The idea is that it is often useful to have the file itself be written to stdout so that pipes can be used, but the user still needs to see what is going on. Try using "curl --silent -i http://www.yahoo.com/test";. That should turn off all of the "user-friendly" updates to stderr. -Robey Holderith > TIA > > Hari -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Code Auditing Tool
On Tue, 01 Feb 2005 21:52:28 -0800, Paul Rubin wrote: > Robey Holderith <[EMAIL PROTECTED]> writes: >> Does anybody know of a tool that can tell me all possible exceptions that >> might occur in each line of code? What I'm hoping to find is something >> like the following: > > That is impossible. The parameter to the raise statement is a class > object, which can be anything. I.e. you could say: > >class ex1: pass >class ex2: pass > >if something(): my_ex = ex1 >else: my_ex = ex2 > >raise my_ex# static tool can't know what exception gets raised here. I suppose that I am willing to lessen my expectations from _all_ to most. ;-) Regarding your example I could also do: if something(): def nothing(): return 0 else: def nothing(): return 1 But this doesn't stop IDEs from attempting to do auto-completion. I'm not trying to find hidden exceptions... just trying to easily get an idea of what could go wrong on each line of code. -Robey Holderith -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie Question
On Tue, 01 Feb 2005 17:47:39 -0800, Joel Eusebio wrote: > > Hi Everybody, > > I'm pretty new to Python and would like to ask a few questions. I have this > setup on a Fedora Core 3 box. > > Python 2.3.4 > wxPython-common-gtk-ansi-2.5.3.1-fc2_py2.3 > mod_python-3.1.3-5 > Apache/2.0.52 > > I have a test.py which looks like this: > from mod_python import apache > def handler(req): >req.write("Hello World!") >return apache.OK > This code looks like you are attempting to define a handler. In this case the handler needs to be properly set up in either your httpd.conf or a .htaccess (assuming your configuration allows for that). > Whenever I access test.py from my browser it says "The page cannot be found" > , I have the file on /var/www/html, what did I miss? You don't access handlers like you do CGI. This problem likely lies in your configuration and not in your code. I would look at mod_python's documentation some more and probably start with mod_python's PublisherHandler for initial testing and experimentation. -Robey Holderith > Thanks in advance, > Joel -- http://mail.python.org/mailman/listinfo/python-list