urllib2 OpenerDirector question on usage.

A

Ant

Hello all,

I am using urllib2 as a part of a web testing tool. One of the things I
am testing is the effect of two different people perforing the same
actions on the website - do they interfer with each other or not.

So to emulate this, I essentially have the following function:

def get_opener():
policy = cookielib.DefaultCookiePolicy(rfc2965=True)
cj = cookielib.CookieJar(policy)
return urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))

Now am I right in thinking that since I am creating a separate
CookieJar for each opener, then creating two openers and using one for
each hypothetical user will achieve this effect - i.e. sessions will be
separate from each other in the app, since the openers will return
different session cookies back to the server.

Cheers,

Ant...
 
J

John J. Lee

Ant said:
I am using urllib2 as a part of a web testing tool. One of the things I
am testing is the effect of two different people perforing the same
actions on the website - do they interfer with each other or not.

So to emulate this, I essentially have the following function:

def get_opener():
policy = cookielib.DefaultCookiePolicy(rfc2965=True)
cj = cookielib.CookieJar(policy)
return urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))

Now am I right in thinking that since I am creating a separate
CookieJar for each opener, then creating two openers and using one for
each hypothetical user will achieve this effect - i.e. sessions will be
separate from each other in the app, since the openers will return
different session cookies back to the server.

Yes.

As far as cookies are concerned, anyway (and assuming you're not
sharing cookies by e.g. loading and saving from a single file,
obviously). Presumably the two users will also be separate login
users too (i.e. have separate usernames and passwords -- or other
credentials).


John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top