Beispiel #1
0
  def parse(self):
    """
    Continously read and parse LDIF records
    """
    self._line = self._input_file.readline()

    while self._line and \
          (not self._max_entries or self.records_read<self._max_entries):

      # Reset record
      version = None; dn = None; changetype = None; modop = None; entry = {}

      if self._line == '-\n': # will return None,None
        attr_type,attr_value = self._parseAttrTypeandValue()
      attr_type,attr_value = self._parseAttrTypeandValue()

      while attr_type!=None and attr_value!=None:
        if attr_type=='dn':
          # attr type and value pair was DN of LDIF record
          if dn!=None:
            raise ValueError, 'Two lines starting with dn: in one record.'
          if not ldif.is_dn(attr_value):
            raise ValueError, 'No valid string-representation of distinguished name %s.' % (repr(attr_value))
          dn = attr_value
        elif attr_type=='version' and dn is None:
          version = 1
        elif attr_type=='changetype':
          # attr type and value pair was DN of LDIF record
          if changetype!=None:
            raise ValueError, 'Two lines starting with changetype: in one record.'
          if not ldif.valid_changetype_dict.has_key(attr_value):
            raise ValueError, 'changetype value %s is invalid.' % (repr(attr_value))
          # Add the attribute to the entry if not ignored attribute
          if entry.has_key(attr_type):
            entry[attr_type].append(attr_value)
          else:
            entry[attr_type]=[attr_value]
        elif attr_value!=None and \
             not self._ignored_attr_types.has_key(string.lower(attr_type)):
          # Add the attribute to the entry if not ignored attribute
          if entry.has_key(attr_type):
            entry[attr_type].append(attr_value)
          else:
            entry[attr_type]=[attr_value]

        # Read the next line within an entry
        if self._line == '-\n': # will return None,None
          attr_type,attr_value = self._parseAttrTypeandValue()
        attr_type,attr_value = self._parseAttrTypeandValue()

      if entry:
        # append entry to result list
        self.handle(dn,entry)
        self.records_read = self.records_read+1

    return # parse()
Beispiel #2
0
  def parse(self):
    """
    Continously read and parse LDIF records
    """
    self._line = self._input_file.readline()

    while self._line and \
          (not self._max_entries or self.records_read<self._max_entries):

      # Reset record
      version = None; dn = None; changetype = None; modop = None; entry = {};

      attr_type,attr_value = self._parseAttrTypeandValue()

      while attr_type!=None and attr_value!=None:
        if attr_type=='dn':
          # attr type and value pair was DN of LDIF record
          if dn!=None:
            raise ValueError, 'Two lines starting with dn: in one record.'
          if not is_dn(attr_value):
            raise ValueError, 'No valid string-representation of distinguished name %s.' % (repr(attr_value))
          dn = attr_value
        elif attr_type=='version' and dn is None:
          version = 1
        elif attr_type=='changetype':
          # attr type and value pair was DN of LDIF record
          if dn is None:
            raise ValueError, 'Read changetype: before getting valid dn: line.'
          if changetype!=None:
            raise ValueError, 'Two lines starting with changetype: in one record.'
          if not valid_changetype_dict.has_key(attr_value):
            raise ValueError, 'changetype value %s is invalid.' % (repr(attr_value))
          changetype = attr_value
          attr_type, attr_value = self._parseAttrTypeandValue()
          modify_list = []
          entry[changetype] = []
          while (attr_type and attr_value) is not None:
            mod_op = MODIFY_MAPPING_DICT[attr_type]
            mod_type = attr_value
            multivalued_list = []
            while attr_value is not None:
              attr_type, attr_value = self._parseAttrTypeandValue()
              if attr_value is not None:
                multivalued_list.append(attr_value)
            modify_list.append((mod_op, mod_type, multivalued_list))
            entry[changetype] = [modify_list]
            attr_type, attr_value = self._parseAttrTypeandValue()
          #don't add new entry for the same dn
          break
        elif attr_value not in (None, '') and \
             not self._ignored_attr_types.has_key(string.lower(attr_type)):
          # Add the attribute to the entry if not ignored attribute
          if entry.has_key(attr_type):
            entry[attr_type].append(attr_value)
          else:
            entry[attr_type]=[attr_value]

        # Read the next line within an entry
        attr_type, attr_value = self._parseAttrTypeandValue()

      if entry:
        # append entry to result list
        self.handle(dn, entry)
        self.records_read = self.records_read+1

    return # parse()
