<commit_before>#!/usr/bin/env python
# -*- encoding: utf-8 -*-

import copy
import urlparse
import vobject
import StringIO
import uuid
from lxml import etree

from caldav.lib import error, vcal, url
from caldav.lib.namespace import ns
from caldav.elements import dav, cdav


class DAVObject(object):
    """
    Base class for all DAV objects.
    """
    id = None
    url = None
    client = None
    parent = None
    name = None

    def __init__(self, client, url=None, parent=None, name=None, id=None):
        """
        Default constructor.

        Parameters:
         * client: A DAVClient instance
         * url: The url for this object
         * parent: The parent object
         * name: A displayname
         * id: The resource id (UID for an Event)
        """

        self.client = client
        self.parent = parent
        self.name = name
        self.id = id
        if url is not None:
            self.url = urlparse.urlparse(url)

    @property
    def canonical_url(self):
        return url.canonicalize(self.url, self.parent)

    def children(self, type=None):
        """
        List children, using a propfind (resourcetype) on the parent object,
        at depth = 1.
        """
        c = []

        depth = 1
        properties = {}

        props = [dav.ResourceType(), ]

        prop = dav.Prop() + props
        root = dav.Propfind() + prop

        body = etree.tostring(root.xmlelement(), encoding="utf-8",
                              xml_declaration=True)

        response = self.client.propfind(self.url.path, body, depth)
        for r in response.tree.findall(dav.Response.tag):
            # We use canonicalized urls to index children<commit_msg>Automated merge with ssh://bitbucket.org/cyrilrbt/caldav<commit_after>#!/usr/bin/env python
# -*- encoding: utf-8 -*-

import copy
import urlparse
import vobject
import StringIO
import uuid
from lxml import etree

from caldav.lib import error, vcal, url
from caldav.lib.namespace import ns
from caldav.elements import dav, cdav


class DAVObject(object):
    """
    Base class for all DAV objects.
    """
    id = None
    url = None
    client = None
    parent = None
    name = None

    def __init__(self, client, url=None, parent=None, name=None, id=None):
        """
        Default constructor.

        Parameters:
         * client: A DAVClient instance
         * url: The url for this object
         * parent: The parent object
         * name: A displayname
         * id: The resource id (UID for an Event)
        """

        self.client = client
        self.parent = parent
        self.name = name
        self.id = id
        if isinstance(url, urlparse.ParseResult):
            self.url = url
        elif url is not None:
            self.url = urlparse.urlparse(url)

    @property
    def canonical_url(self):
        return url.canonicalize(self.url, self.parent)

    def children(self, type=None):
        """
        List children, using a propfind (resourcetype) on the parent object,
        at depth = 1.
        """
        c = []

        depth = 1
        properties = {}

        props = [dav.ResourceType(), ]

        prop = dav.Prop() + props
        root = dav.Propfind() + prop

        body = etree.tostring(root.xmlelement(), encoding="utf-8",
                              xml_declaration=True)

        response = self.client.propfind(self.url.path, body, depth)
        for r in response.tree.findall(dav.Response.tag):
            # We use canonicalized urls to index children
{'fraction_non_alphanumeric': 0.09830028328611898, 'fraction_numerical': 0.0022662889518413596, 'mean_word_length': 1.974726200505476, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1600716', 'n_tokens_mistral': 1046, 'n_tokens_neox': 997, 'n_words': 315}