示例#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({}), '"{}"')