예제 #1
0
def _basetype(var, printname=True):
    if printname:
        yield var.id
        yield '\n'

    if not getattr(var, "shape", ()):
        yield encode(var.data)
    else:
        for indexes, value in zip(np.ndindex(var.shape), var.data.flat):
            yield "{indexes} {value}\n".format(
                indexes="[" + "][".join([str(idx) for idx in indexes]) + "]",
                value=encode(value))
예제 #2
0
파일: ascii.py 프로젝트: taeold/pydap
def _(var, printname=True):
    if printname:
        yield var.id
        yield '\n'

    if not getattr(var, "shape", ()):
        yield encode(var.data)
    else:
        for indexes, value in zip(np.ndindex(var.shape), var.data.flat):
            yield "{indexes} {value}\n".format(
                indexes="[" + "][".join([str(idx) for idx in indexes]) + "]",
                value=encode(value))
예제 #3
0
파일: das.py 프로젝트: lukecampbell/pydap
def build_attributes(attr, values, level=0):
    """
    Recursive function to build the DAS.
    
    """
    # check for metadata
    if isinstance(values, dict):
        yield '{indent}{attr} {{\n'.format(indent=(level+1)*INDENT, attr=attr)
        for k, v in values.items():
            for line in build_attributes(k, v, level+1):
                yield line
        yield '{indent}}}\n'.format(indent=(level+1)*INDENT)
    else:
        # get type
        type = get_type(values)

        # encode values
        if isinstance(values, basestring) or not isinstance(values, Iterable):
            values = [encode(values)]
        else:
            values = map(encode, values)

        yield '{indent}{type} {attr} {values};\n'.format(
                indent=(level+1)*INDENT,
                type=type,
                attr=quote(attr),
                values=', '.join(values))
예제 #4
0
파일: das.py 프로젝트: phrrngtn/pydap
def build_attributes(attr, values, level=0):
    """Recursive function to build the DAS."""
    # check for metadata
    if isinstance(values, dict):
        yield '{indent}{attr} {{\n'.format(indent=(level) * INDENT, attr=attr)
        for k, v in values.items():
            for line in build_attributes(k, v, level + 1):
                yield line
        yield '{indent}}}\n'.format(indent=(level) * INDENT)
    else:
        # get type
        type = get_type(values)

        # encode values
        if (isinstance(values, string_types)
                or not isinstance(values, Iterable)
                or getattr(values, 'shape', None) == ()):
            values = [encode(values)]
        else:
            values = map(encode, values)

        yield '{indent}{type} {attr} {values};\n'.format(
            indent=(level) * INDENT,
            type=type,
            attr=quote(attr),
            values=', '.join(values))
예제 #5
0
 def __call__(self, *args):
     params = []
     for arg in args:
         if isinstance(arg, (DapType, ServerFunctionResult)):
             params.append(arg.id)
         else:
             params.append(encode(arg))
     id_ = self.name + '(' + ','.join(params) + ')'
     return ServerFunctionResult(self.baseurl, id_)
예제 #6
0
 def __call__(self, *args):
     params = []
     for arg in args:
         if isinstance(arg, (DapType, ServerFunctionResult)):
             params.append(arg.id)
         else:
             params.append(encode(arg))
     id_ = self.name + '(' + ','.join(params) + ')'
     return ServerFunctionResult(self.baseurl, id_, self.application,
                                 self.session)
예제 #7
0
    def __init__(self, info):
        # get exception message
        buf = StringIO()
        print_exception(*info, file=buf)
        message = encode(buf.getvalue())

        # build error message
        code = getattr(info[0], 'code', -1)
        self.body = r'''Error {{
    code = {};
    message = {};
}}'''.format(code, message)
예제 #8
0
 def __gt__(self, other): return ConstraintExpression('%s>%s' % (self.id, encode(other)))
 def __lt__(self, other): return ConstraintExpression('%s<%s' % (self.id, encode(other)))
예제 #9
0
 def __eq__(self, other): return ConstraintExpression('%s=%s' % (self.id, encode(other)))
 def __ne__(self, other): return ConstraintExpression('%s!=%s' % (self.id, encode(other)))
예제 #10
0
 def __ge__(self, other): return ConstraintExpression('%s>=%s' % (self.id, encode(other)))
 def __le__(self, other): return ConstraintExpression('%s<=%s' % (self.id, encode(other)))
예제 #11
0
 def test_integer(self):
     """Test integer encoding."""
     self.assertEqual(encode(1), "1")
예제 #12
0
파일: dap.py 프로젝트: pydap/pydap
 def __lt__(self, other):
     return ConstraintExpression("%s<%s" % (self.id, encode(other)))
예제 #13
0
파일: dap.py 프로젝트: lukecampbell/pydap
 def __lt__(self, other):
     return ConstraintExpression('%s<%s' % (self.id, encode(other)))
예제 #14
0
 def test_integer(self):
     """Test integer encoding."""
     self.assertEqual(encode(1), "1")
예제 #15
0
 def test_unicode(self):
     """Unicode objects are encoded just like strings."""
     self.assertEqual(encode(u"test"), '"test"')
예제 #16
0
 def __lt__(self, other):
     if isinstance(other, self.__class__):
         right = other.template.id
     else:
         right = encode(other)
     return ConstraintExpression('%s<%s' % (self.template.id, right))
예제 #17
0
 def test_unicode(self):
     """Unicode objects are encoded just like strings."""
     self.assertEqual(encode(u"test"), '"test"')
예제 #18
0
 def test_obj(self):
     """Other objects are encoded according to their ``repr``."""
     self.assertEqual(encode({}), '"{}"')
예제 #19
0
 def test_string_with_quotation(self):
     """Test encoding a string with a quotation mark."""
     self.assertEqual(encode('this is a "test"'), '"this is a \"test\""')
예제 #20
0
 def test_string(self):
     """Test string encoding."""
     self.assertEqual(encode("test"), '"test"')
예제 #21
0
 def test_float(self):
     """Test floating encoding."""
     self.assertEqual(encode(np.pi), "3.14159")
예제 #22
0
    def __lt__(self, other): return ConstraintExpression('%s<%s' % (self.id, encode(other)))


def build_filter(selection, cols):                                              
예제 #23
0
    def __lt__(self, other): return ConstraintExpression('%s<%s' % (self.id, encode(other)))


class StreamReader(object):
예제 #24
0
 def test_float(self):
     """Test floating encoding."""
     self.assertEqual(encode(np.pi), "3.14159")
예제 #25
0
 def test_string_with_quotation(self):
     """Test encoding a string with a quotation mark."""
     self.assertEqual(encode('this is a "test"'), '"this is a \"test\""')
예제 #26
0
 def __lt__(self, other):
     if isinstance(other, self.__class__):
         right = other.template.id
     else:
         right = encode(other)
     return ConstraintExpression('%s<%s' % (self.template.id, right))
예제 #27
0
 def test_string(self):
     """Test string encoding."""
     self.assertEqual(encode("test"), '"test"')
예제 #28
0
 def test_numpy_string(self):
     self.assertEqual(encode(np.array('1', dtype='<U1')), '"1"')
예제 #29
0
 def test_obj(self):
     """Other objects are encoded according to their ``repr``."""
     self.assertEqual(encode({}), '"{}"')