本文整理汇总了Python中meresco.components.json.JsonDict.loads方法的典型用法代码示例。如果您正苦于以下问题:Python JsonDict.loads方法的具体用法?Python JsonDict.loads怎么用?Python JsonDict.loads使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类meresco.components.json.JsonDict
的用法示例。
在下文中一共展示了JsonDict.loads方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validate
# 需要导入模块: from meresco.components.json import JsonDict [as 别名]
# 或者: from meresco.components.json.JsonDict import loads [as 别名]
def validate(self):
for core in self.cores:
if core == self.resultsFrom:
continue
try:
self._matchCoreSpecs(self.resultsFrom, core)
except KeyError:
raise ValueError("No match set for cores %s" % str((self.resultsFrom, core)))
if self.relationalFilterJson:
try:
JsonDict.loads(self.relationalFilterJson)
except JSONDecodeError:
raise ValueError("Value '%s' for 'relationalFilterJson' can not be parsed as JSON." % self.relationalFilterJson)
示例2: testGetStatusForDomain
# 需要导入模块: from meresco.components.json import JsonDict [as 别名]
# 或者: from meresco.components.json.JsonDict import loads [as 别名]
def testGetStatusForDomain(self):
self.controlHelper(action='allInvalid')
self.startHarvester(repository=REPOSITORY)
header, result = getRequest(self.harvesterInternalServerPortNumber, '/get', {'verb': 'GetStatus', 'domainId': 'adomain'}, parse=False)
data = JsonDict.loads(result)
self.assertEquals(2, len(data['response']['GetStatus']))
self.assertEquals("adomain", data['request']['domainId'])
示例3: testClear
# 需要导入模块: from meresco.components.json import JsonDict [as 别名]
# 或者: from meresco.components.json.JsonDict import loads [as 别名]
def testClear(self):
self.startHarvester(repository=REPOSITORY)
self.assertEquals(BATCHSIZE, self.sizeDumpDir())
header, result = getRequest(self.harvesterInternalServerPortNumber, '/get', {'verb': 'GetStatus', 'domainId': DOMAIN, 'repositoryId': REPOSITORY}, parse=False)
data = JsonDict.loads(result)
self.assertEquals(8, data['response']['GetStatus'][0]['total'])
self.saveRepository(DOMAIN, REPOSITORY, REPOSITORYGROUP, action='clear')
self.startHarvester(repository=REPOSITORY)
self.assertEquals(18, self.sizeDumpDir())
for filename in sorted(listdir(self.dumpDir))[-8:]:
self.assertTrue('_delete.updateRequest' in filename, filename)
header, result = getRequest(self.harvesterInternalServerPortNumber, '/get', {'verb': 'GetStatus', 'domainId': DOMAIN, 'repositoryId': REPOSITORY}, parse=False)
self.assertEqual(0, JsonDict.loads(result)['response']['GetStatus'][0]['total'])
示例4: testRemovingNotListedKeys
# 需要导入模块: from meresco.components.json import JsonDict [as 别名]
# 或者: from meresco.components.json.JsonDict import loads [as 别名]
def testRemovingNotListedKeys(self):
result = asString(self.dna.all.handleRequest(
path='/service/v2/list',
Method='GET',
arguments={'keys':['-no']}
))
header, body = httpSplit(result)
dictBodyV2 = JsonDict.loads(body)
self.assertEquals(['api_version', 'config', 'domain', 'services', 'software_version'], sorted(dictBodyV2.keys()))
示例5: testKeysAll
# 需要导入模块: from meresco.components.json import JsonDict [as 别名]
# 或者: from meresco.components.json.JsonDict import loads [as 别名]
def testKeysAll(self):
result = asString(self.dna.all.handleRequest(
path='/service/v2/list',
Method='GET',
arguments={'__all__':['True']}
))
header, body = httpSplit(result)
dictBodyV2 = JsonDict.loads(body)
self.assertEquals(['api_version', 'collections', 'config', 'domain', 'other', 'services', 'software_version'], sorted(dictBodyV2.keys()))
示例6: testNonexistingKeys
# 需要导入模块: from meresco.components.json import JsonDict [as 别名]
# 或者: from meresco.components.json.JsonDict import loads [as 别名]
def testNonexistingKeys(self):
result = asString(self.dna.all.handleRequest(
path='/service/v2/list',
Method='GET',
arguments={'keys':['no']}
))
header, body = httpSplit(result)
dictBodyV2 = JsonDict.loads(body)
self.assertEquals(['api_version', 'config', 'domain', 'errors', 'services', 'software_version'], sorted(dictBodyV2.keys()))
self.assertEquals(["Key 'no' not found."], dictBodyV2['errors'])
示例7: testGetStatusForDomainAndRepositoryId
# 需要导入模块: from meresco.components.json import JsonDict [as 别名]
# 或者: from meresco.components.json.JsonDict import loads [as 别名]
def testGetStatusForDomainAndRepositoryId(self):
self.controlHelper(action='allInvalid')
self.startHarvester(repository=REPOSITORY)
header, result = getRequest(self.harvesterInternalServerPortNumber, '/get', {'verb': 'GetStatus', 'domainId': 'adomain', 'repositoryId': 'integrationtest'}, parse=False)
data = JsonDict.loads(result)
self.assertEquals("GetStatus", data['request']['verb'])
self.assertEquals("adomain", data['request']['domainId'])
self.assertEquals("integrationtest", data['request']['repositoryId'])
self.assertEquals("IntegrationTest", data['response']['GetStatus'][0]['repositoryGroupId'])
self.assertEquals(6, data['response']['GetStatus'][0]['invalid'])
示例8: testShouldHaveGlobalConfigForVersion2
# 需要导入模块: from meresco.components.json import JsonDict [as 别名]
# 或者: from meresco.components.json.JsonDict import loads [as 别名]
def testShouldHaveGlobalConfigForVersion2(self):
result = asString(self.dna.all.handleRequest(
path='/service/v2/list',
arguments={},
Method='GET',
))
header, body = httpSplit(result)
dictBodyV2 = JsonDict.loads(body)
self.assertEquals(['host', 'port'], sorted(dictBodyV2['config'].keys()))
self.assertEquals(['api_version', 'config', 'domain', 'services', 'software_version'], sorted(dictBodyV2.keys()))
示例9: testAllKeys
# 需要导入模块: from meresco.components.json import JsonDict [as 别名]
# 或者: from meresco.components.json.JsonDict import loads [as 别名]
def testAllKeys(self):
result = asString(self.dna.all.handleRequest(
path='/service/v2/list',
Method='GET',
arguments={'keys':['collections,other']}
))
header, body = httpSplit(result)
dictBodyV2 = JsonDict.loads(body)
self.assertEquals(['api_version', 'collections', 'config', 'domain', 'other', 'services', 'software_version'], sorted(dictBodyV2.keys()))
self.assertEquals({'collection': {'provenanceSource': 'collection_source', 'enabled': True, 'name': 'collection'}}, dictBodyV2['collections'])
self.assertEquals(['other'], dictBodyV2['other'])
self.assertEquals({'host': 'localhost', 'port': 8000}, dictBodyV2['config'])
self.assertEquals({}, dictBodyV2['services'])
示例10: testGetSomethingIsAllowed
# 需要导入模块: from meresco.components.json import JsonDict [as 别名]
# 或者: from meresco.components.json.JsonDict import loads [as 别名]
def testGetSomethingIsAllowed(self):
dataRetrieve = HarvesterDataRetrieve()
observer = CallTrace('observer', returnValues=dict(getSomething='get something result', listSomething=['a', 'b']))
dataRetrieve.addObserver(observer)
result = asString(dataRetrieve.handleRequest(arguments=dict(verb=['GetSomething'], argument=['value'])))
header, body = result.split(CRLF*2,1)
self.assertEqual(okJson, header+CRLF*2)
self.assertEquals({'request': {
'verb': 'GetSomething', 'argument': 'value',
}, 'response': {'GetSomething': 'get something result'}}, JsonDict.loads(body))
self.assertEquals(['getSomething'], observer.calledMethodNames())
self.assertEquals({'argument': 'value'}, observer.calledMethods[0].kwargs)
示例11: parseHeaderAndBody
# 需要导入模块: from meresco.components.json import JsonDict [as 别名]
# 或者: from meresco.components.json.JsonDict import loads [as 别名]
def parseHeaderAndBody(h, b=None, parseBody=True):
if b is None:
h, b = h
header, body = parseResponse(h + CRLF * 2 + b)
if body and parseBody and 'Content-Type' in header['Headers']:
contentType = header['Headers']['Content-Type']
if 'xml' in contentType:
return header, XML(body)
if 'json' in contentType:
try:
return header, JsonDict.loads(body) if body[0] == '{' else JsonList.loads(body)
except JSONDecodeError:
return header, 'JSONDecodeError in: ' + body
return header, body
示例12: _load
# 需要导入模块: from meresco.components.json import JsonDict [as 别名]
# 或者: from meresco.components.json.JsonDict import loads [as 别名]
def _load(self):
if not isfile(self._jsonFilepath):
return {}
data = open(self._jsonFilepath).read().strip()
result = {}
if '[' != data[0]:
for identifier, serviceDict in JsonDict.loads(data).items():
service = Service(domainname=self._domainname, timeout=self._timeout, identifier=identifier, ultimateTimeout=self._ultimateTimeout, **serviceDict)
service.validate()
result[service.identifier] = service
return result
for service in (Service(domainname=self._domainname, timeout=self._timeout, ultimateTimeout=self._ultimateTimeout, **item) for item in JsonList.loads(data)):
service.validate()
result[service.identifier] = service
return result
示例13: testShouldReturnOnlyRequestedKeysWithUpdate
# 需要导入模块: from meresco.components.json import JsonDict [as 别名]
# 或者: from meresco.components.json.JsonDict import loads [as 别名]
def testShouldReturnOnlyRequestedKeysWithUpdate(self):
hash = serviceUpdateHash(secret='guessme!', identifier='cc635329-c089-41a8-91be-2a4554851515', type='srv', ipAddress='127.0.0.1', infoport=1234)
postBody = urlencode({
'identifier': 'cc635329-c089-41a8-91be-2a4554851515',
'type': 'srv',
'ipAddress': '127.0.0.1',
'infoport': '1234',
'data': dumps({'VERSION': '2.718281828'}),
'hash': hash,
})
result = ''.join(compose(self.dna.all.handleRequest(
path='/service/v2/update',
Method='POST',
arguments={'keys':['collections']},
Body=postBody,
)))
header, body = httpSplit(result)
dictBodyV2 = JsonDict.loads(body)
self.assertEquals(['api_version', 'collections', 'config', 'domain', 'services', 'software_version', 'this_service'], sorted(dictBodyV2.keys()))
示例14: _add
# 需要导入模块: from meresco.components.json import JsonDict [as 别名]
# 或者: from meresco.components.json.JsonDict import loads [as 别名]
def _add(self, values, identifier, **kwargs):
self._validate(self, identifier=identifier, **kwargs)
olddata = values.get(identifier, {})
data = dict()
for key in self._register['keys']:
data[key] = kwargs.get(key, [olddata.get(key, '')])[0]
for key in self._register['listKeys']:
data[key] = kwargs.get(key, olddata.get(key, []))
for key in self._register['jsonKeys']:
newdata = kwargs.get(key, [None])[0]
if newdata is None and key in olddata:
data[key] = olddata[key]
continue
data[key] = JsonDict.loads(newdata or '{}')
for key in self._register['booleanKeys']:
data[key] = olddata.get(key, False)
for key in kwargs.get('__booleanKeys__', self._register['booleanKeys']):
if not key:
continue
data[key] = key in kwargs
values[identifier] = data
self._save(values)
示例15: testShouldUpdateServicesOnHttpPostRequest
# 需要导入模块: from meresco.components.json import JsonDict [as 别名]
# 或者: from meresco.components.json.JsonDict import loads [as 别名]
def testShouldUpdateServicesOnHttpPostRequest(self):
hash = serviceUpdateHash(secret='guessme!', identifier='cc635329-c089-41a8-91be-2a4554851515', type='srv', ipAddress='127.0.0.1', infoport=1234)
postBody = urlencode({
'identifier': 'cc635329-c089-41a8-91be-2a4554851515',
'type': 'srv',
'ipAddress': '127.0.0.1',
'infoport': '1234',
'hash': hash,
'data': dumps({'error': 1, 'VERSION': '2.718281828'}),
})
result = ''.join(compose(self.dna.all.handleRequest(
path='/service/v2/update',
Method='POST',
arguments={},
Body=postBody,
)))
header, body = httpSplit(result)
dictBody = JsonDict.loads(body)
lastseen = dictBody['services']['cc635329-c089-41a8-91be-2a4554851515']['lastseen']
body = dictBody.pretty_print()
self.assertEquals('HTTP/1.0 200 OK\r\nContent-Type: application/json; charset=utf-8', header)
self.assertEquals(
{
"services": {
"cc635329-c089-41a8-91be-2a4554851515": {
"type": "srv",
"fqdn": "srv0.seecr.nl",
"identifier": "cc635329-c089-41a8-91be-2a4554851515",
"number": 0,
"lastseen": lastseen,
"lastseen_delta": 0,
"active": True,
"ipAddress": "127.0.0.1",
"infoport": 1234,
'readable': False,
'writable': False,
'data': {'error': 1, 'VERSION': '2.718281828'}
}
},
"this_service": {
"type": "srv",
"fqdn": "srv0.seecr.nl",
"identifier": "cc635329-c089-41a8-91be-2a4554851515",
"number": 0,
"lastseen": lastseen,
"lastseen_delta": 0,
"active": True,
"ipAddress": "127.0.0.1",
"infoport": 1234,
'readable': False,
'writable': False,
"state": {
'readable': False,
'writable': False,
},
'data': {'error': 1, 'VERSION': '2.718281828'}
},
"config": {
"host": "localhost",
"port": 8000
},
'api_version': 2,
'software_version': '42',
'domain': 'seecr.nl'
}, loads(body))
result = self.serviceRegistry.listServices()
result['cc635329-c089-41a8-91be-2a4554851515']['lastseen'] = 666.6
self.assertEquals({
'cc635329-c089-41a8-91be-2a4554851515': {
'type': 'srv',
'fqdn': 'srv0.seecr.nl',
"identifier": "cc635329-c089-41a8-91be-2a4554851515",
'number': 0,
'lastseen': 666.6,
"lastseen_delta": 0,
'active': True,
'ipAddress': '127.0.0.1',
'infoport': 1234,
'readable': False,
'writable': False,
'data': {'error': 1, 'VERSION': '2.718281828'}}
}, result)
self.assertEquals(['getConfig'], self.configuration.calledMethodNames())
self.assertEquals(["updateZone"], self.dns.calledMethodNames())
self.assertEquals([((), {'ipAddress': '127.0.0.1', 'fqdn': 'srv0.seecr.nl'})], [(m.args, m.kwargs) for m in self.dns.calledMethods])