소스 검색

Group read methods together and explain overrides

Mike Naberezny 9 년 전
부모
커밋
b14c32d7f0
1개의 변경된 파일26개의 추가작업 그리고 16개의 파일을 삭제
  1. 26 16
      supervisor/options.py

+ 26 - 16
supervisor/options.py

@@ -1682,9 +1682,14 @@ class UnhosedConfigParser(ConfigParser.RawConfigParser):
     mysection = 'supervisord'
 
     def __init__(self, *args, **kwargs):
+        # inline_comment_prefixes was added in Python 3 but its default makes
+        # RawConfigParser behave differently than it did on Python 2.  This
+        # makes it behave the same by default on Python 2 and 3.
         if PY3 and ('inline_comment_prefixes' not in kwargs):
             kwargs['inline_comment_prefixes'] = (';', '#')
+
         ConfigParser.RawConfigParser.__init__(self, *args, **kwargs)
+
         self.section_to_file = {}
         self.expansions = {}
 
@@ -1697,6 +1702,27 @@ class UnhosedConfigParser(ConfigParser.RawConfigParser):
         except AttributeError:
             return self.readfp(StringIO(string))
 
+    def read(self, filenames, **kwargs):
+        '''Attempt to read and parse a list of filenames, returning a list
+        of filenames which were successfully parsed.  This is a method of
+        RawConfigParser that is overridden to build self.section_to_file,
+        which is a mapping of section names to the files they came from.
+        '''
+        if isinstance(filenames, basestring):  # RawConfigParser compat
+            filenames = [filenames]
+
+        ok_filenames = []
+        for filename in filenames:
+            sections_orig = self._sections.copy()
+
+            ok_filenames.extend(
+                ConfigParser.RawConfigParser.read(self, [filename], **kwargs))
+
+            diff = frozenset(self._sections) - frozenset(sections_orig)
+            for section in diff:
+                self.section_to_file[section] = filename
+        return ok_filenames
+
     def saneget(self, section, option, default=_marker, do_expand=True,
                 expansions={}):
         try:
@@ -1720,22 +1746,6 @@ class UnhosedConfigParser(ConfigParser.RawConfigParser):
         return self.saneget(self.mysection, option, default=default,
                             expansions=expansions, **kwargs)
 
-    def read(self, filenames, **kwargs):
-        if isinstance(filenames, basestring):  # RawConfigParser compat
-            filenames = [filenames]
-
-        ok_filenames = []
-        for filename in filenames:
-            sections_orig = self._sections.copy()
-
-            ok_filenames.extend(
-                ConfigParser.RawConfigParser.read(self, [filename], **kwargs))
-
-            diff = frozenset(self._sections) - frozenset(sections_orig)
-            for section in diff:
-                self.section_to_file[section] = filename
-        return ok_filenames
-
     def expand_here(self, here):
         if here is None:
             return