Пример #1
0
    def convert_query(self, query):
        result = ''
        base = self.base

        #convert objectClass first, as it is indexed (most of the time)
        try:
            result = self.convert_query_element('objectClass', query['objectClass'])
    
            del query['objectClass']
            
        except KeyError:
            #We don't care about objectClass, unusual but valid
            pass
            
        #Then metadata
        #each in its own try except block
        #first the rdn
        try:
            rdn = query['mongolito.rdn']
            #FIXME : What if cn is not used (or replaced with uid?)
            result += '(cn={0})'.format(utils.simple_pattern_from_javascript(rdn))
            del query['mongolito.rdn']
        except KeyError:
            pass

        #then the path
        try:
            path = query['mongolito.parent']
            #We are replacing the base
            #Look at something along those lines
            #http://stackoverflow.com/a/14128905/591064
            #For now, we just use the path as the base (which we must flip). We also
            #ignore the leading ^, if present
            base = utils.reverse_path(utils.pattern_from_javascript(path).lstrip('^'))
            del query['mongolito.parent']
        except KeyError:
            pass

        try:
            path = query['mongolito.path']
            #We are replacing the base
            #Look at something along those lines
            #http://stackoverflow.com/a/14128905/591064
            #For now, we just use the path as the base (which we must flip). We also
            #ignore the leading ^, if present
            base = utils.pattern_from_javascript(path).lstrip('^')
            del query['mongolito.path']
        except KeyError:
            pass

        #Convert other attributes
        for k, v in query.items():
            result += self.convert_query_element(k, v)
            
        return base, '(&{0})'.format(result)
Пример #2
0
    def __init__(self, attribute):
        '''
        >>>remover = RemoveAttribute('logintime')

        :attribute the name (or regex) of the attribute from which a value must be removed
        '''
        self.pattern = re.compile(utils.pattern_from_javascript(attribute), flags=re.IGNORECASE)
Пример #3
0
    def __init__(self, attribute, pattern, change):
        '''
        >>>case_changer = ChangeCase('dn', '/cn=([a-z]{2}).*/', ChangeCase.UPPER)

        :attribute the name of the attribute from which a value must be removed
        '''
        self.attribute = attribute
        self.pattern = re.compile(utils.pattern_from_javascript(pattern))
        self.change = change
Пример #4
0
    def __init__(self, attribute, pattern, replacement):
        '''
        >>>renamer = RenameValue('dn', '/.*ou=AAA.*/', r'\1ou=BBB\2')

        :attribute the name of the attribute from which a value must be removed
        '''
        self.attribute = attribute
        self.pattern = re.compile(utils.pattern_from_javascript(pattern), flags=re.IGNORECASE)
        self.replacement = replacement
Пример #5
0
    def __init__(self, attribute, value):
        '''
        >>>remover = RemoveValue('objectClass', 'irrelevant')
        >>>remover = RemoveValue('objectClass', '/^irrelevant.*expression$/')

        :attribute the name of the attribute from which a value must be removed
        :value the value to be removed. Can be a regular expression enclosed in //
        '''
        self.attribute = attribute
        self.pattern = re.compile(utils.pattern_from_javascript(value), flags=re.IGNORECASE)
Пример #6
0
    def __init__(self, attribute, pattern, query, source, cache=False, selected='dn', deleteIfEmpty=True, keepMissedSearches=False):
        '''
        '''
        self.attribute = attribute
        self.pattern = re.compile(utils.pattern_from_javascript(pattern), flags=re.IGNORECASE)
        self.query = query
        self.source = source
        self.selected = selected
        self.deleteIfEmpty = deleteIfEmpty 
        self.keepMissedSearches = keepMissedSearches

        self.cache_enabled = False  #Cache default is OFF
        self.cache = {}
        
        #Reusing an external cache is better
        if isinstance(cache, dict):
            self.cache_enabled = True
            self.cache = cache
        elif cache:
            self.cache_enabled = True

        self.cache['__hits'] = self.cache.get('__hits', 0)
        self.cache['__miss'] = self.cache.get('__miss', 0)