Example #1
0
    def __init__(self, wsdl=None, cacheDuration=0, suds_client=None, **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
    '''
        if suds_client is None:
            # 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'])

        else:
            self._sforce = suds_client
  def __init__(self, wsdl=None, cacheDuration = 0, suds_client=None, **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
    '''
    if suds_client is None:
      # 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'])

    else:
      self._sforce = suds_client
Example #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):
                if 'darwin' in sys.platform or 'linux' in sys.platform:
                    wsdl = 'file://' + os.path.abspath(
                        wsdl)  #could have trouble here when frozen
                else:
                    wsdl = 'file:///' + os.path.abspath(
                        wsdl)  #could have trouble here when frozen
        if cacheDuration > 0:
            cache = FileCache()
            cache.setduration(seconds=cacheDuration)
        else:
            cache = None

        # TEST
        #   self._setHeaders('login')
        # result = self._sforce.service.login(username, password + token)

        # # set session header
        # header = self.generateHeader('SessionHeader')
        # header.sessionId = result['sessionId']
        # self.setSessionHeader(header)
        # self._sessionId = result['sessionId']
        # self._userId = result['userId']
        # self._metadataServerUrl = result['metadataServerUrl']

        # # change URL to point from test.salesforce.com to something like cs2-api.salesforce.com
        # self._setEndpoint(result['serverUrl'])
        # END TEST

        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())
        #temp = str(self._sforce)
        #print temp
        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

        # Set HTTP headers
        #headers = {'User-Agent': 'Salesforce/' + self._product + '/' + '.'.join(str(x) for x in self._version)}
        headers = {u'User-Agent': u'MavensMate'}
        # This HTTP header will not work until Suds gunzips/inflates the content
        # 'Accept-Encoding': 'gzip, deflate'

        if kwargs.has_key(
                'environment') and 'sandbox' in kwargs['environment']:
            self._setEndpoint("https://test.salesforce.com/services/Soap/u/" +
                              str(util.SFDC_API_VERSION))

        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'])

        #set the timeout from a setting
        self._sforce.set_options(
            timeout=config.connection.get_plugin_client_setting(
                'mm_timeout', 3600))
Example #4
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) #could have trouble here when frozen
    if cacheDuration > 0:
      cache = FileCache()
      cache.setduration(seconds = cacheDuration)
    else:
      cache = None

    # TEST
    #   self._setHeaders('login')
    # result = self._sforce.service.login(username, password + token)

    # # set session header
    # header = self.generateHeader('SessionHeader')
    # header.sessionId = result['sessionId']
    # self.setSessionHeader(header)
    # self._sessionId = result['sessionId']
    # self._userId = result['userId']
    # self._metadataServerUrl = result['metadataServerUrl']

    # # change URL to point from test.salesforce.com to something like cs2-api.salesforce.com
    # self._setEndpoint(result['serverUrl'])
    # END TEST

    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())
    #temp = str(self._sforce)
    #print temp
    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

    # 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'

    if kwargs.has_key('environment') and 'sandbox' in kwargs['environment']:
      self._setEndpoint("https://test.salesforce.com/services/Soap/u/"+mm_util.SFDC_API_VERSION)
    

    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'])

    #set the timeout from a setting
    self._sforce.set_options(timeout=config.connection.get_plugin_client_setting('mm_timeout', 3600))