Exemple #1
0
def test():
    from xml.dom.ext.reader import HtmlLib
    from xml.dom import ext

    d = HtmlLib.FromHtmlFile('single.html')
    ext.PrettyPrint(d)

    d = HtmlLib.FromHtmlFile('mulit-single.html')
    ext.PrettyPrint(d)

    d = HtmlLib.FromHtmlFile('bigTest.html')
    ext.PrettyPrint(d)
Exemple #2
0
    def create_propname(self):
        """ create a multistatus response for the prop names """
        dc = self.__dataclass
        # create the document generator
        doc = Document(None)
        ms = doc.createElement("D:multistatus")
        ms.setAttribute("xmlns:D", "DAV:")
        doc.appendChild(ms)

        if self.__depth == "0":
            pnames = dc.get_propnames(self.__uri)
            re = self.mk_propname_response(self.__uri, pnames)
            ms.appendChild(re)

        elif self.__depth == "1":
            pnames = dc.get_propnames(self.__uri)
            re = self.mk_propname_response(self.__uri, pnames)
            ms.appendChild(re)
            for newuri in dc.get_childs(self.__uri):
                pnames = dc.get_propnames(newuri)
                re = self.mk_propname_response(newuri, pnames)
                ms.appendChild(re)
        # *** depth=="infinity"

        sfile = StringIO()
        ext.PrettyPrint(doc, stream=sfile)
        s = sfile.getvalue()
        sfile.close()
        return s
Exemple #3
0
def read_html_from_file(fileName):
    #build a DOM tree from the file
    reader = HtmlLib.Reader()
    dom_object = reader.fromUri(fileName)

    #strip any ignorable white-space in preparation for pretty-printing
    ext.StripHtml(dom_object)

    #pretty-print the node
    ext.PrettyPrint(dom_object)

    #reclaim the object
    reader.releaseNode(dom_object);
    def tree_action(self):
        """ copy a tree of resources (a collection)

        Here we return a multistatus xml element.

        """
        dc = self.__dataclass
        base = self.__src

        ### some basic tests
        # test if dest exists and overwrite is false
        if dc.exists(self.__dst) and not self.__overwrite: raise DAV_Error, 412
        # test if src and dst are the same
        # (we assume that both uris are on the same server!)
        ps = urlparse.urlparse(self.__src)[2]
        pd = urlparse.urlparse(self.__dst)[2]
        if ps == pd: raise DAV_Error, 403

        result = dc.copytree(self.__src, self.__dst, self.__overwrite)
        #result=copytree(dc,self.__src,self.__dst,self.__overwrite)

        if not result: return None

        ###
        ### create the multistatus XML element
        ### (this is also the same as in delete.py.
        ###  we might make a common method out of it)
        ###

        doc = Document(None)
        ms = doc.createElement("D:multistatus")
        ms.setAttribute("xmlns:D", "DAV:")
        doc.appendChild(ms)

        for el, ec in result.items():
            re = doc.createElement("D:response")
            hr = doc.createElement("D:href")
            st = doc.createElement("D:status")
            huri = doc.createTextNode(quote_uri(el))
            t = doc.createTextNode(gen_estring(ec))
            st.appendChild(t)
            hr.appendChild(huri)
            re.appendChild(hr)
            re.appendChild(st)
            ms.appendChild(re)

        sfile = StringIO()
        ext.PrettyPrint(doc, stream=sfile)
        s = sfile.getvalue()
        sfile.close()
        return s
def test(inFile):

    from xml.dom.ext.reader import HtmlLib
    from xml.dom import ext
    from xml.dom import Node
    from xml.dom.html import HTMLDocument

    doc = HTMLDocument.HTMLDocument()

    HtmlLib.FromHtmlStream(inFile, doc)

    print doc

    ext.PrettyPrint(doc)
    def create_prop(self):
        """ handle a <prop> request

        This will

        1. set up the <multistatus>-Framework

        2. read the property values for each URI
           (which is dependant on the Depth header)
           This is done by the get_propvalues() method.

        3. For each URI call the append_result() method
           to append the actual <result>-Tag to the result
           document.

        We differ between "good" properties, which have been
        assigned a value by the interface class and "bad"
        properties, which resulted in an error, either 404
        (Not Found) or 403 (Forbidden).

        """

        # create the document generator
        doc = Document(None)
        ms = doc.createElement("D:multistatus")
        ms.setAttribute("xmlns:D", "DAV:")
        doc.appendChild(ms)

        if self.__depth == "0":
            gp, bp = self.get_propvalues(self.__uri)
            res = self.mk_prop_response(self.__uri, gp, bp, doc)
            ms.appendChild(res)

        elif self.__depth == "1":
            gp, bp = self.get_propvalues(self.__uri)
            res = self.mk_prop_response(self.__uri, gp, bp, doc)
            ms.appendChild(res)

        for newuri in self.__dataclass.get_childs(self.__uri):
            gp, bp = self.get_propvalues(newuri)
            res = self.mk_prop_response(newuri, gp, bp, doc)
            ms.appendChild(res)

        sfile = StringIO()
        ext.PrettyPrint(doc, stream=sfile)
        s = sfile.getvalue()
        sfile.close()
        return s
Exemple #7
0
def make_xmlresponse(result):
    """ construct a response from a dict of uri:error_code elements """
    doc = Document.Document(None)
    ms = doc.createElement("D:multistatus")
    ms.setAttribute("xmlns:D", "DAV:")
    doc.appendChild(ms)

    for el, ec in result.items():
        re = doc.createElement("D:response")
        hr = doc.createElement("D:href")
        st = doc.createElement("D:status")
        huri = doc.createTextNode(quote_uri(el))
        t = doc.createTextNode(gen_estring(ec))
        st.appendChild(t)
        hr.appendChild(huri)
        re.appendChild(hr)
        re.appendChild(st)
        ms.appendChild(re)

    sfile = StringIO()
    ext.PrettyPrint(doc, stream=sfile)
    s = sfile.getvalue()
    sfile.close()
    return s