def get_proxy(config_file=None): """ Setup proxy """ proxy_info = {} if config_file is None: BASE_PATH=expanduser("~") config_file = join(BASE_PATH,'.proxies') if not exists(config_file): config_file = None if config_file is None: BITS_PATH="/home/group/public/bits" BITS_ETC=join(BITS_PATH,"etc") config_file = join(BITS_ETC,'proxies.conf') if not exists(config_file): config_file = None if config_file and exists(config_file): logger.info('Getting proxy from file %s',config_file) socket.setdefaulttimeout(120) domain = '.'.join(socket.getfqdn().split('.')[1:]) session="PROXY-%s" % domain http_proxy = getenv('http_proxy') proxy_info = get_session(config_file,session, secure=False, host='itaca-prod.utenze.bankit.it', port=8079, user="******" % getenv('LOGNAME'), password=None ) if not proxy_info.has_key('password') or proxy_info['password'] is None: try: user,passwd = get_credentials() proxy_info['password']=passwd except TypeError: raise NoProxyInfoInConfigFileError("No Proxy Info in configurations file (password key)") else: passwd = proxy_info['password'] proxy_info['proxy'] = "http://%(user)s:%(password)s@%(host)s:%(port)s" % proxy_info log_proxy=','.join(["%s=%s" %(k,v) for k,v in proxy_info.items()]) npwd=passwd[0]+'*'*(len(passwd)-2)+passwd[-1] log_proxy=log_proxy.replace(passwd,npwd) logger.info("Proxy Info are %s",log_proxy) return proxy_info
def __init__(self,config_file=None,session="FRED"): """FRED REST Client >>> fr=FRED() """ self.config_file = discover_config_file(self._name, config_file, '~/.fred.conf', DEFAULT_FRED_CONF_FILE, join(BITS_ETC, DEFAULT_BITS_CONF_FILE)) fred_info = get_session(config_file,session, secure=True, url='http://api.stlouisfed.org/fred', api_key=(None,ValueError), ) self._auth=fred_info ### Proxy if any # proxy_info = get_proxy() if proxy_info: pip={ 'http':proxy_info['proxy'], 'https':proxy_info['proxy'], } proxy = urllib2.ProxyHandler(pip) opener = urllib2.build_opener(proxy) urllib2.install_opener(opener) # # ### Fred.__init__(self,self._auth['api_key'])
def __init__(self,config_file=None,session="DWE"): """Datastream SOAP Client >>> ds=Datastream() """ _set_debug(logging.WARN, 'suds.resolver', 'suds.metrics', 'suds.xsd.sxbasic', 'suds.xsd.query', 'suds.client', 'suds.wsdl', 'suds.transport.http', 'suds.mx.core', 'suds.umx.typed', 'suds.xsd.schema', 'suds.xsd.sxbase', 'suds.mx.literal') if config_file is None: if exists(expanduser('~/.dwe.conf')): config_file = expanduser('~/.dwe.conf') os.chmod(config_file,stat.S_IRUSR | stat.S_IWUSR) else: config_file = DEFAULT_DSTREAM_CONF_FILE config_file = expanduser(expandvars(config_file)) if not exists(config_file): logger.info('no configuration for datastream (%s). using BITS path',config_file) config_file = join(BITS_ETC,DEFAULT_BITS_CONF_FILE) self.config_file = config_file if not exists(self.config_file): raise IOError, 'Datastream Configuration File not Found %s' % config_file dstream_info = get_session(config_file,session, secure=True, url='http://dataworks.thomson.com/dataworks/enterprise/1.0/webServiceClient.asmx?WSDL', user=(None,ValueError), password=(None,ValueError), realm='' ) self._auth=dstream_info t = HttpTransport() ### Proxy if any # proxy_info = get_proxy() if proxy_info: pip={ 'http':proxy_info['proxy'], 'https':proxy_info['proxy'], } proxy = urllib2.ProxyHandler(pip) # opener = urllib2.build_opener(SocksiPyHandler(socks.PROXY_TYPE_SOCKS4, 'localhost', 8080)) opener = urllib2.build_opener(proxy) urllib2.install_opener(opener) t.urlopener = opener # # ### Client.__init__(self,self._auth['url'],transport=t)