Skip to content

Commit

Permalink
Merge pull request #31 from ViViDboarder/xmltramp_tuple_indexes
Browse files Browse the repository at this point in the history
Xmltramp tuple indexes [Adds Pypy support]
  • Loading branch information
ellieayla committed Feb 18, 2016
2 parents a80d31f + a847c25 commit c0362cb
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 88 deletions.
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.PHONY: test

PYPY := $(shell which pypy 2>/dev/null)

default: test

test:
@echo "testing with python"
python ./src/pyforce/xmltramp.py
ifdef PYPY
pypy ./src/pyforce/xmltramp.py
else
@echo "pypy not installed... skipping test"
endif

clean:
find . -name '*.pyc' -delete
find . -name '__pycache__' -delete
28 changes: 14 additions & 14 deletions examples/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def getServerTimestamp(self):
def describeGlobal(self):
print "\ndescribeGlobal"
dg = svc.describeGlobal()
for t in dg[sf.types:]:
for t in dg[sf.types,]:
print str(t)

def describeTabs(self):
Expand All @@ -34,29 +34,29 @@ def query(self):
qr = svc.query("select Id, Name from Account")
print "query size = " + str(qr[sf.size])

for rec in qr[sf.records:]:
for rec in qr[sf.records,]:
print str(rec[0]) + " : " + str(rec[2]) + " : " + str(rec[3])

if (str(qr[sf.done]) == 'false'):
print "\nqueryMore"
qr = svc.queryMore(str(qr[sf.queryLocator]))
for rec in qr[sf.records:]:
for rec in qr[sf.records,]:
print str(rec[0]) + " : " + str(rec[2]) + " : " + str(rec[3])

