def describeGlobal(self):
     res = BaseClient.describeGlobal(self)
     data = dict()
     data['encoding'] = str(res[_tPartnerNS.encoding])
     data['maxBatchSize'] = int(str(res[_tPartnerNS.maxBatchSize]))
     data['types'] = [str(t) for t in res[_tPartnerNS.types:]]
     return data
Esempio n. 2
0
    def query(self, *args, **kw):
        if len(args) == 1:  # full query string
            queryString = args[0]
        elif len(args) == 2:  # BBB: fields, sObjectType
            queryString = 'select %s from %s' % (args[0], args[1])
            if 'conditionalExpression' in kw:  # BBB: fields, sObjectType, conditionExpression as kwarg
                queryString += ' where %s' % (kw['conditionalExpression'])
        elif len(args) == 3:  # BBB: fields, sObjectType, conditionExpression as positional arg
            whereClause = args[2] and (' where %s' % args[2]) or ''
            queryString = 'select %s from %s%s' % (args[0], args[1], whereClause)
        else:
            raise RuntimeError("Wrong number of arguments to query method.")

        res = BaseClient.query(self, queryString)
        # calculate the union of the sets of record types from each record
        types = reduce(lambda a, b: a|b, [getRecordTypes(r) for r in res[_tPartnerNS.records:]], set())
        if not self.cacheTypeDescriptions:
            self.flushTypeDescriptionsCache()
        new_types = types - set(self.typeDescs.keys())
        if new_types:
            self.typeDescs.update(self.queryTypesDescriptions(new_types))
        data = QueryRecordSet(
            records=[self._extractRecord(r) for r in res[_tPartnerNS.records:]],
            done=_bool(res[_tPartnerNS.done]),
            size=int(str(res[_tPartnerNS.size])),
            queryLocator=str(res[_tPartnerNS.queryLocator]))
        return data
 def useSession(self, sessionId, serverUrl):
     if ( str(sessionId) == '' or str(serverUrl) == '' ): 
         raise AttributeError , 'Missing server url or session ID to useSession method'
     logging.info( sessionId, serverUrl)
     res = BaseClient.useSession(self, sessionId, serverUrl)
     data = dict()
     data['sessionId'] = sessionId
     return data
Esempio n. 4
0
 def login(self, username, passwd):
     res = BaseClient.login(self, username, passwd)
     data = dict()
     data['passwordExpired'] = _bool(res[_tPartnerNS.passwordExpired])
     data['serverUrl'] = str(res[_tPartnerNS.serverUrl])
     data['sessionId'] = str(res[_tPartnerNS.sessionId])
     data['userId'] = str(res[_tPartnerNS.userId])
     data['userInfo'] = _extractUserInfo(res[_tPartnerNS.userInfo])
     return data
 def query(self, queryString):
     res = BaseClient.query(self, queryString)
     locator = QueryLocator( str(res[_tPartnerNS.queryLocator]) )
     
     data = dict(queryLocator = locator,
         done = _bool(res[_tPartnerNS.done]),
         records = [self.extractRecord( r )
                    for r in res[_tPartnerNS.records:]],
         size = int(str(res[_tPartnerNS.size]))
         )
     return data
 def describeTabs(self):
     res = BaseClient.describeTabs(self)
     data = list()
     for r in res:
         tabs = [_extractTab(t) for t in r[_tPartnerNS.tabs:]]
         d = dict(
                 label = str(r[_tPartnerNS.label]),
                 logoUrl = str(r[_tPartnerNS.logoUrl]),
                 selected = _bool(r[_tPartnerNS.selected]),
                 tabs=tabs)
     return data
 def queryMore(self, queryLocator):
     locator = queryLocator
     res = BaseClient.queryMore(self, locator)
     # calculate the union of the sets of record types from each record
     types = reduce(lambda a,b: a|b, [getRecordTypes(r) for r in res[_tPartnerNS.records:]], set())
     new_types = types - set(self.typeDescs.keys())
     if new_types:
         self.typeDescs.update(self.queryTypesDescriptions(new_types))
     data = QueryRecordSet(records=[self._extractRecord(r) for r in res[_tPartnerNS.records:]],
                           done=_bool(res[_tPartnerNS.done]),
                           size=int(str(res[_tPartnerNS.size])),
                           queryLocator = str(res[_tPartnerNS.queryLocator]))
     return data
 def queryMore(self, queryLocator):
     locator = queryLocator.locator
     #sObjectType = queryLocator.sObjectType
     #fields = queryLocator.fields
     res = BaseClient.queryMore(self, locator)
     locator = QueryLocator( str(res[_tPartnerNS.queryLocator]) )
     data = dict(queryLocator = locator,
         done = _bool(res[_tPartnerNS.done]),
         records = [_extractRecord( r )
                    for r in res[_tPartnerNS.records:]],
         size = int(str(res[_tPartnerNS.size]))
         )
     return data
 def getDeleted(self, sObjectType, start, end):
     res = BaseClient.getDeleted(self, sObjectType, start, end)
     res = res[_tPartnerNS.deletedRecords:]
     if type(res) not in (TupleType, ListType):
         res = [res]
     data = list()
     for r in res:
         d = dict(
             id = str(r[_tPartnerNS.id]),
             deletedDate = marshall('datetime', 'deletedDate', r,
             ns=_tPartnerNS))
         data.append(d)
     return data
