瀏覽代碼

Move stripEscapes into a function.

Chris McDonough 17 年之前
父節點
當前提交
ac82b51328
共有 3 個文件被更改,包括 28 次插入33 次删除
  1. 28 2
      src/supervisor/dispatchers.py
  2. 0 26
      src/supervisor/options.py
  3. 0 5
      src/supervisor/tests/base.py

+ 28 - 2
src/supervisor/dispatchers.py

@@ -129,7 +129,7 @@ class POutputDispatcher(PDispatcher):
         if data:
             config = self.process.config
             if config.options.strip_ansi:
-                data = config.options.stripEscapes(data)
+                data = stripEscapes(data)
             if self.childlog:
                 self.childlog.info(data)
             if self.log_to_mainlog:
@@ -282,7 +282,7 @@ class PEventListenerDispatcher(PDispatcher):
 
             if self.childlog:
                 if self.process.config.options.strip_ansi:
-                    data = self.process.config.options.stripEscapes(data)
+                    data = stripEscapes(data)
                 self.childlog.info(data)
         else:
             # if we get no data back from the pipe, it means that the
@@ -408,3 +408,29 @@ class PInputDispatcher(PDispatcher):
                 else:
                     raise
 
+ANSI_ESCAPE_BEGIN = '\x1b['
+ANSI_TERMINATORS = ('H', 'f', 'A', 'B', 'C', 'D', 'R', 's', 'u', 'J', 
+                    'K', 'h', 'l', 'p', 'm')    
+    
+def stripEscapes(string):
+    """
+    Remove all ANSI color escapes from the given string.
+    """
+    result = ''
+    show = 1
+    i = 0
+    L = len(string)
+    while i < L:
+        if show == 0 and string[i] in ANSI_TERMINATORS:
+            show = 1
+        elif show:
+            n = string.find(ANSI_ESCAPE_BEGIN, i)
+            if n == -1:
+                return result + string[i:]
+            else:
+                result = result + string[i:n]
+                i = n
+                show = 0
+        i = i + 1
+    return result
+

+ 0 - 26
src/supervisor/options.py

@@ -360,10 +360,6 @@ class ServerOptions(Options):
     unlink_socketfiles = True
     mood = states.SupervisorStates.RUNNING
     
-    ANSI_ESCAPE_BEGIN = '\x1b['
-    ANSI_TERMINATORS = ('H', 'f', 'A', 'B', 'C', 'D', 'R', 's', 'u', 'J', 
-                        'K', 'h', 'l', 'p', 'm')    
-    
     def __init__(self):
         Options.__init__(self)
         self.configroot = Dummy()
@@ -1012,28 +1008,6 @@ class ServerOptions(Options):
             return 'Could not set group id of effective user'
         os.setuid(uid)
 
-    def stripEscapes(self, string):
-        """
-        Remove all ANSI color escapes from the given string.
-        """
-        result = ''
-        show = 1
-        i = 0
-        L = len(string)
-        while i < L:
-            if show == 0 and string[i] in self.ANSI_TERMINATORS:
-                show = 1
-            elif show:
-                n = string.find(self.ANSI_ESCAPE_BEGIN, i)
-                if n == -1:
-                    return result + string[i:]
-                else:
-                    result = result + string[i:n]
-                    i = n
-                    show = 0
-            i = i + 1
-        return result
-
     def waitpid(self):
         # need pthread_sigmask here to avoid concurrent sigchild, but
         # Python doesn't offer it as it's not standard across UNIX versions.

+ 0 - 5
src/supervisor/tests/base.py

@@ -205,11 +205,6 @@ class DummyOptions:
     def process_environment(self):
         self.environment_processed = True
 
-    def stripEscapes(self, data):
-        from supervisor.options import ServerOptions
-        o = ServerOptions()
-        return o.stripEscapes(data)
-
     def mktempfile(self, prefix, suffix, dir):
         return self.tempfile_name