#!/usr/bin/env python

import urllib2
LOGIN = "wesley"
PASSWORD = "you'llNever Guess"
URL="http://localhost"
REALM='Secure Archive'

def handler_version(url):
	from urlparse import urlparse
	hdlr = urllib2.HTTPBasicAuthHandler()
	hdlr.add_password(REALM,urlparse(url)[1],LOGIN,PASSWORD)
	opener = urllib2.build_opener(hdlr)
	urllib2.install_opener(opener)
	return url

def request_version(url):
	from base64 import encodestring
	req = urllib2.Request(url)
	b64str = encondestring('%s:%s'%(LOGIN,PASSWORD))[:-1]
	req.add_header('Authorization','Basic %s'%b64str)
	return req
for funcType in ('handler','request'):
	print '****Using %s:'%funcType.upper()
	url = eval("%s_version"%funcType)(URL)
	f = urllib2.urlopen(url)
	print f.readline()
	f.close()