Example #1
0
    def toJson(self, data):
        """Add???

        :param data: TODO
        :returns: TODO
        """
        return gnrstring.toJson(data)
Example #2
0
 def toJson(self, obj):
     """add???
     
     :param obj: add???
     :returns: add???
     """
     return toJson(obj)
Example #3
0
 def toJson(self, data):
     """Add???
         
     :param data: TODO
     :returns: TODO
     """
     return gnrstring.toJson(data)
Example #4
0
 def toJson(self, obj):
     """add???
     
     :param obj: add???
     :returns: add???
     """
     return toJson(obj)
Example #5
0
    def nodeToXmlBlock(self, node):
        """Handle all the different node types, call the method build tag and return its result.
        
        :param node: add???
        :returns: the XML tag that represent self BagNode.
        """
        if self.unresolved and node.resolver != None and not getattr(node.resolver, "_xmlEager", None):
            newattr = dict(node.attr)
            newattr["_resolver"] = gnrstring.toJson(node.resolver.resolverSerialize())
            value = ""
            if isinstance(node._value, Bag):
                value = self.bagToXmlBlock(node._value)
            return self.buildTag(node.label, value, newattr, "", xmlMode=True)

        nodeValue = node.getValue()
        if isinstance(nodeValue, Bag) and nodeValue:  # <---Add the second condition in order to type the empty bag.
            result = self.buildTag(node.label, self.bagToXmlBlock(nodeValue), node.attr, "", xmlMode=True)

        elif isinstance(nodeValue, BagAsXml):
            result = self.buildTag(node.label, nodeValue, node.attr, "", xmlMode=True)

        # elif ((isinstance(nodeValue, list) or isinstance(nodeValue, dict))):
        #    nodeValue = gnrstring.toJson(nodeValue)
        #    result = self.buildTag(node.label, nodeValue, node.attr)
        # elif nodeValue and (isinstance(nodeValue, list) or isinstance(nodeValue, tuple)):
        #    result = self.buildTag(node.label,
        #                           '\n'.join([self.buildTag('C', c) for c in nodeValue]),
        #                           node.attr, cls='A%s' % self.catalog.getClassKey(nodeValue[0]),
        #                           xmlMode=True)
        else:
            result = self.buildTag(node.label, nodeValue, node.attr)
        return result
Example #6
0
 def toJson(self, data):
     """Add???
         
     :param data: add???
     :returns: add???
     """
     return gnrstring.toJson(data)
Example #7
0
    def nodeToXmlBlock(self, node):
        """Handle all the different node types, call the method build tag. Return
        the XML tag that represent the BagNode
        
        :param node: the :meth:`BagNode <gnr.core.gnrbag.BagNode>`"""
        nodeattr = dict(node.attr)
        if '__forbidden__' in nodeattr:
            return ''
        if self.unresolved and node.resolver is not None and not getattr(node.resolver,'_xmlEager',None):
            if not nodeattr.get('_resolver_name'):
                nodeattr['_resolver'] = gnrstring.toJson(node.resolver.resolverSerialize())
            value = ''
            if isinstance(node._value, Bag):
                value = self.bagToXmlBlock(node._value)
            return self.buildTag(node.label, value, nodeattr, '', xmlMode=True)

        nodeValue = node.getValue()
        if isinstance(nodeValue, Bag) and nodeValue: #<---Add the second condition in order to type the empty bag.
            result = self.buildTag(node.label,
                                   self.bagToXmlBlock(nodeValue), nodeattr, '', xmlMode=True)

        elif isinstance(nodeValue, BagAsXml):
            result = self.buildTag(node.label, nodeValue, nodeattr, '', xmlMode=True)

        #elif ((isinstance(nodeValue, list) or isinstance(nodeValue, dict))):
        #    nodeValue = gnrstring.toJson(nodeValue)
        #    result = self.buildTag(node.label, nodeValue, node.attr)
        #elif nodeValue and (isinstance(nodeValue, list) or isinstance(nodeValue, tuple)):
        #    result = self.buildTag(node.label,
        #                           '\n'.join([self.buildTag('C', c) for c in nodeValue]),
        #                           node.attr, cls='A%s' % self.catalog.getClassKey(nodeValue[0]),
        #                           xmlMode=True)
        
        elif self.mode4d and (nodeValue and (isinstance(nodeValue, list) or isinstance(nodeValue, tuple))):
            if node.label[:3] in ('AR_','AL_','AT_','AD_','AH_','AB_'):
                cls4d = node.label[:2] # if variable name specify array type, use it
            else:
                cls4d = 'A%s' % self.catalog.getClassKey(nodeValue[0])
            result = self.buildTag(node.label,
                       '\n'.join([self.buildTag('C', c) for c in nodeValue]),
                       node.attr, cls=cls4d,
                       xmlMode=True)

        else:
            result = self.buildTag(node.label, nodeValue, node.attr)
        return result
