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)
def testReversePath(self): self.assertEqual('ou=stuff,dc=example,dc=com', utils.reverse_path('DC=com,DC=example,OU=stuff')) self.assertEqual('dc=com', utils.reverse_path('DC=COM'))