Пример #1
0
    def addressbookMultiGet(self, rurl, hrefs, props):
        """
        Fetches the specified props for the specified hrefs using a single
        multiget call. The return value is a dictionary where the keys are the
        hrefs and the values are PropFindResult objects containing results for
        the requested props.
        """

        assert (isinstance(rurl, URL))

        request = AdbkMultiget(self,
                               rurl.relativeURL(),
                               hrefs=hrefs,
                               props=props)
        result = ResponseDataString()
        request.setOutput(result)

        # Process it
        self.runSession(request)

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

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

        else:
            self.handleHTTPError(request)
            return None
    def addressbookMultiGet(self, rurl, hrefs, props):
        """
        Fetches the specified props for the specified hrefs using a single
        multiget call. The return value is a dictionary where the keys are the
        hrefs and the values are PropFindResult objects containing results for
        the requested props.
        """

        assert(isinstance(rurl, URL))

        request = AdbkMultiget(self, rurl.relativeURL(), hrefs=hrefs, props=props)
        result = ResponseDataString()
        request.setOutput(result)

        # Process it
        self.runSession(request)

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

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

        else:
            self.handleHTTPError(request)
            return None
Пример #3
0
    def getPropertyNames(self, rurl):

        assert(isinstance(rurl, URL))

        results = ()

        # Create WebDAV propfind
        request = PropNames(self, rurl.relativeURL(), headers.Depth0)
        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
            for item in parser.getResults().itervalues():

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

                # Must match rurl
                if name.equalRelative(rurl):

                    results = tuple([name for name in item.getNodeProperties().iterkeys()])

        else:
            self.handleHTTPError(request)

        return results
Пример #4
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
Пример #5
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
Пример #6
0
    def queryCollection(self, rurl, timerange, start, end, expand, props=()):

        assert(isinstance(rurl, URL))

        hrefs = set()

        # Create CalDAV query REPORT
        if timerange:
            request = QueryVEVENTTimeRange(self, rurl.relativeURL(), start, end, expand, props=props)
        else:
            raise NotImplementedError
        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
            for item in parser.getResults().itervalues():

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

        else:
            self.handleHTTPError(request)

        return hrefs
    def parseXML(self, x):

        x = x.replace("\n", "\r\n")

        # Parse the XML data
        p = PropFindParser()
        p.parse(XML(x))
        return p
Пример #8
0
    def getProperties(self, rurl, props, xmldata=False):

        assert (isinstance(rurl, URL))

        results = {}
        bad = None

        # Create WebDAV propfind
        if props:
            request = PropFind(self, rurl.relativeURL(), headers.Depth0, props)
        else:
            request = PropAll(self, rurl.relativeURL(), headers.Depth0)
        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
            for item in parser.getResults().itervalues():

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

                # Must match rurl
                if name.equalRelative(rurl):
                    for name, value in item.getTextProperties().iteritems():
                        results[name] = value
                    for name, value in item.getHrefProperties().iteritems():
                        if name not in results:
                            results[name] = value
                    for name, value in item.getNodeProperties().iteritems():
                        if name not in results:
                            results[name] = tostring(
                                value) if xmldata else value
                    bad = item.getBadProperties()
        else:
            self.handleHTTPError(request)

        return results, bad
