__name__        = 'xmlfetch.py'
__author__      = 'Trionice'
__date__        = '9-11-2006'
__version__     = '0.1.1'
__license__     = 'GPL'
__copyright__   = 'Copyright (c) Ivan Furone, 2006'


__all__ = ['xmlfetch','operator','repr','types']
filter(__import__, __all__)



class XMLObj(object):

    tree = str()

    def __init__(self,tree=''):

        self.tree = tree + XMLObj.tree
        return self.tree

class XMLFetch(XMLObj):

     def __init__(self, version=1.0, charset="UTF-8", standalone="yes"):
         self.version =     version
         self.charset =     charset
         self.standalone =  standalone

         self.tree = XMLObj.__init__(self,tree=XMLObj.tree)
         self.nodes = ()

     def _gendecl(self):

        """
        Returns a string representing a standard XML 1.0 declaration equal
        as it is default initialized in __init__.

        """

        return '<? xml version="%f" charset="%s" standalone="%s"?>' \
    % (self.version,self.charset,self.standalone)

     def _embedparser(self, tree, XMLparser='xml.sax'):

         """
         Returns a correctly parsed chunk of valid xml according to the parsing
         libraries it relies on (currently it relies on xml.sax only)

         """

         from xml.sax.handler import ContentHandler
         if XMLparser == 'xml.sax':import xml.sax
         pstring = tree;TempHandler = ContentHandler()
         try:
            do_parse = xml.sax.parseString(pstring,TempHandler)
         except:
            return False
         return True

     def _is_node(self, node):

        """
        Checks if a given node is present in the class dict that holds the nodes for
        further processing.

        """

        is_node = node in self.__dict__[nodes]
        if is_node:
            flag = True
        return flag

     def _diffnode(self, node):

        """
        Find equivalence between two nodes.

        """

        if map (self._is_node,(nodeA, nodeB))[0] == True:
            diff = cmp(self, nodeA, nodeB)
            if diff == 0:
                return nodeA
            else: return None

     def yieldattr(self, attr):


        """
         Takes as argument a dictionary which keys are the names of a node's
         attributes,each one bound with their value.It processes the dict's items,
         returning a string from the resulting list of just-unpacked tuples.

        """
        t = attr.items()
        t2 = []
        for item in t[:]: