本文整理汇总了Python中meresco.components.json.JsonDict.load方法的典型用法代码示例。如果您正苦于以下问题:Python JsonDict.load方法的具体用法?Python JsonDict.load怎么用?Python JsonDict.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类meresco.components.json.JsonDict
的用法示例。
在下文中一共展示了JsonDict.load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testLoadEmptyFile
# 需要导入模块: from meresco.components.json import JsonDict [as 别名]
# 或者: from meresco.components.json.JsonDict import load [as 别名]
def testLoadEmptyFile(self):
tempfile = join(self.tempdir, 'json.json')
open(tempfile, 'w').close()
self.assertRaises(JSONDecodeError, lambda: JsonDict.load(tempfile))
self.assertEquals({}, JsonDict.load(tempfile, emptyOnError=True))
self.assertRaises(JSONDecodeError, lambda: JsonList.load(tempfile))
self.assertEquals([], JsonList.load(tempfile, emptyOnError=True))
示例2: getRepositoryIds
# 需要导入模块: from meresco.components.json import JsonDict [as 别名]
# 或者: from meresco.components.json.JsonDict import load [as 别名]
def getRepositoryIds(self, domainId, repositoryGroupId=None):
result = JsonList()
allIds = self.getRepositoryGroupIds(domainId) if repositoryGroupId is None else [repositoryGroupId]
for repositoryGroupId in allIds:
jsonData = JsonDict.load(open(join(self._dataPath, '%s.%s.repositoryGroup' % (domainId, repositoryGroupId))))
result.extend(jsonData.get('repositoryIds', []))
return result
示例3: _read
# 需要导入模块: from meresco.components.json import JsonDict [as 别名]
# 或者: from meresco.components.json.JsonDict import load [as 别名]
def _read(self):
result = JsonDict.load(self._filename)
assert result['version'] == self.version, 'Expected database version %s' % self.version
groups = set(self._groups)
groups.update(set(result['data']['groups']))
self._groups = list(groups)
self._users.update(result['data']['users'])
示例4: urlJsonDict
# 需要导入模块: from meresco.components.json import JsonDict [as 别名]
# 或者: from meresco.components.json.JsonDict import load [as 别名]
def urlJsonDict(self, **kwargs):
arguments = dict((k ,v) for k, v in kwargs.items() if v)
result = JsonDict.load(
self._urlopen("{}/get?{}".format(self._internalurl, urlencode(arguments)))
)
if 'error' in result:
raise ValueError(result['error']['message'])
return result
示例5: getRepositories
# 需要导入模块: from meresco.components.json import JsonDict [as 别名]
# 或者: from meresco.components.json.JsonDict import load [as 别名]
def getRepositories(self, domainId, repositoryGroupId=None):
try:
repositoryIds = self.getRepositoryIds(domainId=domainId, repositoryGroupId=repositoryGroupId)
except IOError:
raise ValueError("idDoesNotExist")
return JsonList([
JsonDict.load(open(join(self._dataPath, '%s.%s.repository' % (domainId, repositoryId))))
for repositoryId in repositoryIds
])
示例6: load
# 需要导入模块: from meresco.components.json import JsonDict [as 别名]
# 或者: from meresco.components.json.JsonDict import load [as 别名]
def load(cls, filePath):
state = cls(filePath=filePath)
if isfile(filePath):
d = JsonDict.load(filePath)
state.datetime = d.get('datetime')
state.harvestingReady = d.get('harvestingReady', False)
state.error = d.get('error')
state.resumptionAttributes = d.get('resumptionAttributes')
return state
示例7: _download
# 需要导入模块: from meresco.components.json import JsonDict [as 别名]
# 或者: from meresco.components.json.JsonDict import load [as 别名]
def _download(self, url, **kwargs):
try:
configuration = JsonDict.load(urlopen(url, **kwargs))
self._cache.update(configuration)
except (HTTPError, URLError, timeout), e:
sys.stderr.write("""%s (%s).
Tried: %s
-----
""" % (e.__class__.__name__, str(e), url))
configuration = self._cache.retrieve()
if configuration is None:
sys.stderr.write('%s: configuration cachefile "%s" not found!\n' % (self.__class__.__name__, self._cache.filepath))
sys.stderr.flush()
raise
sys.stderr.write('%s: configuration cachefile "%s" found.\n' % (self.__class__.__name__, self._cache.filepath))
sys.stderr.flush()
示例8: getDomain
# 需要导入模块: from meresco.components.json import JsonDict [as 别名]
# 或者: from meresco.components.json.JsonDict import load [as 别名]
def getDomain(self, identifier):
domainFile = join(self._dataPath, '{0}.domain'.format(identifier))
try:
return JsonDict.load(open(domainFile))
except IOError:
raise ValueError('idDoesNotExist')
示例9: getMapping
# 需要导入模块: from meresco.components.json import JsonDict [as 别名]
# 或者: from meresco.components.json.JsonDict import load [as 别名]
def getMapping(self, identifier):
try:
return JsonDict.load(open(join(self._dataPath, '%s.mapping' % identifier)))
except IOError:
raise ValueError("idDoesNotExist")
示例10: getRepository
# 需要导入模块: from meresco.components.json import JsonDict [as 别名]
# 或者: from meresco.components.json.JsonDict import load [as 别名]
def getRepository(self, identifier, domainId):
try:
return JsonDict.load(open(join(self._dataPath, '%s.%s.repository' % (domainId, identifier))))
except IOError:
raise ValueError("idDoesNotExist")
示例11: getRepositoryGroupId
# 需要导入模块: from meresco.components.json import JsonDict [as 别名]
# 或者: from meresco.components.json.JsonDict import load [as 别名]
def getRepositoryGroupId(self, domainId, repositoryId):
return JsonDict.load(open(join(self._dataPath, '%s.%s.repository' % (domainId, repositoryId))))['repositoryGroupId']
示例12: testLoadFromFilename
# 需要导入模块: from meresco.components.json import JsonDict [as 别名]
# 或者: from meresco.components.json.JsonDict import load [as 别名]
def testLoadFromFilename(self):
jd = JsonDict({'hello': 'world'})
tempfile = join(self.tempdir, 'json.json')
open(tempfile, 'w').write(str(jd))
jd2 = JsonDict.load(tempfile)
self.assertEquals(jd, jd2)
示例13: listObjects
# 需要导入模块: from meresco.components.json import JsonDict [as 别名]
# 或者: from meresco.components.json.JsonDict import load [as 别名]
def listObjects(self):
return JsonDict.load(self._registryFile)
示例14: _read
# 需要导入模块: from meresco.components.json import JsonDict [as 别名]
# 或者: from meresco.components.json.JsonDict import load [as 别名]
def _read(self):
result = JsonDict.load(self._filename)
assert result['version'] == self.version, 'Expected database version %s' % self.version
self._info = result['users']
示例15: getRepositoryGroupIds
# 需要导入模块: from meresco.components.json import JsonDict [as 别名]
# 或者: from meresco.components.json.JsonDict import load [as 别名]
def getRepositoryGroupIds(self, domainId):
return JsonDict.load(open(join(self._dataPath, '%s.domain' % domainId))).get('repositoryGroupIds',[])