[tor-commits] [flashproxy/master] Move catch_epipe to fac.py.

dcf at torproject.org dcf at torproject.org
Thu Mar 7 09:17:35 UTC 2013


commit 6701af88e5879850a3401b343e0bb8187210057b
Author: David Fifield <david at bamsoftware.com>
Date:   Wed Mar 6 22:56:55 2013 -0800

    Move catch_epipe to fac.py.
---
 facilitator/fac.py      |   18 ++++++++++++++++++
 facilitator/facilitator |   22 ++--------------------
 2 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/facilitator/fac.py b/facilitator/fac.py
index 357009c..301ba3f 100644
--- a/facilitator/fac.py
+++ b/facilitator/fac.py
@@ -1,6 +1,24 @@
+import errno
 import re
 import socket
 
+# A decorator to ignore "broken pipe" errors.
+def catch_epipe(fn):
+    def ret(self, *args):
+        try:
+            return fn(self, *args)
+        except socket.error, e:
+            try:
+                err_num = e.errno
+            except AttributeError:
+                # Before Python 2.6, exception can be a pair.
+                err_num, errstr = e
+            except:
+                raise
+            if err_num != errno.EPIPE:
+                raise
+    return ret
+
 def parse_addr_spec(spec, defhost = None, defport = None, resolve = False):
     """Parse a host:port specification and return a 2-tuple ("host", port) as
     understood by the Python socket functions.
diff --git a/facilitator/facilitator b/facilitator/facilitator
index 0f16620..a4e0fb8 100755
--- a/facilitator/facilitator
+++ b/facilitator/facilitator
@@ -1,7 +1,6 @@
 #!/usr/bin/env python
 
 import SocketServer
-import errno
 import getopt
 import os
 import socket
@@ -140,23 +139,6 @@ class RegSet(object):
         finally:
             self.cv.release()
 
-# A decorator to ignore "broken pipe" errors.
-def catch_epipe(fn):
-    def ret(self, *args):
-        try:
-            return fn(self, *args)
-        except socket.error, e:
-            try:
-                err_num = e.errno
-            except AttributeError:
-                # Before Python 2.6, exception can be a pair.
-                err_num, errstr = e
-            except:
-                raise
-            if err_num != errno.EPIPE:
-                raise
-    return ret
-
 class Handler(SocketServer.StreamRequestHandler):
     def __init__(self, *args, **kwargs):
         self.deadline = time.time() + CLIENT_TIMEOUT
@@ -197,7 +179,7 @@ class Handler(SocketServer.StreamRequestHandler):
                 if buflen >= READLINE_MAX_LENGTH:
                     raise socket.error("readline: refusing to buffer %d bytes (last read was %d bytes)" % (buflen, len(data)))
 
-    @catch_epipe
+    @fac.catch_epipe
     def handle(self):
         num_lines = 0
         while True:
@@ -295,7 +277,7 @@ class Handler(SocketServer.StreamRequestHandler):
         self.send_ok()
         return True
 
-    finish = catch_epipe(SocketServer.StreamRequestHandler.finish)
+    finish = fac.catch_epipe(SocketServer.StreamRequestHandler.finish)
 
 class Server(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
     allow_reuse_address = True





More information about the tor-commits mailing list