Пример #9
0
    def syncCollection(self, rurl, synctoken, props=()):

        assert(isinstance(rurl, URL))

        newsynctoken = ""
        changed = set()
        removed = set()
        other = set()

        # Create WebDAV sync REPORT
        request = SyncCollection(self, rurl.relativeURL(), davxml.sync_level_1, synctoken, 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 propfind result
            for item in parser.getResults().itervalues():

                # Get child element name (decode URL)
                name = URL(url=item.getResource(), decode=True)
                if item.status == 404:
                    removed.add(name)
                elif item.status / 100 != 2:
                    other.add(name)
                else:
                    changed.add(name)

            # Get the new token
            for node in parser.getOthers():
                if node.tag == davxml.sync_token:
                    newsynctoken = node.text
                    break

        else:
            self.handleHTTPError(request)

        return (newsynctoken, changed, removed, other,)
Пример #10
0
    def getProperties(self, rurl, props, xmldata=False):

        assert(isinstance(rurl, URL))

        results = {}
        bad = None

        # Create WebDAV propfind
        if props:
            request = PropFind(self, rurl.relativeURL(), headers.Depth0, props)
        else:
            request = PropAll(self, rurl.relativeURL(), headers.Depth0)
        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
            for item in parser.getResults().itervalues():

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

                # Must match rurl
                if name.equalRelative(rurl):
                    for name, value in item.getTextProperties().iteritems():
                        results[name] = value
                    for name, value in item.getHrefProperties().iteritems():
                        if name not in results:
                            results[name] = value
                    for name, value in item.getNodeProperties().iteritems():
                        if name not in results:
                            results[name] = tostring(value) if xmldata else value
                    bad = item.getBadProperties()
        else:
            self.handleHTTPError(request)

        return results, bad
Пример #11
0
    def getHrefListProperty(self, rurl, propname):

        assert (isinstance(rurl, URL))

        results = ()

        # Create WebDAV propfind
        request = PropFind(self, rurl.relativeURL(), headers.Depth0,
                           (propname, ))
        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)

                # Must match the URL the request was actually targeted at
                if name.equalRelative(URL(url=request.url)):

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

                        propnode = item.getNodeProperties()[str(propname)]
                        results += tuple([
                            URL(url=href.text, decode=True)
                            for href in propnode.findall(str(davxml.href))
                            if href.text
                        ])
        else:
            self.handleHTTPError(request)

        return results