Beispiel #3
0
    def parse(self):
        """
    Continously read and parse LDIF records
    """
        self._line = self._input_file.readline()

        while self._line and \
              (not self._max_entries or self.records_read<self._max_entries):

            # Reset record
            version = None
            dn = None
            changetype = None
            modop = None
            entry = {}

            attr_type, attr_value = self._parseAttrTypeandValue()

            while attr_type != None and attr_value != None:
                if attr_type == 'dn':
                    # attr type and value pair was DN of LDIF record
                    if dn != None:
                        raise ValueError, 'Two lines starting with dn: in one record.'
                    if not is_dn(attr_value):
                        raise ValueError, 'No valid string-representation of distinguished name %s.' % (
                            repr(attr_value))
                    dn = attr_value
                elif attr_type == 'version' and dn is None:
                    version = 1
                elif attr_type == 'changetype':
                    # attr type and value pair was DN of LDIF record
                    if dn is None:
                        raise ValueError, 'Read changetype: before getting valid dn: line.'
                    if changetype != None:
                        raise ValueError, 'Two lines starting with changetype: in one record.'
                    if not valid_changetype_dict.has_key(attr_value):
                        raise ValueError, 'changetype value %s is invalid.' % (
                            repr(attr_value))
                    changetype = attr_value
                    attr_type, attr_value = self._parseAttrTypeandValue()
                    modify_list = []
                    entry[changetype] = []
                    while (attr_type and attr_value) is not None:
                        mod_op = MODIFY_MAPPING_DICT[attr_type]
                        mod_type = attr_value
                        multivalued_list = []
                        while attr_value is not None:
                            attr_type, attr_value = self._parseAttrTypeandValue(
                            )
                            if attr_value is not None:
                                multivalued_list.append(attr_value)
                        modify_list.append(
                            (mod_op, mod_type, multivalued_list))
                        entry[changetype] = [modify_list]
                        attr_type, attr_value = self._parseAttrTypeandValue()
                    #don't add new entry for the same dn
                    break
                elif attr_value not in (None, '') and \
                     not self._ignored_attr_types.has_key(string.lower(attr_type)):
                    # Add the attribute to the entry if not ignored attribute
                    if entry.has_key(attr_type):
                        entry[attr_type].append(attr_value)
                    else:
                        entry[attr_type] = [attr_value]

                # Read the next line within an entry
                attr_type, attr_value = self._parseAttrTypeandValue()

            if entry:
                # append entry to result list
                self.handle(dn, entry)
                self.records_read = self.records_read + 1

        return  # parse()
Beispiel #4
0
    def parse(self):
        """
    Continously read and parse LDIF records
    """
        self._line = self._input_file.readline()

        while self._line and \
              (not self._max_entries or self.records_read<self._max_entries):

            # Reset record
            version = None
            dn = None
            changetype = None
            modop = None
            entry = {}

            if self._line == '-\n':  # will return None,None
                attr_type, attr_value = self._parseAttrTypeandValue()
            attr_type, attr_value = self._parseAttrTypeandValue()

            while attr_type != None and attr_value != None:
                if attr_type == 'dn':
                    # attr type and value pair was DN of LDIF record
                    if dn != None:
                        raise ValueError, 'Two lines starting with dn: in one record.'
                    if not ldif.is_dn(attr_value):
                        raise ValueError, 'No valid string-representation of distinguished name %s.' % (
                            repr(attr_value))
                    dn = attr_value
                elif attr_type == 'version' and dn is None:
                    version = 1
                elif attr_type == 'changetype':
                    # attr type and value pair was DN of LDIF record
                    if changetype != None:
                        raise ValueError, 'Two lines starting with changetype: in one record.'
                    if not ldif.valid_changetype_dict.has_key(attr_value):
                        raise ValueError, 'changetype value %s is invalid.' % (
                            repr(attr_value))
                    # Add the attribute to the entry if not ignored attribute
                    if entry.has_key(attr_type):
                        entry[attr_type].append(attr_value)
                    else:
                        entry[attr_type] = [attr_value]
                elif attr_value!=None and \
                     not self._ignored_attr_types.has_key(string.lower(attr_type)):
                    # Add the attribute to the entry if not ignored attribute
                    if entry.has_key(attr_type):
                        entry[attr_type].append(attr_value)
                    else:
                        entry[attr_type] = [attr_value]

                # Read the next line within an entry
                if self._line == '-\n':  # will return None,None
                    attr_type, attr_value = self._parseAttrTypeandValue()
                attr_type, attr_value = self._parseAttrTypeandValue()

            if entry:
                # append entry to result list
                self.handle(dn, entry)
                self.records_read = self.records_read + 1

        return  # parse()