示例#1
0
def statement_unicode (model, prefixes, encoding='ASCII'):
        e, children = pns_to_xml_unicode (model)
        if children:
                e.xml_children = []
                for child in netstring.decode (children):
                        subject, name = netstring.decode (child)
                        if subject:
                                e.xml_children.append ('<%s pns="%s"/>' % (
                                        ''.join (xml_unicode.xml_prefix_FQN (
                                                unicode (name, 'utf-8'), 
                                                prefixes, encoding
                                                )),
                                        xml_unicode.xml_attr (
                                                unicode (subject, 'utf-8'), 
                                                encoding
                                                )
                                        ))
                        else:
                                e.xml_children.append (
                                        '<%s%s'
                                        ' />' % xml_unicode.xml_prefix_FQN (
                                                unicode (name, 'utf-8'), 
                                                prefixes, encoding
                                                )
                                        )
        return xml_unicode.xml_prefixed (
                e, prefixes, 
                ' context="%s"' % xml_unicode.xml_attr (
                        unicode (model[3], 'utf-8'), encoding
                        ), encoding
                )
示例#2
0
def name_unicode(name, tag='public', encoding='ASCII'):
    names = tuple(netstring.decode(name)) or (name, )
    if len(names) > 1:
        return '<%s names="%s">%s</%s>' % (
            tag, xml_unicode.xml_attr(unicode(name, 'UTF-8')), ''.join(
                [name_unicode(n, tag, encoding) for n in names]), tag)

    return '<%s>%s</%s>' % (tag, xml_unicode.xml_cdata(unicode(name,
                                                               'UTF-8')), tag)


# Note about this implementation
#
# it may be possible to get rid of the last level of PNS/XML articulation
# and make articulation sparser, by allowing un-named child element to
# be completely encoded in their parent. Yet this practically makes encoding
# from XML to PNS also more complex to support sensible trunking.
#
# Most XML leaf elements do not require a PNS/XML statement but the
# presence of one too large in their midst suppose a more elaborated
# algorithm for sparse articulation, counting every bytes in the parent's
# PNS/XML statement to decide which elements to "inline" as:
#
#         :subject,:name,::attributes,:first,:follow,,
#
# and which to reference only:
#
#         :subject,:name,:,
#
# it just might not be worth the trouble.
#
# TODO: add a depth limit to PNS_XML, avoid the possible infinite loop
#       when there is a circular PNS/XML statement in the metabase for
#       the articulated XML element tree.
示例#3
0
def statement_unicode(model, prefixes, encoding='ASCII'):
    e, children = pns_to_xml_unicode(model)
    if children:
        e.xml_children = []
        for child in netstring.decode(children):
            subject, name = netstring.decode(child)
            if subject:
                e.xml_children.append(
                    '<%s pns="%s"/>' %
                    (''.join(
                        xml_unicode.xml_prefix_FQN(unicode(name, 'utf-8'),
                                                   prefixes, encoding)),
                     xml_unicode.xml_attr(unicode(subject, 'utf-8'),
                                          encoding)))
            else:
                e.xml_children.append(
                    '<%s%s'
                    ' />' % xml_unicode.xml_prefix_FQN(unicode(name, 'utf-8'),
                                                       prefixes, encoding))
    return xml_unicode.xml_prefixed(
        e, prefixes, ' context="%s"' %
        xml_unicode.xml_attr(unicode(model[3], 'utf-8'), encoding), encoding)
示例#4
0
def name_unicode (name, tag='public', encoding='ASCII'):
        names = tuple (netstring.decode (name)) or (name,)
        if len (names) > 1:
                return '<%s names="%s">%s</%s>' % (
                        tag,
                        xml_unicode.xml_attr (unicode (name, 'UTF-8')), 
                        ''.join ([name_unicode (
                                n, tag, encoding
                                ) for n in names]),
                        tag
                        )

        return '<%s>%s</%s>' % (
                tag, xml_unicode.xml_cdata (unicode (name, 'UTF-8')), tag
                )


# Note about this implementation 
#
# it may be possible to get rid of the last level of PNS/XML articulation
# and make articulation sparser, by allowing un-named child element to
# be completely encoded in their parent. Yet this practically makes encoding
# from XML to PNS also more complex to support sensible trunking.
#
# Most XML leaf elements do not require a PNS/XML statement but the
# presence of one too large in their midst suppose a more elaborated
# algorithm for sparse articulation, counting every bytes in the parent's
# PNS/XML statement to decide which elements to "inline" as:
#
#         :subject,:name,::attributes,:first,:follow,,
#
# and which to reference only:
#
#         :subject,:name,:,
#
# it just might not be worth the trouble.
#
# TODO: add a depth limit to PNS_XML, avoid the possible infinite loop 
#       when there is a circular PNS/XML statement in the metabase for
#       the articulated XML element tree.