def __init__(self, config): self.dbs = config.get('dbsinst') self.global_url = config.get('dbs') self.phedex_url = config.get('phedex') self.params = config.get('dbsparams') self.dbslist = dbsinstances() self.known_lfns = {} self.dbsver = {} ckey, cert = get_key_cert() handler = HTTPSClientAuthHandler(ckey, cert) self.opener = urllib2.build_opener(handler) urllib2.install_opener(self.opener)
def get_data(url, headers={"Accept": "*/*"}): "Context Manager to read data from given URL" ckey, cert = get_key_cert() req = urllib2.Request(url) if headers: for key, val in headers.items(): req.add_header(key, val) handler = HTTPSClientAuthHandler(ckey, cert) opener = urllib2.build_opener(handler) urllib2.install_opener(opener) data = urllib2.urlopen(req) try: yield data finally: data.close()