예제 #1
0
파일: ascii.py 프로젝트: taeold/pydap
    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')
예제 #2
0
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
예제 #3
0
    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')
예제 #4
0
파일: dods.py 프로젝트: phrrngtn/pydap
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
예제 #5
0
    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
예제 #6
0
파일: dods.py 프로젝트: phrrngtn/pydap
    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
예제 #7
0
 def test_dispatcher(self):
     """Test the single dispatcher."""
     with self.assertRaises(StopIteration):
         dds(None)
예제 #8
0
 def test_dispatcher(self):
     """Test the single dispatcher."""
     with self.assertRaises(StopIteration):
         dds(None)