<commit_before>from sfa.rspecs.elements.element import Element
from sfa.rspecs.elements.sliver import Sliver

class PGv2SliverType:

    @staticmethod
    def add_slivers(xml, sliver):
        if not slivers:
            return 
        if not isinstance(slivers, list):
            slivers = [slivers]
        for sliver in slivers: 
            sliver_elem = Element.add(xml, 'sliver_type', sliver, ['type', 'client_id'])
            PGv2Sliver.add_sliver_attributes(sliver_elem, sliver.get('pl_tags', []))
    
    @staticmethod
    def add_sliver_attributes(xml, attributes):
        for attribute in attributes:
            if attribute['name'] == 'initscript':
                xml.add_element('{%s}initscript' % xml.namespaces['planetlab'], name=attribute['value'])
            elif tag['tagname'] == 'flack_info':
                attrib_elem = xml.add_element('{%s}info' % self.namespaces['flack'])
                attrib_dict = eval(tag['value'])
                for (key, value) in attrib_dict.items():
                    attrib_elem.set(key, value)                <commit_msg>fix add_slivers<commit_after>from sfa.rspecs.elements.element import Element
from sfa.rspecs.elements.sliver import Sliver

class PGv2SliverType:

    @staticmethod
    def add_slivers(xml, slivers):
        if not slivers:
            return 
        if not isinstance(slivers, list):
            slivers = [slivers]
        for sliver in slivers: 
            sliver_elem = Element.add_elements(xml, 'sliver_type', sliver, ['type', 'client_id'])
            PGv2SliverType.add_sliver_attributes(sliver_elem, sliver.get('pl_tags', []))
    
    @staticmethod
    def add_sliver_attributes(xml, attributes):
        for attribute in attributes:
            if attribute['name'] == 'initscript':
                xml.add_element('{%s}initscript' % xml.namespaces['planetlab'], name=attribute['value'])
            elif tag['tagname'] == 'flack_info':
                attrib_elem = xml.add_element('{%s}info' % self.namespaces['flack'])
                attrib_dict = eval(tag['value'])
                for (key, value) in attrib_dict.items():
                    attrib_elem.set(key, value)                
{'fraction_non_alphanumeric': 0.1178082191780822, 'fraction_numerical': 0.0018264840182648401, 'mean_word_length': 2.4449685534591197, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, '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': '1452048', 'n_tokens_mistral': 676, 'n_tokens_neox': 662, 'n_words': 131}