Esempio n. 10
0
 def describeSObjects(self, sObjectTypes):
     res = BaseClient.describeSObjects(self, sObjectTypes)
     if type(res) not in (TupleType, ListType):
         res = [res]
     data = list()
     for r in res:
         d = dict()
         d['activateable'] = _bool(r[_tPartnerNS.activateable])
         rawreldata = r[_tPartnerNS.ChildRelationships:]
         relinfo = [_extractChildRelInfo(cr) for cr in rawreldata]
         d['ChildRelationships'] = relinfo
         d['createable'] = _bool(r[_tPartnerNS.createable])
         d['custom'] = _bool(r[_tPartnerNS.custom])
         try:
             d['customSetting'] = _bool(r[_tPartnerNS.customSetting])
         except KeyError:
             pass
         d['deletable'] = _bool(r[_tPartnerNS.deletable])
         d['deprecatedAndHidden'] = _bool(r[_tPartnerNS.deprecatedAndHidden])
         try:
             d['feedEnabled'] = _bool(r[_tPartnerNS.feedEnabled])
         except KeyError:
             pass
         fields = r[_tPartnerNS.fields:]
         fields = [_extractFieldInfo(f) for f in fields]
         field_map = dict()
         for f in fields:
             field_map[f.name] = f
         d['fields'] = field_map
         d['keyPrefix'] = str(r[_tPartnerNS.keyPrefix])
         d['label'] = str(r[_tPartnerNS.label])
         d['labelPlural'] = str(r[_tPartnerNS.labelPlural])
         d['layoutable'] = _bool(r[_tPartnerNS.layoutable])
         d['mergeable'] = _bool(r[_tPartnerNS.mergeable])
         d['name'] = str(r[_tPartnerNS.name])
         d['queryable'] = _bool(r[_tPartnerNS.queryable])
         d['recordTypeInfos'] = [_extractRecordTypeInfo(rti) for rti in r[_tPartnerNS.recordTypeInfos:]]
         d['replicateable'] = _bool(r[_tPartnerNS.replicateable])
         d['retrieveable'] = _bool(r[_tPartnerNS.retrieveable])
         d['searchable'] = _bool(r[_tPartnerNS.searchable])
         try:
             d['triggerable'] = _bool(r[_tPartnerNS.triggerable])
         except KeyError:
             pass
         d['undeletable'] = _bool(r[_tPartnerNS.undeletable])
         d['updateable'] = _bool(r[_tPartnerNS.updateable])
         d['urlDetail'] = str(r[_tPartnerNS.urlDetail])
         d['urlEdit'] = str(r[_tPartnerNS.urlEdit])
         d['urlNew'] = str(r[_tPartnerNS.urlNew])
         data.append(SObject(**d))
     return data
    def useSession(self, sessionId, serverUrl):
        if ( str(sessionId) == '' or str(serverUrl) == '' ): 
            raise AttributeError , 'Missing server url or session ID to useSession method'
        logging.info( sessionId, serverUrl)
        res = BaseClient.useSession(self, sessionId, serverUrl)
        #print res.__dict__
        data = dict()
#        data['passwordExpired'] = _bool(res[_tPartnerNS.passwordExpired])
#        data['serverUrl'] = str(res[_tPartnerNS.serverUrl])
#        data['sessionId'] = str(res[_tPartnerNS.sessionId])
#        data['userId'] = str(res[_tPartnerNS.userId])
#        data['userInfo'] = _extractUserInfo(res[_tPartnerNS.userInfo])
        self.describeCache = dict()
        return self.getUserInfo()
 def query_old(self, fields, sObjectType, conditionExpression=''):
     #type_data = self.describeSObjects(sObjectType)[0]
     queryString = 'select %s from %s' % (fields, sObjectType)
     if conditionExpression: queryString = '%s where %s' % (queryString, conditionExpression)
     fields = [f.strip() for f in fields.split(',')]
     res = BaseClient.query(self, queryString)
     locator = QueryLocator( str(res[_tPartnerNS.queryLocator]), )
     data = dict(queryLocator = locator,
         done = _bool(res[_tPartnerNS.done]),
         records = [self.extractRecord( r )
                    for r in res[_tPartnerNS.records:]],
         size = int(str(res[_tPartnerNS.size]))
         )
     return data
