def matchFlagsFromJSON(json): if json == "{}": return MatchFlags.none if json.startswith("{") and json.endswith("}"): # Composite flags: "{A,B,C,...}" flags = MatchFlags.none for flag in json[1:-1].split(","): flags |= MatchFlags.lookupByName(flag) return flags return MatchFlags.lookupByName(json)
def recordsMatchingFields(self, fields, operand="OR", recordType=None, limitResults=None, timeoutSeconds=None): log.debug("RecordsMatchingFields") newFields = [] for fieldName, searchTerm, matchFlags, matchType in fields: fieldName = fieldName.decode("utf-8") searchTerm = searchTerm.decode("utf-8") try: field = self._directory.fieldName.lookupByName(fieldName) except ValueError: field = None if field: valueType = self._directory.fieldName.valueType(field) if valueType is uuid.UUID: searchTerm = uuid.UUID(searchTerm) matchFlags = matchFlags.decode("utf-8") if matchFlags.startswith("{") and matchFlags.endswith("}"): flags = MatchFlags.none for flag in matchFlags[1:-1].split(","): flags |= MatchFlags.lookupByName(flag) matchFlags = flags else: matchFlags = MatchFlags.lookupByName(matchFlags) matchType = MatchType.lookupByName(matchType.decode("utf-8")) newFields.append((fieldName, searchTerm, matchFlags, matchType)) operand = Operand.lookupByName(operand) if recordType: recordType = self._directory.recordType.lookupByName(recordType) records = yield self._directory.recordsMatchingFields( newFields, operand=operand, recordType=recordType, limitResults=limitResults, timeoutSeconds=timeoutSeconds) response = self._recordsToResponse(records) # log.debug("Responding with: {response}", response=response) returnValue(response)
def recordsMatchingFields( self, fields, operand="OR", recordType=None, limitResults=None, timeoutSeconds=None ): log.debug("RecordsMatchingFields") newFields = [] for fieldName, searchTerm, matchFlags, matchType in fields: fieldName = fieldName.decode("utf-8") searchTerm = searchTerm.decode("utf-8") try: field = self._directory.fieldName.lookupByName(fieldName) except ValueError: field = None if field: valueType = self._directory.fieldName.valueType(field) if valueType is uuid.UUID: searchTerm = uuid.UUID(searchTerm) matchFlags = matchFlags.decode("utf-8") if matchFlags.startswith("{") and matchFlags.endswith("}"): flags = MatchFlags.none for flag in matchFlags[1:-1].split(","): flags |= MatchFlags.lookupByName(flag) matchFlags = flags else: matchFlags = MatchFlags.lookupByName(matchFlags) matchType = MatchType.lookupByName(matchType.decode("utf-8")) newFields.append((fieldName, searchTerm, matchFlags, matchType)) operand = Operand.lookupByName(operand) if recordType: recordType = self._directory.recordType.lookupByName(recordType) records = yield self._directory.recordsMatchingFields( newFields, operand=operand, recordType=recordType, limitResults=limitResults, timeoutSeconds=timeoutSeconds ) response = self._recordsToResponse(records) # log.debug("Responding with: {response}", response=response) returnValue(response)