|  | @@ -2,40 +2,16 @@ import textwrap
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  from .exception import pini_exception
 | 
	
		
			
				|  |  |  from .key import key
 | 
	
		
			
				|  |  | +from .line import line
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -class section:
 | 
	
		
			
				|  |  | +class section(line):
 | 
	
		
			
				|  |  |      def __init__(self):
 | 
	
		
			
				|  |  | -        self.__name: str | None = None
 | 
	
		
			
				|  |  | -        self.__comment: str | None = None    
 | 
	
		
			
				|  |  | +        super().__init__()
 | 
	
		
			
				|  |  |          self.__keys: list[key] = list()
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @property
 | 
	
		
			
				|  |  |      def is_global(self) -> bool:
 | 
	
		
			
				|  |  | -        return self.__name is None
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    @property
 | 
	
		
			
				|  |  | -    def name(self) -> str | None:
 | 
	
		
			
				|  |  | -        return self.__name
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    @name.setter
 | 
	
		
			
				|  |  | -    def name(self, target: str | None) -> None:
 | 
	
		
			
				|  |  | -        if type(target) is str:
 | 
	
		
			
				|  |  | -            target = target.strip()
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        if type(target) is not str and target is not None:
 | 
	
		
			
				|  |  | -            raise TypeError("Section name must be str, or None for global.")
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        self.__name = target
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    @property 
 | 
	
		
			
				|  |  | -    def comment(self) -> str | None:
 | 
	
		
			
				|  |  | -        return self.__comment
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    def add_comment(self, content: str) -> None:
 | 
	
		
			
				|  |  | -        if self.__comment is None:
 | 
	
		
			
				|  |  | -            self.__comment = ""
 | 
	
		
			
				|  |  | -        
 | 
	
		
			
				|  |  | -        self.__comment = self.__comment + content
 | 
	
		
			
				|  |  | +        return self.name is None
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      def get(self, target: str) -> key | None:
 | 
	
		
			
				|  |  |          if type(target) is not str:
 | 
	
	
		
			
				|  | @@ -44,7 +20,7 @@ class section:
 | 
	
		
			
				|  |  |          target.strip()
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          if len(target) == 0:
 | 
	
		
			
				|  |  | -            raise TypeError("Ket name to get can not be empty.")
 | 
	
		
			
				|  |  | +            raise TypeError("Key name to get can not be empty.")
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          for count in self.__keys:
 | 
	
		
			
				|  |  |              if count.name == target:
 | 
	
	
		
			
				|  | @@ -55,7 +31,21 @@ class section:
 | 
	
		
			
				|  |  |      def exists(self, target: str) -> bool:
 | 
	
		
			
				|  |  |          return self.get(target) is not None
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    def add_key(self, target: key) -> None:
 | 
	
		
			
				|  |  | +    def drop(self, target: key | str) -> key | None:
 | 
	
		
			
				|  |  | +        if type(target) is key:
 | 
	
		
			
				|  |  | +            target = target.name
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        index = -1
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        for count in range(len(self.__keys)):
 | 
	
		
			
				|  |  | +            if self.__keys[count].name == target:
 | 
	
		
			
				|  |  | +                index = count
 | 
	
		
			
				|  |  | +                break
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if index != -1:
 | 
	
		
			
				|  |  | +            return self.__keys.pop(index)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    def add(self, target: key) -> None:
 | 
	
		
			
				|  |  |          if type(target) is not key:
 | 
	
		
			
				|  |  |              raise TypeError("New key must be instance of key.")
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -66,17 +56,17 @@ class section:
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |              raise pini_exception(error)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        self.__keys.append(target)
 | 
	
		
			
				|  |  | +        self.__keys.append(target.clone())
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    def __str__(self) -> str:
 | 
	
		
			
				|  |  | +    def render(self) -> str:
 | 
	
		
			
				|  |  |          content = ""
 | 
	
		
			
				|  |  |          comments = list()
 | 
	
		
			
				|  |  |          
 | 
	
		
			
				|  |  | -        if self.__name is not None:
 | 
	
		
			
				|  |  | -            content = "[" + self.__name + "]\n"
 | 
	
		
			
				|  |  | +        if self.name is not None:
 | 
	
		
			
				|  |  | +            content = "[" + self.name + "]\n"
 | 
	
		
			
				|  |  |          
 | 
	
		
			
				|  |  | -        if self.__comment is not None:
 | 
	
		
			
				|  |  | -            comments = textwrap.wrap(self.__comment, 77)
 | 
	
		
			
				|  |  | +        if self.comment is not None:
 | 
	
		
			
				|  |  | +            comments = textwrap.wrap(self.comment, 77)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          for count in comments:
 | 
	
		
			
				|  |  |              content = content + "# " + count + "\n"
 |