def __iter__(self): for line in dds(self.dataset): yield line.encode('ascii') yield (45 * '-' + '\n').encode('ascii') for line in ascii(self.dataset): yield line.encode('ascii')
def calculate_size(dataset): """Calculate the size of the response. Returns the size in bytes.""" length = 0 for var in walk(dataset): # Pydap can't calculate the size of sequences since the data is # streamed directly from the source. Also, strings are encoded # individually, so it's not possible to get their size unless we read # everything. if (isinstance(var, SequenceType) or (isinstance(var, BaseType) and var.dtype.char in 'SU')): return None elif isinstance(var, BaseType): if var.shape: length += 8 # account for array size marker size = int(np.prod(var.shape)) if var.data.dtype == np.byte: length += size + (-size % 4) elif var.data.dtype == np.short: length += size * 4 else: opendap_size = np.dtype(typemap[var.data.dtype.char]).itemsize length += size * opendap_size # account for DDS length += len(''.join(dds(dataset))) + len(b'Data:\n') return length
def __iter__(self): # generate DDS for line in dds(self.dataset): yield line.encode('ascii') yield b'Data:\n' for block in dods(self.dataset): yield block
def test_dispatcher(self): """Test the single dispatcher.""" with self.assertRaises(StopIteration): dds(None)