本文整理汇总了Python中rhsm.ourjson.loads函数的典型用法代码示例。如果您正苦于以下问题:Python loads函数的具体用法?Python loads怎么用?Python loads使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了loads函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_package_json_handles_non_unicode
def test_package_json_handles_non_unicode(self):
package = Package(name=b'\xf6', version=b'\xf6', release=b'\xf6', arch=b'\xf6', vendor=b'\xf6')
data = package.to_dict()
json_str = json.dumps(data) # to json
data = json.loads(json_str) # and back to an object
for attr in ['name', 'version', 'release', 'arch', 'vendor']:
self.assertEqual(u'\ufffd', data[attr])
开发者ID:Lorquas,项目名称:subscription-manager,代码行数:7,代码来源:test_cache.py
示例2: test_facts_has_changed_cache_is_none
def test_facts_has_changed_cache_is_none(self, mock_load_hw, mock_load_cf, mock_read_cache):
test_facts = json.loads(facts_buf)
mock_load_hw.return_value = test_facts
changed = self.f.has_changed()
self.assert_equal_dict(test_facts, self.f.facts)
self.assertTrue(changed)
开发者ID:ggainey,项目名称:subscription-manager,代码行数:7,代码来源:test_facts.py
示例3: test_package_json_missing_attributes
def test_package_json_missing_attributes(self):
package = Package(name=None, version=None, release=None, arch=None, vendor=None)
data = package.to_dict()
json_str = json.dumps(data) # to json
data = json.loads(json_str) # and back to an object
for attr in ['name', 'version', 'release', 'arch', 'vendor']:
self.assertEqual(None, data[attr])
开发者ID:Lorquas,项目名称:subscription-manager,代码行数:7,代码来源:test_cache.py
示例4: check_for_update
def check_for_update(self):
if self.exists():
data = json.loads(self.read())
last_update = parse_date(data["lastUpdate"])
else:
last_update = None
return self._query_for_update(if_modified_since=last_update)
开发者ID:jstavel,项目名称:subscription-manager,代码行数:7,代码来源:cache.py
示例5: test_facts_has_changed_cache_exists_false
def test_facts_has_changed_cache_exists_false(self, mock_load_hw, mock_load_cf, mock_read_cache):
test_facts = json.loads(facts_buf)
mock_load_hw.return_value = test_facts
changed = self.f.has_changed()
self.assertTrue(changed)
开发者ID:ggainey,项目名称:subscription-manager,代码行数:7,代码来源:test_facts.py
示例6: test_write_cache
def test_write_cache(self):
mock_server_status = {'fake server status': random.uniform(1, 2 ** 32)}
status_cache = EntitlementStatusCache()
status_cache.server_status = mock_server_status
cache_dir = tempfile.mkdtemp()
cache_file = os.path.join(cache_dir, 'status_cache.json')
status_cache.CACHE_FILE = cache_file
status_cache.write_cache()
# try to load the file 5 times, if
# we still can't read it, fail
# we don't know when the write_cache thread ends or
# when it starts. Need to track the cache threads
# but we do not...
tries = 0
while tries <= 5:
try:
new_status_buf = open(cache_file).read()
new_status = json.loads(new_status_buf)
break
except Exception as e:
log.exception(e)
tries += 1
time.sleep(.1)
continue
shutil.rmtree(cache_dir)
self.assertEqual(new_status, mock_server_status)
开发者ID:Lorquas,项目名称:subscription-manager,代码行数:29,代码来源:test_cache.py
示例7: __init__
def __init__(self, from_file=None):
"""
Load the RPM package profile from a given file, or from rpm itself.
NOTE: from_file is a file descriptor, not a file name.
"""
self.packages = []
if from_file:
log.debug("Loading RPM profile from file.")
json_buffer = from_file.read()
pkg_dicts = json.loads(json_buffer)
for pkg_dict in pkg_dicts:
self.packages.append(Package(
name=pkg_dict['name'],
version=pkg_dict['version'],
release=pkg_dict['release'],
arch=pkg_dict['arch'],
epoch=pkg_dict['epoch'],
vendor=pkg_dict['vendor']
))
else:
log.debug("Loading current RPM profile.")
ts = rpm.TransactionSet()
ts.setVSFlags(-1)
installed = ts.dbMatch()
self.packages = self._accumulate_profile(installed)
开发者ID:Lorquas,项目名称:subscription-manager,代码行数:26,代码来源:profile.py
示例8: setUp
def setUp(self):
SubManFixture.setUp(self)
self.status = json.loads(INST_PROD_STATUS)['installedProducts']
self.prod_status_cache = NonCallableMock()
self.prod_status_cache.load_status = Mock(return_value=self.status)
inj.provide(inj.PROD_STATUS_CACHE, self.prod_status_cache)
self.calculator = ValidProductDateRangeCalculator(None)
开发者ID:MichaelMraka,项目名称:subscription-manager,代码行数:7,代码来源:test_validity.py
示例9: test_package_json_as_unicode_type
def test_package_json_as_unicode_type(self):
# note that the data type at time of writing is bytes, so this is just defensive coding
package = Package(name=u'Björk', version=u'Björk', release=u'Björk', arch=u'Björk', vendor=u'Björk')
data = package.to_dict()
json_str = json.dumps(data) # to json
data = json.loads(json_str) # and back to an object
for attr in ['name', 'version', 'release', 'arch', 'vendor']:
self.assertEqual(u'Björk', data[attr])
开发者ID:Lorquas,项目名称:subscription-manager,代码行数:8,代码来源:test_cache.py
示例10: _print_consumer
def _print_consumer(self, zip_archive):
# Print out the consumer data
part = zip_archive._read_file(os.path.join("export", "consumer.json"))
data = json.loads(part)
to_print = []
to_print.append((_("Name"), get_value(data, "name")))
to_print.append((_("UUID"), get_value(data, "uuid")))
to_print.append((_("Type"), get_value(data, "type.label")))
self._print_section(_("Consumer:"), to_print)
开发者ID:MichaelMraka,项目名称:subscription-manager,代码行数:9,代码来源:manifest_commands.py
示例11: test_facts_has_changed_with_change
def test_facts_has_changed_with_change(self, mock_collect):
test_facts = json.loads(facts_buf)
# change socket fact count from what is in the cache
test_facts['cpu.cpu_socket(s)'] = '16'
mock_collect.return_value = test_facts
changed = self.f.has_changed()
self.assertEqual(self.f.facts['cpu.cpu_socket(s)'], '16')
self.assertTrue(changed)
开发者ID:Januson,项目名称:subscription-manager,代码行数:9,代码来源:test_facts.py
示例12: test_facts_has_changed_with_change
def test_facts_has_changed_with_change(self, mock_load_hw, mock_load_cf):
test_facts = json.loads(facts_buf)
# change socket fact count from what is in the cache
test_facts["cpu.cpu_socket(s)"] = "16"
mock_load_hw.return_value = test_facts
changed = self.f.has_changed()
self.assertEquals(self.f.facts["cpu.cpu_socket(s)"], "16")
self.assertTrue(changed)
开发者ID:ggainey,项目名称:subscription-manager,代码行数:9,代码来源:test_facts.py
示例13: _parse_facts_json
def _parse_facts_json(self, json_buffer, file_path):
custom_facts = None
try:
custom_facts = json.loads(json_buffer)
except ValueError:
log.warn("Unable to load custom facts file: %s" % file_path)
return custom_facts
开发者ID:NehaRawat,项目名称:subscription-manager,代码行数:9,代码来源:facts.py
示例14: _print_general
def _print_general(self, zip_archive):
# Print out general data
part = zip_archive._read_file(os.path.join("export", "meta.json"))
data = json.loads(part)
to_print = []
to_print.append((_("Server"), get_value(data, "webAppPrefix")))
to_print.append((_("Server Version"), get_value(data, "version")))
to_print.append((_("Date Created"), get_value(data, "created")))
to_print.append((_("Creator"), get_value(data, "principalName")))
self._print_section(_("General:"), to_print)
开发者ID:MichaelMraka,项目名称:subscription-manager,代码行数:10,代码来源:manifest_commands.py
示例15: _load_data
def _load_data(self, open_file):
try:
self.overrides = json.loads(open_file.read()) or {}
return self.overrides
except IOError as err:
log.error("Unable to read cache: %s" % self.CACHE_FILE)
log.exception(err)
except ValueError:
# ignore json file parse errors, we are going to generate
# a new as if it didn't exist
pass
开发者ID:jstavel,项目名称:subscription-manager,代码行数:11,代码来源:cache.py
示例16: from_json
def from_json(cls, json_blob):
custom_facts = cls
# Default to no facts collected
# See BZ#1435771
data = {}
try:
data = ourjson.loads(json_blob)
except ValueError:
log.warn("Unable to load custom facts file.")
custom_facts.data = data
return custom_facts
开发者ID:Lorquas,项目名称:subscription-manager,代码行数:13,代码来源:custom.py
示例17: _decompress_payload
def _decompress_payload(self, payload):
"""
Certificate payloads arrive in zlib compressed strings
of JSON.
This method de-compresses and parses the JSON and returns the
resulting dict.
"""
try:
decompressed = zlib.decompress(payload)
return json.loads(decompressed)
except Exception, e:
log.exception(e)
raise CertificateException("Error decompressing/parsing " "certificate payload.")
开发者ID:vittyvk,项目名称:python-rhsm,代码行数:13,代码来源:certificate2.py
示例18: __read_cache_file
def __read_cache_file(file_name):
try:
with open(file_name) as file:
json_str = file.read()
data = json.loads(json_str)
return data
except IOError as err:
log.error("Unable to read cache: %s" % file_name)
log.exception(err)
except ValueError:
# ignore json file parse errors, we are going to generate
# a new as if it didn't exist
pass
return None
开发者ID:Januson,项目名称:subscription-manager,代码行数:14,代码来源:product-id.py
示例19: _print_consumer
def _print_consumer(self, zip_archive):
# Print out the consumer data
part = zip_archive._read_file(os.path.join("export", "consumer.json"))
data = json.loads(part)
to_print = []
to_print.append((_("Name"), get_value(data, "name")))
to_print.append((_("UUID"), get_value(data, "uuid")))
# contentAccessMode is entitlement if null, blank or non-present
contentAccessMode = 'entitlement'
if "contentAccessMode" in data and data["contentAccessMode"] == 'org_environment':
contentAccessMode = 'org_environment'
to_print.append((_("Content Access Mode"), contentAccessMode))
to_print.append((_("Type"), get_value(data, "type.label")))
to_print.append((_("API URL"), get_value(data, "urlApi")))
to_print.append((_("Web URL"), get_value(data, "urlWeb")))
self._print_section(_("Consumer:"), to_print)
开发者ID:Januson,项目名称:subscription-manager,代码行数:16,代码来源:manifest_commands.py
示例20: validateResponse
def validateResponse(self, response, request_type=None, handler=None):
# FIXME: what are we supposed to do with a 204?
if str(response['status']) not in ["200", "204"]:
parsed = {}
if not response.get('content'):
parsed = {}
else:
# try vaguely to see if it had a json parseable body
try:
parsed = json.loads(response['content'], object_hook=self._decode_dict)
except ValueError, e:
log.error("Response: %s" % response['status'])
log.error("JSON parsing error: %s" % e)
except Exception, e:
log.error("Response: %s" % response['status'])
log.exception(e)
开发者ID:barnabycourt,项目名称:python-rhsm,代码行数:17,代码来源:connection.py
注:本文中的rhsm.ourjson.loads函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论