Exemplo n.º 1
0
def parseXRDS(text):
    """Parse the given text as an XRDS document.

    @return: ElementTree containing an XRDS document

    @raises XRDSError: When there is a parse error or the document does
        not contain an XRDS.
    """
    try:
        parser = XMLTreeBuilder()
        parser.feed(text)
        element = parser.close()
    except XMLError, why:
        exc = XRDSError('Error parsing document as XML')
        exc.reason = why
        raise exc
Exemplo n.º 2
0
def parseXRDS(text):
    """Parse the given text as an XRDS document.

    @return: ElementTree containing an XRDS document

    @raises XRDSError: When there is a parse error or the document does
        not contain an XRDS.
    """
    try:
        parser = XMLTreeBuilder()
        parser.feed(text)
        element = parser.close()
    except XMLError, why:
        exc = XRDSError('Error parsing document as XML')
        exc.reason = why
        raise exc
Exemplo n.º 3
0
Arquivo: meld3.py Projeto: openxxs/gps
 def _start(self, tag, attrib_in):
     # this is used by self._parser (an Expat parser) as
     # StartElementHandler but only if _start_list is not
     # provided... so why does this method exist?
     for key in attrib_in:
         if "{" + key == _MELD_ID:
             meldid = attrib_in[key]
             if self.meldids.get(meldid):
                 raise ValueError, ('Repeated meld id "%s" in source' % meldid)
             self.meldids[meldid] = 1
     return XMLTreeBuilder._start(self, tag, attrib_in)
Exemplo n.º 4
0
 def _start(self, tag, attrib_in):
     # this is used by self._parser (an Expat parser) as
     # StartElementHandler but only if _start_list is not
     # provided... so why does this method exist?
     for key in attrib_in:
         if '{' + key == _MELD_ID:
             meldid = attrib_in[key]
             if self.meldids.get(meldid):
                 raise ValueError, ('Repeated meld id "%s" in source' %
                                    meldid)
             self.meldids[meldid] = 1
     return XMLTreeBuilder._start(self, tag, attrib_in)
Exemplo n.º 5
0
Arquivo: meld3.py Projeto: openxxs/gps
 def _start_list(self, tag, attrib_in):
     # This is used by self._parser (an Expat parser)
     # as StartElementHandler.  attrib_in is a flat even-length
     # sequence of name, value pairs for all attributes.
     # See http://python.org/doc/lib/xmlparser-objects.html
     for i in range(0, len(attrib_in), 2):
         # For some reason, clark names are missing the leading '{'
         attrib = self._fixname(attrib_in[i])
         if _MELD_ID == attrib:
             meldid = attrib_in[i + 1]
             if self.meldids.get(meldid):
                 raise ValueError, ('Repeated meld id "%s" in source' % meldid)
             self.meldids[meldid] = 1
     return XMLTreeBuilder._start_list(self, tag, attrib_in)
Exemplo n.º 6
0
    def body(self, xml):
        """ Body importer
        """

        if isinstance(xml, (str, unicode)):
            parser = XMLTreeBuilder()
            parser.feed(xml)
            tree = parser.close()
            tree = ElementTree(tree)
            elem = tree.getroot()
        else:
            elem = xml

        if elem.tag != 'object':
            raise AttributeError('Invalid xml root element %s' % elem.tag)

        name = elem.get('name')
        if not name:
            raise AttributeError('No name provided for object')

        if hasattr(self.context, '__name__') and (name != self.context.__name__):
            raise AttributeError(('XML root object name %s '
                'should match context name %s') % (name, self.context.__name__))

        for child in elem.getchildren():
            if child.tag == 'property':
                self.attribute = child
            elif child.tag == 'object':
                self.child = child

        event.notify(ObjectModifiedEvent(self.context))

        if INews.providedBy(self.context):
            logger.info('Commit transaction import for %s' % getattr(
                self.context, '__name__', '(no name)'))
            transaction.commit()
Exemplo n.º 7
0
 def _start_list(self, tag, attrib_in):
     # This is used by self._parser (an Expat parser)
     # as StartElementHandler.  attrib_in is a flat even-length
     # sequence of name, value pairs for all attributes.
     # See http://python.org/doc/lib/xmlparser-objects.html
     for i in range(0, len(attrib_in), 2):
         # For some reason, clark names are missing the leading '{'
         attrib = self._fixname(attrib_in[i])
         if _MELD_ID == attrib:
             meldid = attrib_in[i + 1]
             if self.meldids.get(meldid):
                 raise ValueError, ('Repeated meld id "%s" in source' %
                                    meldid)
             self.meldids[meldid] = 1
     return XMLTreeBuilder._start_list(self, tag, attrib_in)
Exemplo n.º 8
0
    def __request_xml(self, url):
        y = urllib.urlopen(url)
        ret = y.read()
        y.close()

        parser = XMLTreeBuilder(html=True)
        parser.entity = self.entities
        parser.feed(ret)

        return parser.close()
Exemplo n.º 9
0
Arquivo: meld3.py Projeto: openxxs/gps
 def close(self):
     val = XMLTreeBuilder.close(self)
     self.meldids = {}
     return val
Exemplo n.º 10
0
Arquivo: meld3.py Projeto: openxxs/gps
 def __init__(self, html=0, target=None):
     XMLTreeBuilder.__init__(self, html, target)
     # assumes ElementTree 1.2.X
     self._parser.CommentHandler = self.handle_comment
     self.meldids = {}
Exemplo n.º 11
0
 def close(self):
     val = XMLTreeBuilder.close(self)
     self.meldids = {}
     return val
Exemplo n.º 12
0
 def __init__(self, html=0, target=None):
     XMLTreeBuilder.__init__(self, html, target)
     # assumes ElementTree 1.2.X
     self._parser.CommentHandler = self.handle_comment
     self.meldids = {}