def upsert(self):
print "\nupsert"
t = { 'type': 'Task',
'ChandlerId__c': '12345',
'subject': 'BeatBoxTest updated',
t = { 'type': 'Task',
'ChandlerId__c': '12345',
'subject': 'BeatBoxTest updated',
'ActivityDate' : datetime.date(2006,2,20) }

ur = svc.upsert('ChandlerId__c', t)
print str(ur[sf.success]) + " -> " + str(ur[sf.id])

t = {'type': 'Event',
'ChandlerId__c': '67890',
'durationinminutes': 45,
'subject': 'BeatBoxTest',
t = {'type': 'Event',
'ChandlerId__c': '67890',
'durationinminutes': 45,
'subject': 'BeatBoxTest',
'ActivityDateTime' : datetime.datetime(2006,2,20,13,30,30),
'IsPrivate': False }
ur = svc.upsert('ChandlerId__c', t)
Expand Down Expand Up @@ -141,22 +141,22 @@ def resetPassword(self):
def describeSObjects(self):
print "\ndescribeSObjects(Account)"
desc = svc.describeSObjects("Account")
for f in desc[sf.fields:]:
for f in desc[sf.fields,]:
print "\t" + str(f[sf.name])

print "\ndescribeSObjects(Lead, Contact)"
desc = svc.describeSObjects(["Lead", "Contact"])
for d in desc:
print str(d[sf.name]) + "\n" + ( "-" * len(str(d[sf.name])))
for f in d[sf.fields:]:
for f in d[sf.fields,]:
print "\t" + str(f[sf.name])

def describeLayout(self):
print "\ndescribeLayout(Account)"
desc = svc.describeLayout("Account")
for layout in desc[sf.layouts:]:
for layout in desc[sf.layouts,]:
print "sections in detail layout " + str(layout[sf.id])
for s in layout[sf.detailLayoutSections:]:
for s in layout[sf.detailLayoutSections,]:
print "\t" + str(s[sf.heading])


Expand Down
4 changes: 2 additions & 2 deletions examples/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
def buildSoql(sobjectName):
dr = svc.describeSObjects(sobjectName)
soql = ""
for f in dr[sf.fields:]:
for f in dr[sf.fields,]:
if len(soql) > 0: soql += ','
soql += str(f[sf.name])
return "select " + soql + " from " + sobjectName
Expand All @@ -35,7 +35,7 @@ def export(username, password, objectOrSoql):
printHeaders = 1
while True:
if printHeaders: printColumnHeaders(qr); printHeaders = 0
for row in qr[sf.records:]:
for row in qr[sf.records,]:
needsComma = False
for col in row[2:]:
if needsComma: print ',',
Expand Down
12 changes: 6 additions & 6 deletions examples/soql2atom.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from xml.sax.xmlreader import AttributesNSImpl
import datetime
from urlparse import urlparse
import os
import os
import base64
import string

Expand Down Expand Up @@ -73,15 +73,15 @@ def soql2atom(loginResult, soql, title):
x.writeStringElement(atom_ns, "name", str(userInfo.userFullName))
x.endElement()
x.characters("\n")
rel = AttributesNSImpl( {(None, "rel"): "self", (None, "href") : thisUrl},
rel = AttributesNSImpl( {(None, "rel"): "self", (None, "href") : thisUrl},
{(None, "rel"): "rel", (None, "href"): "href"})
x.startElement(atom_ns, "link", rel)
x.endElement()
x.writeStringElement(atom_ns, "updated", datetime.datetime.utcnow().isoformat() +"Z")
x.writeStringElement(atom_ns, "updated", datetime.datetime.utcnow().isoformat() +"Z")
x.writeStringElement(atom_ns, "id", thisUrl + "&userid=" + str(loginResult[pyforce._tPartnerNS.userId]))
x.characters("\n")
type = AttributesNSImpl({(None, u"type") : "html"}, {(None, u"type") : u"type" })
for row in qr[sf.records:]:
for row in qr[sf.records,]:
x.startElement(atom_ns, "entry")
desc = ""
x.writeStringElement(atom_ns, "title", str(row[2]))
Expand All @@ -105,7 +105,7 @@ def soql2atom(loginResult, soql, title):
print x.endDocument()

def writeLink(x, namespace, localname, rel, type, href):
rel = AttributesNSImpl( {(None, "rel"): rel, (None, "href"): href, (None, "type"): type },
rel = AttributesNSImpl( {(None, "rel"): rel, (None, "href"): href, (None, "type"): type },
{(None, "rel"): "rel", (None, "href"): "href", (None, "type"): "type"})
x.startElement(namespace, localname, rel)
x.endElement()
Expand All @@ -129,7 +129,7 @@ def authenticationRequired(message="Unauthorized"):
if form.has_key("title"):
title = form.getvalue("title")
try:
lr = svc.login(username, password)
lr = svc.login(username, password)
soql2atom(lr, soql, title)
except pyforce.SoapFaultError, sfe:
if (sfe.faultCode == 'INVALID_LOGIN'):
Expand Down
2 changes: 1 addition & 1 deletion src/pyforce/marshall.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def textMarshaller(fieldname, xml, ns):


def multiMarshaller(fieldname, xml, ns):
asString = str(xml[getattr(ns, fieldname):][0])
asString = str(xml[getattr(ns, fieldname),][0])
if not asString:
return []
return asString.split(';')
Expand Down
50 changes: 25 additions & 25 deletions src/pyforce/pyforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def describeGlobal(self):
data['encoding'] = str(res[_tPartnerNS.encoding])
data['maxBatchSize'] = int(str(res[_tPartnerNS.maxBatchSize]))
sobjects = list()
for r in res[_tPartnerNS.sobjects:]:
for r in res[_tPartnerNS.sobjects,]:
d = dict()
d['activateable'] = _bool(r[_tPartnerNS.activateable])
d['createable'] = _bool(r[_tPartnerNS.createable])
Expand Down Expand Up @@ -134,7 +134,7 @@ def describeGlobal(self):
d['updateable'] = _bool(r[_tPartnerNS.updateable])
sobjects.append(SObject(**d))
data['sobjects'] = sobjects
data['types'] = [str(t) for t in res[_tPartnerNS.types:]]
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']]
Expand All @@ -148,7 +148,7 @@ def describeSObjects(self, sObjectTypes):
for r in res:
d = dict()
d['activateable'] = _bool(r[_tPartnerNS.activateable])
rawreldata = r[_tPartnerNS.ChildRelationships:]
rawreldata = r[_tPartnerNS.ChildRelationships,]
relinfo = [_extractChildRelInfo(cr) for cr in rawreldata]
d['ChildRelationships'] = relinfo
d['createable'] = _bool(r[_tPartnerNS.createable])
Expand All @@ -165,7 +165,7 @@ def describeSObjects(self, sObjectTypes):
d['feedEnabled'] = _bool(r[_tPartnerNS.feedEnabled])
except KeyError:
pass
fields = r[_tPartnerNS.fields:]
fields = r[_tPartnerNS.fields,]
fields = [_extractFieldInfo(f) for f in fields]
field_map = dict()
for f in fields:
Expand All @@ -179,7 +179,7 @@ def describeSObjects(self, sObjectTypes):
d['name'] = str(r[_tPartnerNS.name])
d['queryable'] = _bool(r[_tPartnerNS.queryable])
d['recordTypeInfos'] = ([_extractRecordTypeInfo(rti) for rti in
r[_tPartnerNS.recordTypeInfos:]])
r[_tPartnerNS.recordTypeInfos,]])
d['replicateable'] = _bool(r[_tPartnerNS.replicateable])
d['retrieveable'] = _bool(r[_tPartnerNS.retrieveable])
d['searchable'] = _bool(r[_tPartnerNS.searchable])
Expand Down Expand Up @@ -208,7 +208,7 @@ def create(self, sObjects):
d['success'] = success = _bool(r[_tPartnerNS.success])
if not success:
d['errors'] = [_extractError(e)
for e in r[_tPartnerNS.errors:]]
for e in r[_tPartnerNS.errors,]]
else:
d['errors'] = list()
return data
Expand All @@ -226,7 +226,7 @@ def convert_leads(self, lead_converts):
d['success'] = success = _bool(resu[_tPartnerNS.success])
if not success:
d['errors'] = [_extractError(e)
for e in resu[_tPartnerNS.errors:]]
for e in resu[_tPartnerNS.errors,]]
else:
d['errors'] = list()
d['account_id'] = str(resu[_tPartnerNS.accountId])
Expand Down Expand Up @@ -272,7 +272,7 @@ def sendEmail(self, emails, mass_type='SingleEmailMessage'):
d['success'] = success = _bool(resu[_tPartnerNS.success])
if not success:
d['errors'] = [_extractError(e)
for e in resu[_tPartnerNS.errors:]]
for e in resu[_tPartnerNS.errors,]]
else:
d['errors'] = list()
return data
Expand Down Expand Up @@ -308,7 +308,7 @@ def update(self, sObjects):
d['success'] = success = _bool(r[_tPartnerNS.success])
if not success:
d['errors'] = [_extractError(e)
for e in r[_tPartnerNS.errors:]]
for e in r[_tPartnerNS.errors,]]
else:
d['errors'] = list()
return data
Expand Down Expand Up @@ -337,12 +337,12 @@ def _extractRecord(self, r, typeDescs):
fname = str(field._name[1])
if isObject(field):
record[fname] = self._extractRecord(
r[field._name:][0], typeDescs
r[field._name,][0], typeDescs
)
elif isQueryResult(field):
record[fname] = QueryRecordSet(
records=[self._extractRecord(rec, typeDescs) for rec
in field[_tPartnerNS.records:]],
in field[_tPartnerNS.records,]],
done=field[_tPartnerNS.done],
size=int(str(field[_tPartnerNS.size]))
)
Expand Down Expand Up @@ -377,13 +377,13 @@ def query(self, *args, **kw):
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())
res[_tPartnerNS.records,]], set())
new_types = types - set(typeDescs.keys())
if new_types:
typeDescs.update(self.queryTypesDescriptions(new_types))
data = QueryRecordSet(
records=[self._extractRecord(r, typeDescs) for r in
res[_tPartnerNS.records:]],
res[_tPartnerNS.records,]],
done=_bool(res[_tPartnerNS.done]),
size=int(str(res[_tPartnerNS.size])),
queryLocator=str(res[_tPartnerNS.queryLocator])
Expand All @@ -400,13 +400,13 @@ def queryMore(self, 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())
res[_tPartnerNS.records,]], set())
new_types = types - set(typeDescs.keys())
if new_types:
typeDescs.update(self.queryTypesDescriptions(new_types))
data = QueryRecordSet(
records=[self._extractRecord(r, typeDescs) for r in
res[_tPartnerNS.records:]],
res[_tPartnerNS.records,]],
done=_bool(res[_tPartnerNS.done]),
size=int(str(res[_tPartnerNS.size])),
queryLocator=str(res[_tPartnerNS.queryLocator])
Expand Down Expand Up @@ -444,7 +444,7 @@ def delete(self, ids):
d['success'] = success = _bool(r[_tPartnerNS.success])
if not success:
d['errors'] = [_extractError(e)
for e in r[_tPartnerNS.errors:]]
for e in r[_tPartnerNS.errors,]]
else:
d['errors'] = list()
return data
Expand All @@ -462,15 +462,15 @@ def upsert(self, externalIdName, sObjects):
d['success'] = success = _bool(r[_tPartnerNS.success])
if not success:
d['errors'] = [_extractError(e)
for e in r[_tPartnerNS.errors:]]
for e in r[_tPartnerNS.errors,]]
else:
d['errors'] = list()
d['isCreated'] = d['created'] = _bool(r[_tPartnerNS.created])
return data

