Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

# This file is part of daf_base 

# 

# Developed for the LSST Data Management System. 

# This product includes software developed by the LSST Project 

# (http://www.lsst.org/). 

# See the COPYRIGHT file at the top-level directory of this distribution 

# for details of code ownership. 

# 

# This program is free software: you can redistribute it and/or modify 

# it under the terms of the GNU General Public License as published by 

# the Free Software Foundation, either version 3 of the License, or 

# (at your option) any later version. 

# 

# This program is distributed in the hope that it will be useful, 

# but WITHOUT ANY WARRANTY; without even the implied warranty of 

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

# GNU General Public License for more details. 

# 

# You should have received a copy of the GNU General Public License 

# along with this program. If not, see <http://www.gnu.org/licenses/>. 

 

"""This module defines YAML I/O for key lsst.daf.base classes.""" 

 

# If yaml package is not installed there is no reason to fail everywhere 

try: 

import yaml 

except ImportError: 

yaml = None 

 

from .dateTime import DateTime 

from .propertyContainer import PropertyList, getPropertyListState, setPropertyListState, \ 

getPropertySetState, setPropertySetState, PropertySet 

 

# For YAML >= 5.1 need a different Loader for the constructor 

loaderList = [] 

36 ↛ 55line 36 didn't jump to line 55, because the condition on line 36 was never falseif yaml: 

loaderList = [yaml.Loader, yaml.CLoader] 

try: 

loaderList.append(yaml.FullLoader) 

except AttributeError: 

pass 

try: 

loaderList.append(yaml.UnsafeLoader) 

except AttributeError: 

pass 

try: 

loaderList.append(yaml.SafeLoader) 

except AttributeError: 

pass 

 

 

# YAML representers for key lsst.daf.base classes 

 

 

def dt_representer(dumper, data): 

"""Represent an lsst.daf.base.DateTime (as ISO8601-formatted string in TAI) 

""" 

return dumper.represent_scalar('lsst.daf.base.DateTime', 

data.toString(DateTime.TAI)) 

 

 

62 ↛ 66line 62 didn't jump to line 66, because the condition on line 62 was never falseif yaml: 

yaml.add_representer(DateTime, dt_representer) 

 

 

def pl_representer(dumper, data): 

"""Represent an lsst.daf.base.PropertyList as an ordered sequence of 

name/type/value/comment lists)""" 

# Turn the tuples into lists for cleaner representation in yaml 

result = getPropertyListState(data, asLists=True) 

return dumper.represent_sequence('lsst.daf.base.PropertyList', result, 

flow_style=None) 

 

 

75 ↛ 79line 75 didn't jump to line 79, because the condition on line 75 was never falseif yaml: 

yaml.add_representer(PropertyList, pl_representer) 

 

 

def ps_representer(dumper, data): 

"""Represent an lsst.daf.base.PropertySet as a mapping from names to 

type/value pairs.""" 

# Turn the tuples into lists for cleaner representation in yaml 

result = getPropertySetState(data, asLists=True) 

return dumper.represent_sequence('lsst.daf.base.PropertySet', result, 

flow_style=None) 

 

 

88 ↛ 96line 88 didn't jump to line 96, because the condition on line 88 was never falseif yaml: 

yaml.add_representer(PropertySet, ps_representer) 

 

############################################################################### 

 

# YAML constructors for key lsst.daf.base classes 

 

 

def dt_constructor(loader, node): 

"""Construct an lsst.daf.base.DateTime from an ISO8601-formatted string in 

TAI""" 

dt = loader.construct_scalar(node) 

return DateTime(str(dt), DateTime.TAI) 

 

 

def pl_constructor(loader, node): 

"""Construct an lsst.daf.base.PropertyList from a YAML pickle-like 

structure.""" 

pl = PropertyList() 

yield pl 

state = loader.construct_sequence(node, deep=True) 

setPropertyListState(pl, state) 

 

 

def ps_constructor(loader, node): 

"""Construct an lsst.daf.base.PropertyList from a YAML pickle-like 

structure.""" 

ps = PropertySet() 

yield ps 

state = loader.construct_sequence(node, deep=True) 

setPropertySetState(ps, state) 

 

 

121 ↛ exitline 121 didn't exit the module, because the condition on line 121 was never falseif yaml: 

for loader in loaderList: 

yaml.add_constructor('lsst.daf.base.PropertyList', pl_constructor, Loader=loader) 

yaml.add_constructor('lsst.daf.base.PropertySet', ps_constructor, Loader=loader) 

yaml.add_constructor('lsst.daf.base.DateTime', dt_constructor, Loader=loader)