Esempio n. 13
0
    def search(self, sosl):
        res = BaseClient.search(self, sosl)

        if not self.cacheTypeDescriptions:
            self.flushTypeDescriptionsCache()
        # calculate the union of the sets of record types from each record
        if len(res):
            types = reduce(lambda a,b: a|b, [getRecordTypes(r) for r in res[_tPartnerNS.searchRecords]], set())
            new_types = types - set(self.typeDescs.keys())
            if new_types:
                self.typeDescs.update(self.queryTypesDescriptions(new_types))
            return [self._extractRecord(r) for r in res[_tPartnerNS.searchRecords]]
        else:
            return []
Esempio n. 14
0
 def delete(self, ids):
     res = BaseClient.delete(self, ids)
     if type(res) not in (TupleType, ListType):
         res = [res]
     data = list()
     for r in res:
         d = dict()
         data.append(d)
         d['id'] = str(r[_tPartnerNS.id])
         d['success'] = success = _bool(r[_tPartnerNS.success])
         if not success:
             d['errors'] = [_extractError(e)
                            for e in r[_tPartnerNS.errors:]]
         else:
             d['errors'] = list()
     return data
Esempio n. 15
0
    def retrieve(self, fields, sObjectType, ids):
        resultSet = BaseClient.retrieve(self, fields, sObjectType, ids)
        type_data = self.describeSObjects(sObjectType)[0]

        if type(resultSet) not in (TupleType, ListType):
            if isnil(resultSet):
                resultSet = list()
            else:
                resultSet = [resultSet]
        fields = [f.strip() for f in fields.split(',')]
        data = list()
        for result in resultSet:
            d = dict()
            data.append(d)
            for fname in fields:
                d[fname] = type_data.marshall(fname, result)
        return data
 def describeSObjects(self, sObjectTypes):
     if (self.describeCache.has_key(sObjectTypes)):
         data = list()
         data.append(self.describeCache[sObjectTypes])
         return data
     
     res = BaseClient.describeSObjects(self, sObjectTypes)
     if type(res) not in (TupleType, ListType):
         res = [res]
     data = list()
     for r in res:
         d = dict()
         d['activateable'] = _bool(r[_tPartnerNS.activateable])
         d['createable'] = _bool(r[_tPartnerNS.createable])
         d['custom'] = _bool(r[_tPartnerNS.custom])
         d['deletable'] = _bool(r[_tPartnerNS.deletable])
         fields = r[_tPartnerNS.fields:]
         fields = [_extractFieldInfo(f) for f in fields]
         field_map = dict()
         for f in fields:
             field_map[f.name] = f
         d['fields'] = field_map
         rawreldata = r[_tPartnerNS.ChildRelationships:]
         # why is this list empty ? 
         # print repr(rawreldata)
         relinfo = [_extractChildRelInfo(cr) for cr in rawreldata]
         d['ChildRelationships'] = relinfo
         d['keyPrefix'] = str(r[_tPartnerNS.keyPrefix])
         d['label'] = str(r[_tPartnerNS.label])
         d['labelPlural'] = str(r[_tPartnerNS.labelPlural])
         d['layoutable'] = _bool(r[_tPartnerNS.layoutable])
         d['name'] = str(r[_tPartnerNS.name])
         d['queryable'] = _bool(r[_tPartnerNS.queryable])
         d['replicateable'] = _bool(r[_tPartnerNS.replicateable])
         d['retrieveable'] = _bool(r[_tPartnerNS.retrieveable])
         d['searchable'] = _bool(r[_tPartnerNS.searchable])
         d['undeletable'] = _bool(r[_tPartnerNS.undeletable])
         d['updateable'] = _bool(r[_tPartnerNS.updateable])
         d['urlDetail'] = str(r[_tPartnerNS.urlDetail])
         d['urlEdit'] = str(r[_tPartnerNS.urlEdit])
         d['urlNew'] = str(r[_tPartnerNS.urlNew])
         data.append(SObject(**d))
         self.describeCache[str(r[_tPartnerNS.name])] = SObject(**d)
     
     return data