def getDeleted(self, sObjectType, start, end):
res = BaseClient.getDeleted(self, sObjectType, start, end)
res = res[_tPartnerNS.deletedRecords:]
res = res[_tPartnerNS.deletedRecords,]
if type(res) not in (TupleType, ListType):
res = [res]
data = list()
Expand All @@ -487,7 +487,7 @@ def getDeleted(self, sObjectType, start, end):

def getUpdated(self, sObjectType, start, end):
res = BaseClient.getUpdated(self, sObjectType, start, end)
res = res[_tPartnerNS.ids:]
res = res[_tPartnerNS.ids,]
if type(res) not in (TupleType, ListType):
res = [res]
return [str(r) for r in res]
Expand All @@ -501,7 +501,7 @@ def describeTabs(self):
res = BaseClient.describeTabs(self)
data = list()
for r in res:
tabs = [_extractTab(t) for t in r[_tPartnerNS.tabs:]]
tabs = [_extractTab(t) for t in r[_tPartnerNS.tabs,]]
d = dict(
label=str(r[_tPartnerNS.label]),
logoUrl=str(r[_tPartnerNS.logoUrl]),
Expand Down Expand Up @@ -595,10 +595,10 @@ def _extractFieldInfo(fdata):
data['length'] = int(str(fdata[_tPartnerNS.length]))
data['name'] = str(fdata[_tPartnerNS.name])
data['nameField'] = _bool(fdata[_tPartnerNS.nameField])
plValues = fdata[_tPartnerNS.picklistValues:]
plValues = fdata[_tPartnerNS.picklistValues,]
data['picklistValues'] = [_extractPicklistEntry(p) for p in plValues]
data['precision'] = int(str(fdata[_tPartnerNS.precision]))
data['referenceTo'] = [str(r) for r in fdata[_tPartnerNS.referenceTo:]]
data['referenceTo'] = [str(r) for r in fdata[_tPartnerNS.referenceTo,]]
data['restrictedPicklist'] = _bool(fdata[_tPartnerNS.restrictedPicklist])
data['scale'] = int(str(fdata[_tPartnerNS.scale]))
data['soapType'] = str(fdata[_tPartnerNS.soapType])
Expand All @@ -616,7 +616,7 @@ def _extractFieldInfo(fdata):
def _extractPicklistEntry(pldata):
data = dict()
data['active'] = _bool(pldata[_tPartnerNS.active])
data['validFor'] = [str(v) for v in pldata[_tPartnerNS.validFor:]]
data['validFor'] = [str(v) for v in pldata[_tPartnerNS.validFor,]]
data['defaultValue'] = _bool(pldata[_tPartnerNS.defaultValue])
data['label'] = str(pldata[_tPartnerNS.label])
data['value'] = str(pldata[_tPartnerNS.value])
Expand Down Expand Up @@ -646,7 +646,7 @@ def _extractError(edata):
data = dict()
data['statusCode'] = str(edata[_tPartnerNS.statusCode])
data['message'] = str(edata[_tPartnerNS.message])
data['fields'] = [str(f) for f in edata[_tPartnerNS.fields:]]
data['fields'] = [str(f) for f in edata[_tPartnerNS.fields,]]
return data


Expand Down Expand Up @@ -721,5 +721,5 @@ def getRecordTypes(xml):
elif isQueryResult(field):
record_types.update(reduce(lambda x, y: x | y, [
getRecordTypes(r) for r in
field[_tPartnerNS.records:]]))
field[_tPartnerNS.records,]]))
return record_types
2 changes: 1 addition & 1 deletion src/pyforce/tests/test_xmlclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def testQuery(self):
"from Contact where LastName = 'Doe' and FirstName = 'Jane'")
res = svc.query(query)
self.assertEqual(int(str(res[partnerns.size])), 1)
records = res[partnerns.records:]
records = res[partnerns.records,]
self.assertEqual(
janeid, str(records[0][pyforce._tSObjectNS.Id]))

Expand Down
Loading

0 comments on commit c0362cb

Please sign in to comment.