Пример #12
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
Пример #13
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
Пример #14
0
    def getPropertiesOnHierarchy(self, rurl, props):

        assert (isinstance(rurl, URL))

        results = {}

        # Create WebDAV propfind
        request = PropFind(self, rurl.relativeURL(), headers.Depth1, 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 propfind result
            for item in parser.getResults().itervalues():

                # Get child element name (decode URL)
                name = URL(url=item.getResource(), decode=True)
                propresults = {}
                results[name.relativeURL()] = propresults

                for prop in props:

                    if str(prop) in item.getTextProperties():
                        propresults[prop] = item.getTextProperties().get(
                            str(prop))

                    elif str(prop) in item.getNodeProperties():
                        propresults[prop] = item.getNodeProperties()[str(prop)]
        else:
            self.handleHTTPError(request)

        return results
Пример #15
0
    def queryCollection(self, rurl, timerange, start, end, expand, props=()):

        assert (isinstance(rurl, URL))

        hrefs = set()

        # Create CalDAV query REPORT
        if timerange:
            request = QueryVEVENTTimeRange(self,
                                           rurl.relativeURL(),
                                           start,
                                           end,
                                           expand,
                                           props=props)
        else:
            raise NotImplementedError
        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
            for item in parser.getResults().itervalues():

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

        else:
            self.handleHTTPError(request)

        return hrefs
Пример #16
0
    def getPropertiesOnHierarchy(self, rurl, props):

        assert(isinstance(rurl, URL))

        results = {}

        # Create WebDAV propfind
        request = PropFind(self, rurl.relativeURL(), headers.Depth1, 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 propfind result
            for item in parser.getResults().itervalues():

                # Get child element name (decode URL)
                name = URL(url=item.getResource(), decode=True)
                propresults = {}
                results[name.relativeURL()] = propresults

                for prop in props:

                    if str(prop) in item.getTextProperties():
                        propresults[prop] = item.getTextProperties().get(str(prop))

                    elif str(prop) in item.getNodeProperties():
                        propresults[prop] = item.getNodeProperties()[str(prop)]
        else:
            self.handleHTTPError(request)

        return results
Пример #17
0
    def getHrefListProperty(self, rurl, propname):

        assert(isinstance(rurl, URL))

        results = ()

        # Create WebDAV propfind
        request = PropFind(self, rurl.relativeURL(), headers.Depth0, (propname,))
        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)

                # Must match rurl
                if name.equalRelative(rurl):

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

                        propnode = item.getNodeProperties()[str(propname)]
                        results += tuple([URL(url=href.text, decode=True) for href in propnode.findall(str(davxml.href)) if href.text])
        else:
            self.handleHTTPError(request)

        return results
Пример #18
0
    def getPropertyNames(self, rurl):

        assert (isinstance(rurl, URL))

        results = ()

        # Create WebDAV propfind
        request = PropNames(self, rurl.relativeURL(), headers.Depth0)
        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
            for item in parser.getResults().itervalues():

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

                # Must match rurl
                if name.equalRelative(rurl):

                    results = tuple(
                        [name for name in item.getNodeProperties().iterkeys()])

        else:
            self.handleHTTPError(request)

        return results
Пример #19
0
    def syncCollection(self, rurl, synctoken, props=(), infinite=False):

        assert (isinstance(rurl, URL))

        newsynctoken = ""
        changed = set()
        removed = set()
        other = set()

        # Create WebDAV sync REPORT
        request = SyncCollection(
            self, rurl.relativeURL(),
            davxml.sync_level_infinite if infinite else davxml.sync_level_1,
            synctoken, 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 propfind result
            for item in parser.getResults().itervalues():

                # Get child element name (decode URL)
                name = URL(url=item.getResource(), decode=True)
                if int(item.status) == 404:
                    removed.add(name)
                elif int(item.status) / 100 != 2:
                    other.add(name)
                else:
                    changed.add(name)

            # Get the new token
            for node in parser.getOthers():
                if node.tag == davxml.sync_token:
                    newsynctoken = node.text
                    break

        else:
            self.handleHTTPError(request)

        return (
            newsynctoken,
            changed,
            removed,
            other,
        )
Пример #20
0
    def setProperties(self, rurl, props):

        assert(isinstance(rurl, URL))

        results = ()

        # Convert property data into something sensible
        converted = []
        for name, value in props:
            node = None
            if isinstance(value, types.StringType):
                node = Element(name)
                node.text = value
            elif isinstance(value, URL):
                node = Element(davxml.href)
                node.text = value.absoluteURL()
            elif isinstance(value, types.ListType) or isinstance(value, types.TupleType):
                hrefs = []
                for item in value:
                    if isinstance(item, URL):
                        href = Element(davxml.href)
                        href.text = item.relativeURL()
                        hrefs.append(href)
                    else:
                        break
                else:
                    node = Element(name)
                    map(node.append, hrefs)

            if node is not None:
                converted.append(node)

        # Create WebDAV propfind
        request = PropPatch(self, rurl.relativeURL(), converted)
        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
            for item in parser.getResults().itervalues():

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

                # Must match rurl
                if name.equalRelative(rurl):

                    for prop in item.getNodeProperties():
                        results += (prop,)

        else:
            self.handleHTTPError(request)

        return results
Пример #21
0
    def setProperties(self, rurl, props):

        assert (isinstance(rurl, URL))

        results = ()

        # Convert property data into something sensible
        converted = []
        for name, value in props:
            node = None
            if isinstance(value, types.StringType):
                node = Element(name)
                node.text = value
            elif isinstance(value, URL):
                node = Element(davxml.href)
                node.text = value.absoluteURL()
            elif isinstance(value, types.ListType) or isinstance(
                    value, types.TupleType):
                hrefs = []
                for item in value:
                    if isinstance(item, URL):
                        href = Element(davxml.href)
                        href.text = item.relativeURL()
                        hrefs.append(href)
                    else:
                        break
                else:
                    node = Element(name)
                    map(node.append, hrefs)

            if node is not None:
                converted.append(node)

        # Create WebDAV propfind
        request = PropPatch(self, rurl.relativeURL(), converted)
        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
            for item in parser.getResults().itervalues():

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

                # Must match rurl
                if name.equalRelative(rurl):

                    for prop in item.getNodeProperties():
                        results += (prop, )

        else:
            self.handleHTTPError(request)

        return results