@@ -2082,13 +2082,16 @@ def getDatasetValuesByUuid(self, obj_uuid, slices=Ellipsis, format="json"):
2082
2082
raise IOError (errno .EINVAL , msg )
2083
2083
2084
2084
if dset is None :
2085
- return None
2085
+ msg = "Dataset: " + obj_uuid + " not found"
2086
+ self .log .info (msg )
2087
+ raise IOError (errno .ENXIO , msg )
2088
+
2086
2089
values = None
2087
2090
dt = dset .dtype
2088
2091
typeItem = getTypeItem (dt )
2089
2092
itemSize = getItemSize (typeItem )
2090
2093
if itemSize == "H5T_VARIABLE" and format == "binary" :
2091
- msg + "Only JSON is supported for for this data type"
2094
+ msg = "Only JSON is supported for for this data type"
2092
2095
self .log .info (msg )
2093
2096
raise IOError (errno .EINVAL , msg )
2094
2097
@@ -2116,7 +2119,7 @@ def getDatasetValuesByUuid(self, obj_uuid, slices=Ellipsis, format="json"):
2116
2119
2117
2120
if dt .kind == 'O' :
2118
2121
if format != "json" :
2119
- msg + "Only JSON is supported for for this data type"
2122
+ msg = "Only JSON is supported for for this data type"
2120
2123
self .log .info (msg )
2121
2124
raise IOError (errno .EINVAL , msg )
2122
2125
# numpy object type - could be a vlen string or generic vlen
@@ -2146,7 +2149,7 @@ def getDatasetValuesByUuid(self, obj_uuid, slices=Ellipsis, format="json"):
2146
2149
# For Python3 fixed string values will be returned as bytes,
2147
2150
# so finese them into strings
2148
2151
if format != "json" :
2149
- msg + "Only JSON is supported for for this data type"
2152
+ msg = "Only JSON is supported for for this data type"
2150
2153
self .log .info (msg )
2151
2154
raise IOError (errno .EINVAL , msg )
2152
2155
values = self .bytesArrayToList (dset [slices ])
@@ -2179,6 +2182,7 @@ def getDatasetPointSelectionByUuid(self, obj_uuid, points):
2179
2182
msg = "Dataset: " + obj_uuid + " not found"
2180
2183
self .log .info (msg )
2181
2184
raise IOError (errno .ENXIO , msg )
2185
+
2182
2186
rank = len (dset .shape )
2183
2187
values = np .zeros (len (points ), dtype = dset .dtype )
2184
2188
try :
@@ -2200,18 +2204,36 @@ def getDatasetPointSelectionByUuid(self, obj_uuid, points):
2200
2204
setDatasetValuesByUuid - update the given dataset values with supplied data
2201
2205
and optionally a hyperslab selection (slices)
2202
2206
"""
2203
- def setDatasetValuesByUuid (self , obj_uuid , data , slices = None ):
2207
+ def setDatasetValuesByUuid (self , obj_uuid , data , slices = None , format = "json" ):
2204
2208
dset = self .getDatasetObjByUuid (obj_uuid )
2205
-
2209
+
2210
+ if format not in ("json" , "binary" ):
2211
+ msg = "only json and binary formats are supported"
2212
+ self .log .info (msg )
2213
+ raise IOError (errno .EINVAL , msg )
2214
+
2215
+ if format == "binary" and type (data ) is not bytes :
2216
+ msg = "data must be of type bytes for binary writing"
2217
+ self .log .info (msg )
2218
+ raise IOError (errno .EINVAL , msg )
2219
+
2206
2220
if dset is None :
2207
2221
msg = "Dataset: " + obj_uuid + " not found"
2208
2222
self .log .info (msg )
2209
2223
raise IOError (errno .ENXIO , msg )
2224
+
2225
+ dt = dset .dtype
2226
+ typeItem = getTypeItem (dt )
2227
+ itemSize = getItemSize (typeItem )
2228
+ if itemSize == "H5T_VARIABLE" and format == "binary" :
2229
+ msg = "Only JSON is supported for for this data type"
2230
+ self .log .info (msg )
2231
+ raise IOError (errno .EINVAL , msg )
2210
2232
2211
2233
# need some special conversion for compound types --
2212
2234
# each element must be a tuple, but the JSON decoder
2213
2235
# gives us a list instead.
2214
- if len (dset .dtype ) > 1 and type (data ) in (list , tuple ):
2236
+ if format != "binary" and len (dset .dtype ) > 1 and type (data ) in (list , tuple ):
2215
2237
converted_data = []
2216
2238
for i in range (len (data )):
2217
2239
converted_data .append (self .toTuple (data [i ]))
@@ -2220,15 +2242,28 @@ def setDatasetValuesByUuid(self, obj_uuid, data, slices=None):
2220
2242
h5t_check = h5py .check_dtype (ref = dset .dtype )
2221
2243
if h5t_check in (h5py .Reference , h5py .RegionReference ):
2222
2244
# convert data to data refs
2245
+ if format == "binary" :
2246
+ msg = "Only JSON is supported for for this data type"
2247
+ self .log .info (msg )
2248
+ raise IOError (errno .EINVAL , msg )
2223
2249
data = self .listToRef (data )
2224
2250
2225
2251
if slices is None :
2226
2252
# write entire dataset
2227
- dset [()] = data
2253
+ if format == "binary" :
2254
+ if len (data ) != dset .size :
2255
+ msg = "Expected " + dset .size + " bytes, but got: " + len (data )
2256
+ self .log .info (msg )
2257
+ raise IOError (errno .EINVAL , msg )
2258
+ arr = np .fromstring (data , dtype = dset .dtype )
2259
+ arr .reshape (dset .shape )
2260
+ dset [()] = arr
2261
+ else :
2262
+ dset [()] = data
2228
2263
else :
2229
2264
if type (slices ) != tuple :
2230
- self . log . error (
2231
- "setDatasetValuesByUuid: bad type for dim parameter" )
2265
+ msg = "setDatasetValuesByUuid: bad type for dim parameter"
2266
+ self . log . error ( msg )
2232
2267
return False
2233
2268
rank = len (dset .shape )
2234
2269
0 commit comments