Test tool for python code.

2006-06-07 Thread jnair
Is there any tool available that will tell me what  are the different
test  paths  for any python code?

thnaks
regards
Jitu

-- 
http://mail.python.org/mailman/listinfo/python-list


how to browse using urllib2 and cookeilib the correct way

2006-04-25 Thread jnair
Hi ,

I am using python2.4 "urllib2" and "cookelib".
In line "5" below i provide my credentials to
login into a web site.During the first attempt i "fail",
judging from the output of line "6".
I try again and the second time i succeed,judging
from the output of line "8".

Now using the "twill" module (http://www.idyll.org/~t/www-tools/twill/)
it suceeds in the  first attempt(lines "10" to "19").

can anybody explain, in the first case why i need to do two attempts.


1) >>>import urllib2,urllib,cookielib
2) >>>cj = cookielib.CookieJar()
3) >>>opener = urllib2.build_opener( urllib2.HTTPCookieProcessor(cj))
4) >>>data = urllib.urlencode( { "username" : "user" , "password" :
"" } )
5) >>>fp = opener.open(
"https://rhn.redhat.com/rhn/LoginSubmit.do",data )
6) >>>fp.url

'https://rhn.redhat.com/rhn/ReLogin.do?url_bounce=/network/index.pxt'
7) >>>fp = opener.open(
"https://rhn.redhat.com/rhn/LoginSubmit.do",data )
8) >>>fp.url
   'https://rhn.redhat.com/network/index.pxt'



#twill module

10) >>>from twill.commands import *
11) >>>go("https://rhn.redhat.com";)
12) ==> at https://rhn.redhat.com
13) 'https://rhn.redhat.com'
14) >>>fv("2","username","eipl")
15) >>>fv("2","password","ensim1234")
16) >>>submit()
17) Note: submit is using submit button: name="None", value=" Â  Sign
In  "
18) >>>url('https://rhn.redhat.com/network/index.pxt')
19) 'https://rhn.redhat.com/network/index.pxt'

Thanks 
Jitu

-- 
http://mail.python.org/mailman/listinfo/python-list


how to browse using urllib2 and cookeilib the correct way

2006-04-25 Thread jnair
Hi ,

I am using python2.4 "urllib2" and "cookelib".
In line "5" below i provide my credentials to
login into a web site.During the first attempt i "fail",
judging from the output of line "6".
I try again and the second time i succeed,judging
from the output of line "8".

Now using the "twill" module (http://www.idyll.org/~t/www-tools/twill/)
it suceeds in the  first attempt(lines "10" to "19").

can anybody explain, in the first case why i need to do two attempts.

1) >>>import urllib2,urllib,cookielib
2) >>>cj = cookielib.CookieJar()
3) >>>opener = urllib2.build_opener( urllib2.HTTPCookieProcessor(cj))
4) >>>data = urllib.urlencode   ( { "username" : "user" ,
 "password" :"" } )
5) >>>fp = opener.open(
"https://rhn.redhat.com/rhn/LoginSubmit.do",data )
6) >>>fp.url

'https://rhn.redhat.com/rhn/ReLogin.do?url_bounce=/network/index.pxt'
7) >>>fp = opener.open(
"https://rhn.redhat.com/rhn/LoginSubmit.do",data )
8) >>>fp.url
   'https://rhn.redhat.com/network/index.pxt'

#twill module

10) >>>from twill.commands import *
11) >>>go("https://rhn.redhat.com";)
12) ==> at https://rhn.redhat.com
13) 'https://rhn.redhat.com'
14) >>>fv("2","username","user")
15) >>>fv("2","password","")
16) >>>submit()
17) Note: submit is using submit button: name="None", value=" Â  Sign
In  "
18) >>>url('https://rhn.redhat.com/network/index.pxt')
19) 'https://rhn.redhat.com/network/index.pxt'

Thanks
jn
jn

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to browse using urllib2 and cookeilib the correct way

2006-04-25 Thread jnair
ok , got it . Thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Multiple inheritance : waht does this error mean ?

2006-05-15 Thread jnair
I am using Python 2.4.3

>>>class K(object,list):
   ...: pass
   ...:

Traceback (most recent call last):
  File "", line 1, in ?
TypeError: Error when calling the metaclass bases
Cannot create a consistent method resolution
order (MRO) for bases object, list


Regards
Jitendra Nair

-- 
http://mail.python.org/mailman/listinfo/python-list


