<commit_before>import os 

from agx.core import (
    handler,
    Scope,
    registerScope,
    token
)
from node.ext.zcml import ZCMLNode
from node.ext.zcml import ZCMLFile
from node.ext.zcml import SimpleDirective
from node.ext.zcml import ComplexDirective
from node.ext.uml.utils import TaggedValues, UNSET


confname = 'configure.zcml'

def relpath(self,other):
    assert self.path == other.path[:len(self.path)], \
           'other must be a subpath of self'
    return '/'.join(other.path[len(self.path):])


def addZcmlRef(directory, zcml):
    """Adds a reference to a zcml file and implicitly taks care for creating 
    a configure.zcml"""
    # zcmls zamsammeln, um zu wissen, was vom configure.zcml includiert 
    # werden soll
    path = directory.path
    path.append(confname)
    #fullpath = os.path.join(*path)
    if confname not in directory.keys():
        #conf = ZCMLFile(fullpath)
        conf = ZCMLFile()
        directory[confname] = conf
    else:
        conf = directory[confname]

    zcmlpath = relpath(directory,zcml)
    if zcmlpath!='configure.zcml':
#        import pdb;pdb.set_trace()
        
        if zcml.name=='configure.zcml':
            packname='.'+directory.name
            found_include = conf.filter(tag='include', attr='package', 
                                        value=packname)
            #add include directive if necessary
            if not found_include:
                include = SimpleDirective(name='include', parent=conf)
                include.attrs['package'] = packname
        else:
            found_include = conf.filter(tag='include', attr='file', 
                                        value=zcmlpath)
            #add include directive if necessary
            if not found_include:
                include = SimpleDirective(name='include', parent=conf)
                include.attrs['file'] = zcmlpath

        
    if directory not in token('pyeggs',False).directories:
        parentdir = directory.__parent__
        addZcmlRef(parentdir, conf)

def get_zcml(directory,zcmlname):
    directory.factories['.zcml']=ZCMLFile
    if not zcmlname in directory:
        new=ZCMLFile()
        directory[zcmlname]=new
        res=new
    else:
        res=directory[zcmlname]
    return res

def set_zcml_namespace(directory,zcmlname,nsid,nspath):
    zcml=get_zcml(directory,zcmlname)
    zcml.nsmap[nsid]=nspath
    
def set_zcml_directive(directory,zcmlname,tag,attr,value,**kw):
    zcml=get_zcml(directory,zcmlname)<commit_msg>nsmap parameter<commit_after>import os 

from agx.core import (
    handler,
    Scope,
    registerScope,
    token
)
from node.ext.zcml import ZCMLNode
from node.ext.zcml import ZCMLFile
from node.ext.zcml import SimpleDirective
from node.ext.zcml import ComplexDirective
from node.ext.uml.utils import TaggedValues, UNSET


confname = 'configure.zcml'

def relpath(self,other):
    assert self.path == other.path[:len(self.path)], \
           'other must be a subpath of self'
    return '/'.join(other.path[len(self.path):])


def addZcmlRef(directory, zcml):
    """Adds a reference to a zcml file and implicitly taks care for creating 
    a configure.zcml"""
    # zcmls zamsammeln, um zu wissen, was vom configure.zcml includiert 
    # werden soll
    path = directory.path
    path.append(confname)
    #fullpath = os.path.join(*path)
    if confname not in directory.keys():
        #conf = ZCMLFile(fullpath)
        conf = ZCMLFile()
        directory[confname] = conf
    else:
        conf = directory[confname]

    zcmlpath = relpath(directory,zcml)
    if zcmlpath!='configure.zcml':
#        import pdb;pdb.set_trace()
        
        if zcml.name=='configure.zcml':
            packname='.'+directory.name
            found_include = conf.filter(tag='include', attr='package', 
                                        value=packname)
            #add include directive if necessary
            if not found_include:
                include = SimpleDirective(name='include', parent=conf)
                include.attrs['package'] = packname
        else:
            found_include = conf.filter(tag='include', attr='file', 
                                        value=zcmlpath)
            #add include directive if necessary
            if not found_include:
                include = SimpleDirective(name='include', parent=conf)
                include.attrs['file'] = zcmlpath

        
    if directory not in token('pyeggs',False).directories:
        parentdir = directory.__parent__
        addZcmlRef(parentdir, conf)

def get_zcml(directory,zcmlname,nsmap=None):
    directory.factories['.zcml']=ZCMLFile
    if not zcmlname in directory:
        if nsmap:
            new=ZCMLFile(nsmap=nsmap)
        else:
            new=ZCMLFile()
        directory[zcmlname]=new
        res=new
    else:
        res=directory[zcmlname]
    return res

def set_zcml_namespace(directory,zcmlname,nsid,nspath):
    zcml=get_zcml(directory,zcmlname)
    zcml.nsmap['plone']='http://namespaces.plone.org/plone'
    zcml.nsmap[nsid]=nspath
    
def set_zcml_directive(directory,zcmlname,tag,attr,value,**kw):
    zcml=get_zcml(directory,zcmlname)
{'fraction_non_alphanumeric': 0.10164251207729469, 'fraction_numerical': 0.0, 'mean_word_length': 2.5091525423728815, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '338303', 'n_tokens_mistral': 1671, 'n_tokens_neox': 1575, 'n_words': 343}