[o2on-svn] [179] Check if read is completed.

Back to archive index

o2on svn commit o2on-****@lists*****
2010年 2月 16日 (火) 22:15:15 JST


Revision: 179
          http://sourceforge.jp/projects/o2on/svn/view?view=rev&revision=179
Author:   nawota
Date:     2010-02-16 22:15:15 +0900 (Tue, 16 Feb 2010)

Log Message:
-----------
Check if read is completed.

Modified Paths:
--------------
    trunk/opy2on/lib/o2on_node.py

Modified: trunk/opy2on/lib/o2on_node.py
===================================================================
--- trunk/opy2on/lib/o2on_node.py	2010-02-16 13:04:08 UTC (rev 178)
+++ trunk/opy2on/lib/o2on_node.py	2010-02-16 13:15:15 UTC (rev 179)
@@ -246,7 +246,7 @@
                 data = r.read(l)
             elif r.status == 404: pass
             else: raise Exception("status error %d" % r.status)
-        except socket.error:
+        except socket.error, httplib.IncompleteRead:
             pass
         else:
             if data:
@@ -279,8 +279,11 @@
             r = self.request("POST","/dat", data,headers)
         else:
             r = self.request("GET","/dat",None,headers)
-        stat = r.status
-        data = r.read()
+        try:
+            stat = r.status
+            data = r.read()
+        except socket.error, httplib.IncompleteRead:
+            return None
         if stat == 200:
             path = None
             path = r.getheader("X-O2-Original-DAT-URL")
@@ -303,7 +306,10 @@
             l = r.getheader('Content-Length')
             if l: l = int(l)
             else: return False
-            return r.read(l)
+            try:
+                return r.read(l)
+            except socket.error, httplib.IncompleteRead:
+                return False
         else: raise Exception("ping status %d" % r.status)
         return False
     def collection(self, glob):
@@ -313,7 +319,10 @@
         r = self.request("POST","/collection",board_xml,headers)
         result = []
         if r.status == 200:
-            data = r.read()
+            try:
+                data = r.read()
+            except socket.error, httplib.IncompleteRead:
+                return result
             # 本家o2on の bug 対策
             if data.rfind("</boards>") == -1:
                 index = data.rfind("<boards>")
@@ -330,9 +339,13 @@
     def findvalue(self, kid):
         headers = {"X-O2-Target-Key":hexlify(kid)}
         r = self.request("GET","/findvalue",None,headers)
+        try:
+            data = r.read()
+        except socket.error, httplib.IncompleteRead:
+            return []
         if r.status == 200:
             res = []
-            dom = xml.dom.minidom.parseString(r.read())
+            dom = xml.dom.minidom.parseString(data)
             nodes = dom.getElementsByTagName("nodes")
             keys = dom.getElementsByTagName("keys")
             if len(nodes):




o2on-svn メーリングリストの案内
Back to archive index