@@ -65,6 +65,13 @@ def apply(self,
65
65
self .nodata = nodata
66
66
self .checksum = checksum
67
67
68
+ def _set_property (self , key , value , asset ):
69
+ target = self .item .properties if asset is None else asset .properties
70
+ if value is None :
71
+ target .pop (key , None )
72
+ else :
73
+ target [key ] = value
74
+
68
75
@property
69
76
def data_type (self ):
70
77
"""Get or sets the data_type of the file.
@@ -90,7 +97,7 @@ def get_data_type(self, asset=None):
90
97
if asset is not None and 'file:data_type' in asset .properties :
91
98
data_type = asset .properties .get ('file:data_type' )
92
99
else :
93
- data_type = self .item .properties .get ('file_data_type ' )
100
+ data_type = self .item .properties .get ('file:data_type ' )
94
101
95
102
if data_type is not None :
96
103
return FileDataType (data_type )
@@ -101,10 +108,7 @@ def set_data_type(self, data_type, asset=None):
101
108
If an Asset is supplied, sets the property on the Asset.
102
109
Otherwise sets the Item's value.
103
110
"""
104
- if asset is not None :
105
- asset .properties ['file:data_type' ] = data_type .value
106
- else :
107
- self .item .properties ['file:data_type' ] = data_type .value
111
+ self ._set_property ('file:data_type' , data_type .value , asset )
108
112
109
113
@property
110
114
def size (self ):
@@ -139,10 +143,7 @@ def set_size(self, size, asset=None):
139
143
If an Asset is supplied, sets the property on the Asset.
140
144
Otherwise sets the Item's value.
141
145
"""
142
- if asset is None :
143
- self .item .properties ['file:size' ] = size
144
- else :
145
- asset .properties ['file:size' ] = size
146
+ self ._set_property ('file:size' , size , asset )
146
147
147
148
@property
148
149
def nodata (self ):
@@ -177,10 +178,7 @@ def set_nodata(self, nodata, asset=None):
177
178
If an Asset is supplied, sets the property on the Asset.
178
179
Otherwise sets the Item's value.
179
180
"""
180
- if asset is None :
181
- self .item .properties ['file:nodata' ] = nodata
182
- else :
183
- asset .properties ['file:nodata' ] = nodata
181
+ self ._set_property ('file:nodata' , nodata , asset )
184
182
185
183
@property
186
184
def checksum (self ):
@@ -191,7 +189,7 @@ def checksum(self):
191
189
"""
192
190
return self .get_checksum ()
193
191
194
- @nodata .setter
192
+ @checksum .setter
195
193
def checksum (self , v ):
196
194
self .set_checksum (v )
197
195
@@ -215,10 +213,7 @@ def set_checksum(self, checksum, asset=None):
215
213
If an Asset is supplied, sets the property on the Asset.
216
214
Otherwise sets the Item's value.
217
215
"""
218
- if asset is None :
219
- self .item .properties ['file:checksum' ] = checksum
220
- else :
221
- asset .properties ['file:checksum' ] = checksum
216
+ self ._set_property ('file:checksum' , checksum , asset )
222
217
223
218
def __repr__ (self ):
224
219
return '<FileItemExt Item id={}>' .format (self .item .id )
0 commit comments