Example #8
0
    def nodeToXmlBlock(self, node):
        """Handle all the different node types, call the method build tag and return its result.
        
        :param node: add???
        :returns: the XML tag that represent self BagNode.
        """
        if self.unresolved and node.resolver != None and not getattr(
                node.resolver, '_xmlEager', None):
            newattr = dict(node.attr)
            newattr['_resolver'] = gnrstring.toJson(
                node.resolver.resolverSerialize())
            value = ''
            if isinstance(node._value, Bag):
                value = self.bagToXmlBlock(node._value)
            return self.buildTag(node.label, value, newattr, '', xmlMode=True)

        nodeValue = node.getValue()
        if isinstance(
                nodeValue, Bag
        ) and nodeValue:  #<---Add the second condition in order to type the empty bag.
            result = self.buildTag(node.label,
                                   self.bagToXmlBlock(nodeValue),
                                   node.attr,
                                   '',
                                   xmlMode=True)

        elif isinstance(nodeValue, BagAsXml):
            result = self.buildTag(node.label,
                                   nodeValue,
                                   node.attr,
                                   '',
                                   xmlMode=True)

        #elif ((isinstance(nodeValue, list) or isinstance(nodeValue, dict))):
        #    nodeValue = gnrstring.toJson(nodeValue)
        #    result = self.buildTag(node.label, nodeValue, node.attr)
        #elif nodeValue and (isinstance(nodeValue, list) or isinstance(nodeValue, tuple)):
        #    result = self.buildTag(node.label,
        #                           '\n'.join([self.buildTag('C', c) for c in nodeValue]),
        #                           node.attr, cls='A%s' % self.catalog.getClassKey(nodeValue[0]),
        #                           xmlMode=True)
        else:
            result = self.buildTag(node.label, nodeValue, node.attr)
        return result
Example #9
0
    def nodeToXmlBlock(self, node, namespaces=None):
        """Handle all the different node types, call the method build tag. Return
        the XML tag that represent the BagNode

        :param node: the :meth:`BagNode <gnr.core.gnrbag.BagNode>`
        """
        nodeattr = dict(node.attr)
        local_namespaces = [
            k[6:] for k in nodeattr.keys() if k.startswith('xmlns:')
        ]
        current_namespaces = namespaces + local_namespaces

        if '__forbidden__' in nodeattr:
            return ''
        if self.unresolved and node.resolver is not None and not getattr(
                node.resolver, '_xmlEager', None):
            if not nodeattr.get('_resolver_name'):
                nodeattr['_resolver'] = gnrstring.toJson(
                    node.resolver.resolverSerialize())
            value = ''
            if isinstance(node._value, Bag):
                value = self.bagToXmlBlock(node._value,
                                           namespaces=current_namespaces)
            return self.buildTag(node.label,
                                 value,
                                 nodeattr,
                                 '',
                                 xmlMode=True,
                                 namespaces=namespaces)

        nodeValue = node.getValue()
        # Add the second condition in order to type the empty bag.
        if isinstance(nodeValue, Bag) and nodeValue:
            result = self.buildTag(node.label,
                                   self.bagToXmlBlock(
                                       nodeValue,
                                       namespaces=current_namespaces),
                                   nodeattr,
                                   '',
                                   xmlMode=True,
                                   localize=False,
                                   namespaces=namespaces)
        elif isinstance(nodeValue, BagAsXml):
            result = self.buildTag(node.label,
                                   nodeValue,
                                   nodeattr,
                                   '',
                                   xmlMode=True,
                                   namespaces=namespaces)
        elif self.mode4d and (nodeValue and (isinstance(nodeValue, list)
                                             or isinstance(nodeValue, tuple))):
            if node.label[:3] in ('AR_', 'AL_', 'AT_', 'AD_', 'AH_', 'AB_'):
                cls4d = node.label[:
                                   2]  # if variable name specify array type, use it
            else:
                cls4d = 'A%s' % self.catalog.getClassKey(nodeValue[0])
            result = self.buildTag(node.label,
                                   '\n'.join([
                                       self.buildTag(
                                           'C',
                                           c,
                                           namespaces=current_namespaces)
                                       for c in nodeValue
                                   ]),
                                   node.attr,
                                   cls=cls4d,
                                   xmlMode=True,
                                   namespaces=namespaces)

        else:
            result = self.buildTag(node.label,
                                   nodeValue,
                                   node.attr,
                                   namespaces=namespaces)
        return result
Example #10
0
def test_toJson():
    res = gnrstring.toJson([{'a': 2}, {'b': 3, 'c': 6}, {'z': 9}])
    assert res == '[{"a": 2}, {"c": 6, "b": 3}, {"z": 9}]'
Example #11
0
def test_toJson():
    res = gnrstring.toJson([{'a': 2}, {'b': 3, 'c': 6}, {'z': 9}])
    assert res == '[{"a": 2}, {"c": 6, "b": 3}, {"z": 9}]'
Example #12
0
 def toJson(self, obj):
     """Return the object into Json form
     
     :param obj: the object"""
     return toJson(obj)
Example #13
0
 def toJson(self, obj):
     """Return the object into Json form
     
     :param obj: the object"""
     return toJson(obj)