예제 #1
0
    def getSelfHrefs(self, rurl):

        assert(isinstance(rurl, URL))

        results = ()

        # Create WebDAV principal-match
        request = PrincipalMatch(self, rurl.relativeURL(), (davxml.principal_URL,))
        result = ResponseDataString()
        request.setOutput(result)

        # Process it
        self.runSession(request)

        # If its a 207 we want to parse the XML
        if request.getStatusCode() == statuscodes.MultiStatus:

            parser = PropFindParser()
            parser.parseData(result.getData())

            # Look at each propfind result and extract any Hrefs
            for item in parser.getResults().itervalues():

                # Get child element name (decode URL)
                name = URL(url=item.getResource(), decode=True)
                results += (name,)

        else:
            self.handleHTTPError(request)
            return None

        return results
예제 #2
0
    def getSelfHrefs(self, rurl):

        assert (isinstance(rurl, URL))

        results = ()

        # Create WebDAV principal-match
        request = PrincipalMatch(self, rurl.relativeURL(),
                                 (davxml.principal_URL, ))
        result = ResponseDataString()
        request.setOutput(result)

        # Process it
        self.runSession(request)

        # If its a 207 we want to parse the XML
        if request.getStatusCode() == statuscodes.MultiStatus:

            parser = PropFindParser()
            parser.parseData(result.getData())

            # Look at each propfind result and extract any Hrefs
            for item in parser.getResults().itervalues():

                # Get child element name (decode URL)
                name = URL(url=item.getResource(), decode=True)
                results += (name, )

        else:
            self.handleHTTPError(request)
            return None

        return results
    def test_Depth0Headers(self):

        server = Session("www.example.com")
        request = PrincipalMatch(server, "/", ())
        hdrs = request.generateRequestHeader()
        self.assertTrue("Depth: 0" in hdrs)
        self.assertFalse("Depth: 1" in hdrs)
        self.assertFalse("Depth: infinity" in hdrs)
    def test_Depth0Headers(self):

        server = Session("www.example.com")
        request = PrincipalMatch(server, "/", ())
        hdrs = request.generateRequestHeader()
        self.assertTrue("Depth: 0" in hdrs)
        self.assertFalse("Depth: 1" in hdrs)
        self.assertFalse("Depth: infinity" in hdrs)
    def test_GenerateXMLOneProperty(self):

        server = Session("www.example.com")
        request = PrincipalMatch(server, "/", (davxml.getetag,))
        os = StringIO()
        request.generateXML(os)
        self.assertEqual(os.getvalue(), """<?xml version='1.0' encoding='utf-8'?>
<ns0:principal-match xmlns:ns0="DAV:">
  <ns0:self />
  <ns0:prop>
    <ns0:getetag />
  </ns0:prop>
</ns0:principal-match>
""".replace("\n", "\r\n")
        )
    def test_GenerateXMLOneProperty(self):

        server = Session("www.example.com")
        request = PrincipalMatch(server, "/", (davxml.getetag, ))
        os = StringIO()
        request.generateXML(os)
        self.assertEqual(
            os.getvalue(), """<?xml version='1.0' encoding='utf-8'?>
<ns0:principal-match xmlns:ns0="DAV:">
  <ns0:self />
  <ns0:prop>
    <ns0:getetag />
  </ns0:prop>
</ns0:principal-match>
""".replace("\n", "\r\n"))
예제 #7
0
    def getSelfProperties(self, rurl, props):

        assert (isinstance(rurl, URL))

        results = {}

        # Create WebDAV principal-match
        request = PrincipalMatch(self, rurl.relativeURL(), props)
        result = ResponseDataString()
        request.setOutput(result)

        # Process it
        self.runSession(request)

        # If its a 207 we want to parse the XML
        if request.getStatusCode() == statuscodes.MultiStatus:

            parser = PropFindParser()
            parser.parseData(result.getData())

            # Look at each principal-match result and return first one that is appropriate
            for item in parser.getResults().itervalues():

                for prop in props:

                    if str(prop) in item.getNodeProperties():

                        href = item.getNodeProperties()[str(prop)].find(
                            str(davxml.href))

                        if href is not None:
                            results[prop] = URL(url=href.text, decode=True)

                # We'll take the first one, whatever that is
                break

        else:
            self.handleHTTPError(request)
            return None

        return results
예제 #8
0
    def getSelfProperties(self, rurl, props):

        assert(isinstance(rurl, URL))

        results = {}

        # Create WebDAV principal-match
        request = PrincipalMatch(self, rurl.relativeURL(), props)
        result = ResponseDataString()
        request.setOutput(result)

        # Process it
        self.runSession(request)

        # If its a 207 we want to parse the XML
        if request.getStatusCode() == statuscodes.MultiStatus:

            parser = PropFindParser()
            parser.parseData(result.getData())

            # Look at each principal-match result and return first one that is appropriate
            for item in parser.getResults().itervalues():

                for prop in props:

                    if str(prop) in item.getNodeProperties():

                        href = item.getNodeProperties()[str(prop)].find(str(davxml.href))

                        if href is not None:
                            results[prop] = URL(url=href.text, decode=True)

                # We'll take the first one, whatever that is
                break

        else:
            self.handleHTTPError(request)
            return None

        return results
    def test_Method(self):

        server = Session("www.example.com")
        request = PrincipalMatch(server, "/", ())
        self.assertEqual(request.getMethod(), "REPORT")
    def test_Method(self):

        server = Session("www.example.com")
        request = PrincipalMatch(server, "/", ())
        self.assertEqual(request.getMethod(), "REPORT")