コード例 #1
0
	def __init__(self, wsdl, cacheDuration = 0, **kwargs):
		if '://' not in wsdl:
			if os.path.isfile(wsdl):
				if 'darwin' in sys.platform or 'linux' in sys.platform:
					wsdl = 'file:///' + os.path.abspath(wsdl)
		if cacheDuration > 0:
			cache = FileCache()
			cache.setduration(seconds = cacheDuration)
		else:
			cache = None
		
		if 'sid' in kwargs:
			self._sessionId = kwargs['sid']
		if 'metadata_server_url' in kwargs:
			self._metadataServerUrl = kwargs['metadata_server_url']
		xml_response = False
		if 'retxml' in kwargs:
			xml_response = kwargs['retxml']
		self._sforce = Client(wsdl, cache=cache, plugins=[PrunePlugin()], retxml=xml_response, transport=WellBehavedHttpTransport())
		if 'server_url' in kwargs:
			self._setEndpoint(kwargs['server_url'])
		if 'apiVersion' in kwargs:
			if type(kwargs['apiVersion']) == str:
				api_version = float(kwargs['apiVersion'])
			else:
				api_version = kwargs['apiVersion']
			self._apiVersion = api_version
		else:
			self._apiVersion = 27.0
		headers = {u'User-Agent': u'MetaData'}
		self._sforce.set_options(headers = headers)
コード例 #2
0
ファイル: base.py プロジェクト: kcshafer/pyrannosaurus
    def __init__(self, wsdl='wsdl/partner.xml', cacheDuration=0, **kwargs):
        if cacheDuration > 0:
            cache = FileCache()
            cache.setduration(seconds = cacheDuration)
        else:
            cache = None

        wsdl = get_package_dir(wsdl)
        wsdl = 'file:///' + os.path.abspath(wsdl)
        self._base_client =  Client(wsdl, cache = cache)

        headers = {'User-Agent': 'Salesforce/' + self._product + '/' + '.'.join(str(x) for x in self._version)}
        self._base_client.set_options(headers = headers)
コード例 #3
0
  def __init__(self, wsdl, cacheDuration = 0, **kwargs):
    '''
    Connect to Salesforce
   
    'wsdl' : Location of WSDL
    'cacheDuration' : Duration of HTTP GET cache in seconds, or 0 for no cache
    'proxy' : Dict of pair of 'protocol' and 'location'
              e.g. {'http': 'my.insecure.proxy.example.com:80'}
    'username' : Username for HTTP auth when using a proxy ONLY
    'password' : Password for HTTP auth when using a proxy ONLY
    '''
    # Suds can only accept WSDL locations with a protocol prepended
    if '://' not in wsdl:
      # TODO windows users???
      # check if file exists, else let bubble up to suds as is
      # definitely don't want to assume http or https
      if os.path.isfile(wsdl):
        wsdl = 'file://' + os.path.abspath(wsdl)

    if cacheDuration > 0:
      cache = FileCache()
      cache.setduration(seconds = cacheDuration)
    else:
      cache = None
    
    self._sforce = Client(wsdl, cache = cache)

    # Set HTTP headers
    headers = {'User-Agent': 'Salesforce/' + self._product + '/' + '.'.join(str(x) for x in self._version)}

    # This HTTP header will not work until Suds gunzips/inflates the content
    # 'Accept-Encoding': 'gzip, deflate'

    self._sforce.set_options(headers = headers)

    if kwargs.has_key('proxy'):
      # urllib2 cannot handle HTTPS proxies yet (see bottom of README)
      if kwargs['proxy'].has_key('https'):
        raise NotImplementedError('Connecting to a proxy over HTTPS not yet implemented due to a \
limitation in the underlying urllib2 proxy implementation.  However, traffic from a proxy to \
Salesforce will use HTTPS.')
      self._sforce.set_options(proxy = kwargs['proxy'])

    if kwargs.has_key('username'):
      self._sforce.set_options(username = kwargs['username'])

    if kwargs.has_key('password'):
      self._sforce.set_options(password = kwargs['password'])
コード例 #4
0
ファイル: apex.py プロジェクト: kcshafer/pyrannosaurus
    def __init__(self, wsdl='wsdl/apex.xml', cacheDuration=0, **kwargs):
        super(ApexClient, self).__init__()
        #TODO: clean this up
        wsdl = get_package_dir(wsdl)
        wsdl = 'file:///' + os.path.abspath(wsdl)

        if cacheDuration > 0:
            cache = FileCache()
            cache.setduration(seconds = cacheDuration)
        else:
            cache = None   

        self._client = Client(wsdl, cache = cache)

        headers = {'User-Agent': 'Salesforce/' + self._product + '/' + '.'.join(str(x) for x in self._version)}
        self._client.set_options(headers = headers)
コード例 #5
0
def clear_suds_cache(wsdl):
    for type in ("wsdl", "document"):
        cacheId = Reader(Options()).mangle(wsdl, type)
        DocumentCache().purge(cacheId)
        ObjectCache().purge(cacheId)
        FileCache().purge(cacheId)