MCPcopy Index your code
hub / github.com/python/cpython / IdleUserConfParser

Class IdleUserConfParser

Lib/idlelib/config.py:79–143  ·  view source on GitHub ↗

IdleConfigParser specialised for user configuration handling.

Source from the content-addressed store, hash-verified

77 self.read(self.file)
78
79class IdleUserConfParser(IdleConfParser):
80 """
81 IdleConfigParser specialised for user configuration handling.
82 """
83
84 def SetOption(self, section, option, value):
85 """Return True if option is added or changed to value, else False.
86
87 Add section if required. False means option already had value.
88 """
89 if self.has_option(section, option):
90 if self.get(section, option) == value:
91 return False
92 else:
93 self.set(section, option, value)
94 return True
95 else:
96 if not self.has_section(section):
97 self.add_section(section)
98 self.set(section, option, value)
99 return True
100
101 def RemoveOption(self, section, option):
102 """Return True if option is removed from section, else False.
103
104 False if either section does not exist or did not have option.
105 """
106 if self.has_section(section):
107 return self.remove_option(section, option)
108 return False
109
110 def AddSection(self, section):
111 "If section doesn't exist, add it."
112 if not self.has_section(section):
113 self.add_section(section)
114
115 def RemoveEmptySections(self):
116 "Remove any sections that have no options."
117 for section in self.sections():
118 if not self.GetOptionList(section):
119 self.remove_section(section)
120
121 def IsEmpty(self):
122 "Return True if no sections after removing empty sections."
123 self.RemoveEmptySections()
124 return not self.sections()
125
126 def Save(self):
127 """Update user configuration file.
128
129 If self not empty after removing empty sections, write the file
130 to disk. Otherwise, remove the file from disk if it exists.
131 """
132 fname = self.file
133 if fname and fname[0] != '#':
134 if not self.IsEmpty():
135 try:
136 cfgFile = open(fname, 'w')

Callers 1

CreateConfigHandlersMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…