socket.socket.settimeout implementation

2006-04-05 Thread jnair
When using socket.socket.settimeout we normally only guard against
"socket.timeout" exception.Now the implementation of "settimeout" in
"Python-2.4.3/Modules/socketmodule.c" sets the socket fd to
nonblocking and uses "select()" to timeout
as seen below in line 1487 and 1386 :

static PyObject *
  1470  sock_settimeout(PySocketSockObject *s, PyObject *arg)
  1471  {
  1472  double timeout;
  ..
  1485
  1486  s->sock_timeout = timeout;
  1487  internal_setblocking(s, timeout < 0.0);
  1488
  1489  Py_INCREF(Py_None);
  1490  return Py_None;
  1491  }
  1492

  1362  sock_accept(PySocketSockObject *s)
  1363  {
  ...

  1385 Py_BEGIN_ALLOW_THREADS
  1386 timeout = internal_select(s, 0);
  1387 if (!timeout)
  1388   newfd = accept(s->sock_fd, (struct sockaddr *)&addrbuf,
  1389 &addrlen);
  1390 Py_END_ALLOW_THREADS
  1391


Now internal_select()  returns "1" on timemout else "0"  as seen below
:

  673n = select(s->sock_fd+1, &fds, NULL, NULL,&tv);
  674 if (n == 0)
  675return 1;
  676  return 0;

back to the sock_accept() fuction on line 1387

1387  if (!timeout)
1388 newfd = accept(s->sock_fd, (struct sockaddr *) &addrbuf,
1389&addrlen)


if "select()" returned before timeout we call "accept()"

Now my observation on FC4 ( kernel version 2.6.11-1.1369_FC4)
"select()" can return  before timeout with a
"Interrupted system call" (EINTR) error,

my question is , is it possible that our internal_select() fuction as
seen on line 676 above returns "0" and we go on to do a "accept()" call
which returns with a  "Resource temporarily unavailable" error if the
sockfd is not readable. So user expects only "socket.timeout" but gets
"Resource temporarily unavailable" which stops the program
from proceeding.

Our Case : We are using CherryPy , which sets a timeout on socket using
"settimeout" and whenever our code uses "os.seteuid" cherrpy dies
giving
out the "Resource temporarily unavailable".

I did write a "C" program using pthreads , one thread doing
non blocking accept() and select()  and other thread doing a seteuid()
.
select() did bail out giving Interrupted system call Error.

Thanks
Jitendra Nair

-- 
http://mail.python.org/mailman/listinfo/python-list


Is this code snippet pythonic

2006-04-10 Thread jnair
My Tead  Lead  my object counter  code seen below is not  pythonic

 class E(object):
_count = 0
def __init__(self):
E._count += 1
count = property(lambda self: E._count )

def  test():
if __name__ == "__main__":
e1 = E()
print e1.count
e2 = E()
print e2.count
e3 = E()
print e3.count

test()



if  not  waht woutld be the  pythonic way

-- 
http://mail.python.org/mailman/listinfo/python-list


Is this object counter code pythonic

2006-04-10 Thread jnair
My Team  Lead says  my object counter  code seen below is not  pythonic

 class E(object):
_count = 0
def __init__(self):
E._count += 1
count = property(lambda self: E._count )

def  test():
if __name__ == "__main__":
e1 = E()
print e1.count
e2 = E()
print e2.count
e3 = E()
print e3.count

test()



if  not  what would be the  pythonic way

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is this object counter code pythonic

2006-04-10 Thread jnair
Ok got it .
Thanks a Lot

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is this object counter code pythonic

2006-04-10 Thread jnair
Fredrik is then this a valid "property"  use  case and pythonic  to
get/set a common varibale  across objects

class E(object):
_i = 0
def geti(self) : return E._i
def seti(self,val) : E._i = val
i = property(geti,seti)

if __name__ == "__main__":
e1 = E()
e1.i = 100
e2 = E()
print e2.i

-- 
http://mail.python.org/mailman/listinfo/python-list


something similar to LWP::Simple mirror function

2006-04-17 Thread jnair
from the perl man pages of  LWP::Simple

  mirror($url, $file)
  Get and store a document identified by a URL, using
If-modified-
  since, and checking the Content-Length.  Returns the HTTP
response
  code.

is there something similar in python 

regards
jitya

-- 
http://mail.python.org/mailman/listinfo/python-list