本文整理汇总了Python中pvl.loads函数的典型用法代码示例。如果您正苦于以下问题:Python loads函数的具体用法?Python loads怎么用?Python loads使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了loads函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_units
def test_units():
label = pvl.loads("""
foo = 42 <beards>
g = 9.8 <m/s>
list = (1, 2, 3) <numbers>
cool = (1 <number>)
End
""")
assert isinstance(label['foo'], Units)
assert label['foo'].value == 42
assert label['foo'].units == 'beards'
assert isinstance(label['g'], Units)
assert label['g'].value == 9.8
assert label['g'].units == 'm/s'
assert isinstance(label['list'], Units)
assert isinstance(label['list'].value, list)
assert label['list'].units == 'numbers'
assert isinstance(label['cool'], list)
assert isinstance(label['cool'][0], Units)
assert label['cool'][0].value == 1
assert label['cool'][0].units == 'number'
with pytest.raises(pvl.decoder.ParseError):
pvl.loads(b'foo = bar <')
开发者ID:michaelaye,项目名称:pvl,代码行数:27,代码来源:test_decoder.py
示例2: test_groups
def test_groups():
label = pvl.loads("""
Group = test_group
foo = bar
Object = embedded_object
foo = bar
End_Object
Group = embedded_group
foo = bar
End_Group
End_Group
End
""")
test_group = label['test_group']
assert isinstance(test_group, LabelGroup)
assert test_group['foo'] == 'bar'
embedded_object = test_group['embedded_object']
assert isinstance(embedded_object, LabelObject)
assert embedded_object['foo'] == 'bar'
embedded_group = test_group['embedded_group']
assert isinstance(embedded_group, LabelGroup)
assert embedded_group['foo'] == 'bar'
with pytest.raises(pvl.decoder.ParseError):
pvl.loads("""
BEGIN_GROUP = foo
END_GROUP = bar
""")
开发者ID:michaelaye,项目名称:pvl,代码行数:31,代码来源:test_decoder.py
示例3: test_comments
def test_comments():
label = pvl.loads("""
/* comment on line */
# here is a line comment
/* here is a multi-
line comment */
foo = bar /* comment at end of line */
weird/* in the */=/*middle*/comments
baz = bang # end line comment
End
""")
assert len(label) == 3
assert isinstance(label['foo'], six.text_type)
assert label['foo'] == 'bar'
assert isinstance(label['foo'], six.text_type)
assert label['weird'] == 'comments'
assert isinstance(label['foo'], six.text_type)
assert label['baz'] == 'bang'
with pytest.raises(pvl.decoder.ParseError):
pvl.loads(b'/*')
开发者ID:michaelaye,项目名称:pvl,代码行数:25,代码来源:test_decoder.py
示例4: test_assignment
def test_assignment():
label = pvl.loads('foo=bar')
assert isinstance(label, Label)
assert label['foo'] == 'bar'
label = pvl.loads('Group_Foo=bar')
assert isinstance(label, Label)
assert label['Group_Foo'] == 'bar'
开发者ID:jlaura,项目名称:pvl,代码行数:8,代码来源:test_decoder.py
示例5: test_special_values
def test_special_values():
module = pvl.PVLModule([
('bool_true', True),
('bool_false', False),
('null', None),
])
assert module == pvl.loads(pvl.dumps(module))
encoder = pvl.encoder.IsisCubeLabelEncoder
assert module == pvl.loads(pvl.dumps(module, cls=encoder))
encoder = pvl.encoder.PDSLabelEncoder
assert module == pvl.loads(pvl.dumps(module, cls=encoder))
开发者ID:planetarypy,项目名称:pvl,代码行数:13,代码来源:test_encoder.py
示例6: test_special_strings
def test_special_strings():
module = pvl.PVLModule([
('single_quote', "'"),
('double_quote', '"'),
('mixed_quotes', '"\''),
])
assert module == pvl.loads(pvl.dumps(module))
encoder = pvl.encoder.IsisCubeLabelEncoder
assert module == pvl.loads(pvl.dumps(module, cls=encoder))
encoder = pvl.encoder.PDSLabelEncoder
assert module == pvl.loads(pvl.dumps(module, cls=encoder))
开发者ID:planetarypy,项目名称:pvl,代码行数:13,代码来源:test_encoder.py
示例7: test_dates
def test_dates():
label = pvl.loads("""
date1 = 1990-07-04
date2 = 1990-158
date3 = 2001-001
time1 = 12:00
time_s = 12:00:45
time_s_float = 12:00:45.4571
time_tz1 = 15:24:12Z
time_tz2 = 01:12:22+07
time_tz3 = 01:12:22+7
time_tz4 = 01:10:39.4575+07
datetime1 = 1990-07-04T12:00
datetime2 = 1990-158T15:24:12Z
datetime3 = 2001-001T01:10:39+7
datetime4 = 2001-001T01:10:39.457591+7
End
""")
assert isinstance(label['date1'], datetime.date)
assert label['date1'] == datetime.date(1990, 7, 4)
assert isinstance(label['date2'], datetime.date)
assert label['date2'] == datetime.date(1990, 6, 7)
assert isinstance(label['date3'], datetime.date)
assert label['date3'] == datetime.date(2001, 1, 1)
assert isinstance(label['time1'], datetime.time)
assert label['time1'] == datetime.time(12)
assert isinstance(label['time_s'], datetime.time)
assert label['time_s'] == datetime.time(12, 0, 45)
assert isinstance(label['time_s_float'], datetime.time)
assert label['time_s_float'] == datetime.time(12, 0, 45, 457100)
assert isinstance(label['time_tz1'], datetime.time)
assert label['time_tz1'] == datetime.time(15, 24, 12, tzinfo=pytz.utc)
assert isinstance(label['time_tz2'], datetime.time)
assert label['time_tz2'] == datetime.time(1, 12, 22, tzinfo=pytz.FixedOffset(420)) # noqa
assert isinstance(label['time_tz3'], datetime.time)
assert label['time_tz3'] == datetime.time(1, 12, 22, tzinfo=pytz.FixedOffset(420)) # noqa
assert isinstance(label['time_tz4'], datetime.time)
assert label['time_tz4'] == datetime.time(1, 10, 39, 457500, pytz.FixedOffset(420)) # noqa
assert isinstance(label['datetime1'], datetime.datetime)
assert label['datetime1'] == datetime.datetime(1990, 7, 4, 12)
assert isinstance(label['datetime2'], datetime.datetime)
assert label['datetime2'] == datetime.datetime(1990, 6, 7, 15, 24, 12, tzinfo=pytz.utc) # noqa
assert isinstance(label['datetime3'], datetime.datetime)
assert label['datetime3'] == datetime.datetime(2001, 1, 1, 1, 10, 39, tzinfo=pytz.FixedOffset(420)) # noqa
assert isinstance(label['datetime4'], datetime.datetime)
assert label['datetime4'] == datetime.datetime(2001, 1, 1, 1, 10, 39, 457591, pytz.FixedOffset(420)) # noqa
开发者ID:michaelaye,项目名称:pvl,代码行数:60,代码来源:test_decoder.py
示例8: test_floats
def test_floats():
label = pvl.loads("""
float = 1.0
float_no_decimal = 2.
float_no_whole = .3
float_leading_zero = 0.5
positive_float = +2.0
negative_float = -1.0
invalid_float = 1.2.3
End
""")
assert isinstance(label['float'], float)
assert label['float'] == 1.0
assert isinstance(label['float_no_decimal'], float)
assert label['float_no_decimal'] == 2.0
assert isinstance(label['float_no_whole'], float)
assert label['float_no_whole'] == 0.3
assert isinstance(label['float_leading_zero'], float)
assert label['float_leading_zero'] == 0.5
assert isinstance(label['positive_float'], float)
assert label['positive_float'] == 2.0
assert isinstance(label['negative_float'], float)
assert label['negative_float'] == -1.0
assert isinstance(label['invalid_float'], six.text_type)
assert label['invalid_float'] == '1.2.3'
开发者ID:michaelaye,项目名称:pvl,代码行数:31,代码来源:test_decoder.py
示例9: test_groups
def test_groups():
label = pvl.loads("""
Group = test_group
foo = bar
Object = embedded_object
foo = bar
End_Object
Group = embedded_group
foo = bar
End_Group
End_Group
End
""")
test_group = label['test_group']
assert isinstance(test_group, LabelGroup)
assert test_group['foo'] == 'bar'
embedded_object = test_group['embedded_object']
assert isinstance(embedded_object, LabelObject)
assert embedded_object['foo'] == 'bar'
embedded_group = test_group['embedded_group']
assert isinstance(embedded_group, LabelGroup)
assert embedded_group['foo'] == 'bar'
开发者ID:jlaura,项目名称:pvl,代码行数:25,代码来源:test_decoder.py
示例10: test_linewrap
def test_linewrap():
label = pvl.loads("""
foo = bar-
baz
End
""")
assert label['foo'] == 'barbaz'
开发者ID:michaelaye,项目名称:pvl,代码行数:8,代码来源:test_decoder.py
示例11: test_hex
def test_hex():
label = pvl.loads("""
hex_number_upper = 16#100A#
hex_number_lower = 16#100b#
positive_hex_number = +16#100A#
negative_hex_number = -16#100A#
End
""")
assert isinstance(label['hex_number_upper'], int)
assert label['hex_number_upper'] == 4106
assert isinstance(label['hex_number_lower'], int)
assert label['hex_number_lower'] == 4107
assert isinstance(label['positive_hex_number'], int)
assert label['positive_hex_number'] == 4106
assert isinstance(label['negative_hex_number'], int)
assert label['negative_hex_number'] == -4106
with pytest.raises(pvl.decoder.ParseError):
pvl.loads('empty = 16##')
with pytest.raises(pvl.decoder.ParseError):
pvl.loads('hex_number_upper = 16#100A')
with pytest.raises(pvl.decoder.ParseError):
pvl.loads('hex_number_upper = 16#100AZ#')
开发者ID:michaelaye,项目名称:pvl,代码行数:29,代码来源:test_decoder.py
示例12: test_octal
def test_octal():
label = pvl.loads("""
octal_number = 8#0107#
positive_octal_number = +8#0107#
negative_octal_number = -8#0107#
End
""")
assert isinstance(label['octal_number'], int)
assert label['octal_number'] == 71
assert isinstance(label['positive_octal_number'], int)
assert label['positive_octal_number'] == 71
assert isinstance(label['negative_octal_number'], int)
assert label['negative_octal_number'] == -71
with pytest.raises(pvl.decoder.ParseError):
pvl.loads('empty = 8##')
with pytest.raises(pvl.decoder.ParseError):
pvl.loads('octal_number = 8#0107')
with pytest.raises(pvl.decoder.ParseError):
pvl.loads('octal_number = 8#01079#')
开发者ID:michaelaye,项目名称:pvl,代码行数:25,代码来源:test_decoder.py
示例13: test_binary
def test_binary():
label = pvl.loads("""
binary_number = 2#0101#
positive_binary_number = +2#0101#
negative_binary_number = -2#0101#
End
""")
assert isinstance(label['binary_number'], int)
assert label['binary_number'] == 5
assert isinstance(label['positive_binary_number'], int)
assert label['positive_binary_number'] == 5
assert isinstance(label['negative_binary_number'], int)
assert label['negative_binary_number'] == -5
with pytest.raises(pvl.decoder.ParseError):
pvl.loads('empty = 2##')
with pytest.raises(pvl.decoder.ParseError):
pvl.loads('binary_number = 2#0101')
with pytest.raises(pvl.decoder.ParseError):
pvl.loads('binary_number = 2#01014201#')
开发者ID:michaelaye,项目名称:pvl,代码行数:25,代码来源:test_decoder.py
示例14: test_quoated_strings
def test_quoated_strings():
module = pvl.PVLModule([
('int_like', "123"),
('float_like', '.2'),
('date', '1987-02-25'),
('time', '03:04:05'),
('datetime', '1987-02-25T03:04:05'),
('keyword', 'END'),
('restricted_chars', '&<>\'{},[]=!#()%";|'),
('restricted_seq', '/**/'),
])
assert module == pvl.loads(pvl.dumps(module))
encoder = pvl.encoder.IsisCubeLabelEncoder
assert module == pvl.loads(pvl.dumps(module, cls=encoder))
encoder = pvl.encoder.PDSLabelEncoder
assert module == pvl.loads(pvl.dumps(module, cls=encoder))
开发者ID:planetarypy,项目名称:pvl,代码行数:18,代码来源:test_encoder.py
示例15: test_quotes
def test_quotes():
label = pvl.loads("""
foo = 'bar'
empty = ''
space = ' test '
double = "double'quotes"
single = 'single"quotes'
mixed = 'mixed"\\'quotes'
number = '123'
date = '1918-05-11'
multiline = 'this is a
multi-line string'
continuation = "The planet Jupi-
ter is very big"
formating = "\\n\\t\\f\\v\\\\\\n\\t\\f\\v\\\\"
End
""")
assert isinstance(label['foo'], six.text_type)
assert label['foo'] == 'bar'
assert isinstance(label['empty'], six.text_type)
assert label['empty'] == ''
assert isinstance(label['space'], six.text_type)
assert label['space'] == 'test'
assert isinstance(label['double'], six.text_type)
assert label['double'] == "double'quotes"
assert isinstance(label['single'], six.text_type)
assert label['single'] == 'single"quotes'
assert isinstance(label['single'], six.text_type)
assert label['mixed'] == 'mixed"\'quotes'
assert isinstance(label['number'], six.text_type)
assert label['number'] == '123'
assert isinstance(label['date'], six.text_type)
assert label['date'] == '1918-05-11'
assert isinstance(label['multiline'], six.text_type)
assert label['multiline'] == 'this is a multi-line string'
assert isinstance(label['continuation'], six.text_type)
assert label['continuation'] == 'The planet Jupiter is very big'
assert isinstance(label['formating'], six.text_type)
assert label['formating'] == '\n\t\f\v\\\n\t\f\v\\'
with pytest.raises(pvl.decoder.ParseError):
pvl.loads('foo = "bar')
with pytest.raises(pvl.decoder.ParseError):
pvl.loads("foo = 'bar")
with pytest.raises(pvl.decoder.ParseError):
pvl.loads("foo = '\\bar'")
开发者ID:michaelaye,项目名称:pvl,代码行数:59,代码来源:test_decoder.py
示例16: test_spacing
def test_spacing():
label = pvl.loads("""
foo = bar
nospace=good
lots_of_spacing = alsogood
same = line no = problem; like=aboss
End
""")
assert isinstance(label, Label)
assert label['foo'] == 'bar'
assert label['nospace'] == 'good'
assert label['lots_of_spacing'] == 'alsogood'
assert label['same'] == 'line'
assert label['no'] == 'problem'
assert label['like'] == 'aboss'
开发者ID:michaelaye,项目名称:pvl,代码行数:16,代码来源:test_decoder.py
示例17: test_binary
def test_binary():
label = pvl.loads("""
binary_number = 2#0101#
positive_binary_number = +2#0101#
negative_binary_number = -2#0101#
End
""")
assert isinstance(label['binary_number'], int)
assert label['binary_number'] == 5
assert isinstance(label['positive_binary_number'], int)
assert label['positive_binary_number'] == 5
assert isinstance(label['negative_binary_number'], int)
assert label['negative_binary_number'] == -5
开发者ID:jlaura,项目名称:pvl,代码行数:16,代码来源:test_decoder.py
示例18: test_octal
def test_octal():
label = pvl.loads("""
octal_number = 8#0107#
positive_octal_number = +8#0107#
negative_octal_number = -8#0107#
End
""")
assert isinstance(label['octal_number'], int)
assert label['octal_number'] == 71
assert isinstance(label['positive_octal_number'], int)
assert label['positive_octal_number'] == 71
assert isinstance(label['negative_octal_number'], int)
assert label['negative_octal_number'] == -71
开发者ID:jlaura,项目名称:pvl,代码行数:16,代码来源:test_decoder.py
示例19: extract_keywords
def extract_keywords(header, *args):
"""
For a given header, find all of the keys and return an unnested dict.
"""
try:
header = pvl.load(header)
except:
header = pvl.loads(header)
res = {}
# Iterate through all of the requested keys
for a in args:
try:
res[a] = find_in_dict(a)
except:
res[a] = None
return res
开发者ID:USGS-Astrogeology,项目名称:plio,代码行数:17,代码来源:io_pvl.py
示例20: test_sequence
def test_sequence():
label = pvl.loads("""
strings = (a, b, c)
nospace=(a,b,c)
numbers = (1, 2, 3)
mixed = (a, 1, 2.5)
empty = ()
multiline = (a,
b,
c)
End
""")
assert isinstance(label['strings'], list)
assert len(label['strings']) == 3
assert label['strings'][0] == 'a'
assert label['strings'][1] == 'b'
assert label['strings'][2] == 'c'
assert isinstance(label['nospace'], list)
assert len(label['nospace']) == 3
assert label['nospace'][0] == 'a'
assert label['nospace'][1] == 'b'
assert label['nospace'][2] == 'c'
assert isinstance(label['numbers'], list)
assert len(label['numbers']) == 3
assert label['numbers'][0] == 1
assert label['numbers'][1] == 2
assert label['numbers'][2] == 3
assert isinstance(label['mixed'], list)
assert len(label['mixed']) == 3
assert label['mixed'][0] == 'a'
assert label['mixed'][1] == 1
assert label['mixed'][2] == 2.5
assert isinstance(label['empty'], list)
assert len(label['empty']) == 0
assert isinstance(label['multiline'], list)
assert len(label['multiline']) == 3
assert label['multiline'][0] == 'a'
assert label['multiline'][1] == 'b'
assert label['multiline'][2] == 'c'
开发者ID:michaelaye,项目名称:pvl,代码行数:45,代码来源:test_decoder.py
注:本文中的pvl.loads函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论