Esempio n. 17
0
 def upsert(self, externalIdName, sObjects):
     preparedObjects = _prepareSObjects(sObjects)
     res = BaseClient.upsert(self, externalIdName, preparedObjects)
     if type(res) not in (TupleType, ListType):
         res = [res]
     data = list()
     for r in res:
         d = dict()
         data.append(d)
         d['id'] = str(r[_tPartnerNS.id])
         d['success'] = success = _bool(r[_tPartnerNS.success])
         if not success:
             d['errors'] = [_extractError(e)
                            for e in r[_tPartnerNS.errors:]]
         else:
             d['errors'] = list()
         d['isCreated'] = d['created'] = _bool(r[_tPartnerNS.created])
     return data
Esempio n. 18
0
 def describeGlobal(self):
     res = BaseClient.describeGlobal(self)
     data = dict()
     data['encoding'] = str(res[_tPartnerNS.encoding])
     data['maxBatchSize'] = int(str(res[_tPartnerNS.maxBatchSize]))
     sobjects = list()
     for r in res[_tPartnerNS.sobjects:]:
         d = dict()
         d['activateable'] = _bool(r[_tPartnerNS.activateable])
         d['createable'] = _bool(r[_tPartnerNS.createable])
         d['custom'] = _bool(r[_tPartnerNS.custom])
         try:
             d['customSetting'] = _bool(r[_tPartnerNS.customSetting])
         except KeyError:
             pass
         d['deletable'] = _bool(r[_tPartnerNS.deletable])
         d['deprecatedAndHidden'] = _bool(r[_tPartnerNS.deprecatedAndHidden])
         try:
             d['feedEnabled'] = _bool(r[_tPartnerNS.feedEnabled])
         except KeyError:
             pass
         d['keyPrefix'] = str(r[_tPartnerNS.keyPrefix])
         d['label'] = str(r[_tPartnerNS.label])
         d['labelPlural'] = str(r[_tPartnerNS.labelPlural])
         d['layoutable'] = _bool(r[_tPartnerNS.layoutable])
         d['mergeable'] = _bool(r[_tPartnerNS.mergeable])
         d['name'] = str(r[_tPartnerNS.name])
         d['queryable'] = _bool(r[_tPartnerNS.queryable])
         d['replicateable'] = _bool(r[_tPartnerNS.replicateable])
         d['retrieveable'] = _bool(r[_tPartnerNS.retrieveable])
         d['searchable'] = _bool(r[_tPartnerNS.searchable])
         d['triggerable'] = _bool(r[_tPartnerNS.triggerable])
         d['undeletable'] = _bool(r[_tPartnerNS.undeletable])
         d['updateable'] = _bool(r[_tPartnerNS.updateable])
         sobjects.append(SObject(**d))
     data['sobjects'] = sobjects
     data['types'] = [str(t) for t in res[_tPartnerNS.types:]]
     if not data['types']:
         # BBB for code written against API < 17.0
         data['types'] = [s.name for s in data['sobjects']]
     return data
Esempio n. 19
0
 def executeanonymous(self, code):
     res = BaseClient.executeanonymous(self, code)
     data = dict()
     logging.info( res )
     return data
Esempio n. 20
0
 def getUserInfo(self):
     res = BaseClient.getUserInfo(self)
     data = _extractUserInfo(res)
     return data
Esempio n. 21
0
 def getUserInfo(self):
     res = BaseClient.getUserInfo(self)
     data = _extractUserInfo(res)
     return data
Esempio n. 22
0
 def __init__(self, serverUrl=None, cacheTypeDescriptions=False):
     BaseClient.__init__(self, serverUrl=serverUrl)
     self.cacheTypeDescriptions = cacheTypeDescriptions
     self.typeDescs = {}
Esempio n. 23
0
 def getUpdated(self, sObjectType, start, end):
     res = BaseClient.getUpdated(self, sObjectType, start, end)
     res = res[_tPartnerNS.ids:]
     if type(res) not in (TupleType, ListType):
         res = [res]
     return [str(r) for r in res]
Esempio n. 24
0
 def metacreate(self, metadata):
     res = BaseClient.metacreate(self, metadata)          
     return _extractAsyncResult(res)
Esempio n. 25
0
 def checkstatus(self, id):
     res = BaseClient.checkstatus(self, id)
     return _extractAsyncResult(res)
 def __init__(self, serverUrl=None, cacheTypeDescriptions=False):
     BaseClient.__init__(self, serverUrl=serverUrl)
     self.cacheTypeDescriptions = cacheTypeDescriptions
     self.typeDescs = {}
Esempio n. 27
0
 def getUpdated(self, sObjectType, start, end):
     res = BaseClient.getUpdated(self, sObjectType, start, end)
     res = res[_tPartnerNS.ids:]
     if type(res) not in (TupleType, ListType):
         res = [res]
     return [str(r) for r in res]