<commit_before>from xml.etree import cElementTree as ctree

class Base(object):

    def addElement(self, elt, tagName=None):
        root = self.etree
        t_elt = root.find(tagName)
        if not t_elt:
            t_elt = ctree.SubElement(root, tagName)

        root.append(t_elt)
        return True

    def removeElement(self, elt, tagName=None):
        root = self.etree
        t_elt = root.find(tagName)

        try:
            root.remove(t_elt)
            return True
        except Exception,e:
            print(e)

        return False

    def addFunction(self, func_code, from_file=''):
        """Add function 
        """
        if from_file:
            with open(from_file) as f:
                func_code = f.read()

        root = self.etree
        t_execute = root.find('execute')

        if not t_execute :
            t_execute = ctree.SubElement(root, 'execute')

        t_execute.text = "\n\t![CDATA]{0:>5}]]\n\t".format(func_code.ljust(4))

        return True

    def removeFunction(self):
        """Remove function tag
        """
        root = self.etree
        t_execute = root.find('execute')
        try:
            root.remove(t_execute)
            return True
        except Exception,e:
            print(e)

        return False


class BaseBinder(Base):
    """Represents any element under <bindings> : <select>,<insert>,<update>,<delete> and <function>
    """
    def __init__(self, name, **kwargs):
        """
        """
        self.name = name
        vars(self).update(kwargs)

        self.etree = self._buildElementTree()

        if self.urls:
            [ self.addUrl(url) for url in self.urls ]

        if self.inputs:
            [ self.addInput(elt) for elt in self.inputs ]

        if self.paging:
            self.addPaging(self.paging)
        
    def _buildElementTree(self,):
        """Turns object into a Element Tree
        """
        t_binder = ctree.Element(self.name)

        for k,v in self.__dict__.items():
            if k not in ('name', 'urls', 'inputs', 'paging') and v :
                t_binder.set(k,v)

        self.etree = t_binder
        return t_binder

    def addUrl(self, url):
        """Add url to binder
        """

        if not url in self.urls:
            self.urls.append(url)

        root = self.etree
        t_urls = root.find('urls')

        if not t_urls:
            t_urls = ctree.SubElement(root, 'urls')

        t_url = ctree.SubElement(t_urls, 'url')
        t_url.text = url

        return True

    def removeUrl(self, url):
        """Remove passed url from a binder
        """

        root = self.etree
        t_urls = root.find('urls')

        if not t_urls:
            return False

        for t_url in t_urls.findall('url'):
            if t_url.text == url.strip():
                t_urls.remove(t_url)
                if url in self.urls:
                    self.urls.remove(url)
                return True

        return False

    def addInput(self, key):
        """Add key to input : key, value or map
        """
        if not key in self.inputs:
            self.inputs.append(key)

        root = self.etree
        t_inputs = root.find('inputs')

        if not t_inputs :
            t_inputs = ctree.SubElement(root, 'inputs')

        t_inputs.append(key.etree)

        return True

    def removeInput(self, key_id):
        """Remove key (key, value, map) from Input
        """
        root = self.etree
        t_inputs = root.find('inputs')

        if not t_inputs:
            return False

        keys = t_inputs.findall('key')

        key = [ key for key in keys if key.get('id') == key_id ]

        try:
            t_inputs.remove(key[0])
            return True
        except Exception,e:
            print(e)

        return False

    def addPaging(self,paging):
        """Add paging to Binder
        """
        if not self.paging:
            self.paging = paging
        root = self.etree

        try:
            root.append(paging.etree)
            return True
        except Exception,e:
            print(e)

        return False

    def removePaging(self,):<commit_msg>#52 : removeInput new attribute added<commit_after>from xml.etree import cElementTree as ctree

class Base(object):

    def addElement(self, elt, tagName=None):
        root = self.etree
        t_elt = root.find(tagName)
        if not t_elt:
            t_elt = ctree.SubElement(root, tagName)

        root.append(t_elt)
        return True

    def removeElement(self, elt, tagName=None):
        root = self.etree
        t_elt = root.find(tagName)

        try:
            root.remove(t_elt)
            return True
        except Exception,e:
            print(e)

        return False

    def addFunction(self, func_code, from_file=''):
        """Add function 
        """
        if from_file:
            with open(from_file) as f:
                func_code = f.read()

        root = self.etree
        t_execute = root.find('execute')

        if not t_execute :
            t_execute = ctree.SubElement(root, 'execute')

        t_execute.text = "\n\t![CDATA]{0:>5}]]\n\t".format(func_code.ljust(4))

        return True

    def removeFunction(self):
        """Remove function tag
        """
        root = self.etree
        t_execute = root.find('execute')
        try:
            root.remove(t_execute)
            return True
        except Exception,e:
            print(e)

        return False


class BaseBinder(Base):
    """Represents any element under <bindings> : <select>,<insert>,<update>,<delete> and <function>
    """
    def __init__(self, name, **kwargs):
        """
        """
        self.name = name
        vars(self).update(kwargs)

        self.etree = self._buildElementTree()

        if self.urls:
            [ self.addUrl(url) for url in self.urls ]

        if self.inputs:
            [ self.addInput(elt) for elt in self.inputs ]

        if self.paging:
            self.addPaging(self.paging)
        
    def _buildElementTree(self,):
        """Turns object into a Element Tree
        """
        t_binder = ctree.Element(self.name)

        for k,v in self.__dict__.items():
            if k not in ('name', 'urls', 'inputs', 'paging') and v :
                t_binder.set(k,v)

        self.etree = t_binder
        return t_binder

    def addUrl(self, url):
        """Add url to binder
        """

        if not url in self.urls:
            self.urls.append(url)

        root = self.etree
        t_urls = root.find('urls')

        if not t_urls:
            t_urls = ctree.SubElement(root, 'urls')

        t_url = ctree.SubElement(t_urls, 'url')
        t_url.text = url

        return True

    def removeUrl(self, url):
        """Remove passed url from a binder
        """

        root = self.etree
        t_urls = root.find('urls')

        if not t_urls:
            return False

        for t_url in t_urls.findall('url'):
            if t_url.text == url.strip():
                t_urls.remove(t_url)
                if url in self.urls:
                    self.urls.remove(url)
                return True

        return False

    def addInput(self, key):
        """Add key to input : key, value or map
        """
        if not key in self.inputs:
            self.inputs.append(key)

        root = self.etree
        t_inputs = root.find('inputs')

        if not t_inputs :
            t_inputs = ctree.SubElement(root, 'inputs')

        t_inputs.append(key.etree)

        return True

    def removeInput(self, key_id, input_type='key'):
        """Remove key (key, value, map) from Input
        key_id : id of the input element i.e <key id='artist' />
        input_type : type of the input ; key, value or map
        """
        root = self.etree
        t_inputs = root.find('inputs')

        if not t_inputs:
            return False

        keys = t_inputs.findall(input_type)

        key = [ key for key in keys if key.get('id') == key_id ]

        try:
            t_inputs.remove(key[0])
            return True
        except Exception,e:
            print(e)

        return False

    def addPaging(self,paging):
        """Add paging to Binder
        """
        if not self.paging:
            self.paging = paging
        root = self.etree

        try:
            root.append(paging.etree)
            return True
        except Exception,e:
            print(e)

        return False

    def removePaging(self,):
{'fraction_non_alphanumeric': 0.10648311566066596, 'fraction_numerical': 0.0011766090128250382, 'mean_word_length': 1.5875190258751903, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '784372', 'n_tokens_mistral': 2629, 'n_tokens_neox': 2553, 'n_words': 644}