[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

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



commit 6701af88e5879850a3401b343e0bb8187210057b
Author: David Fifield <david@xxxxxxxxxxxxxxx>
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



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits