[o2on-svn] [151] Support python 2.5

Back to archive index

o2on svn commit o2on-****@lists*****
2009年 8月 8日 (土) 16:49:21 JST


Revision: 151
          http://sourceforge.jp/projects/o2on/svn/view?view=rev&revision=151
Author:   nawota
Date:     2009-08-08 16:49:21 +0900 (Sat, 08 Aug 2009)

Log Message:
-----------
Support python 2.5

Modified Paths:
--------------
    trunk/opy2on/README
    trunk/opy2on/lib/o2on_dat.py
    trunk/opy2on/lib/o2on_im.py
    trunk/opy2on/lib/o2on_key.py
    trunk/opy2on/lib/o2on_node.py
    trunk/opy2on/lib/o2on_server.py
    trunk/opy2on/lib/o2on_util.py

Modified: trunk/opy2on/README
===================================================================
--- trunk/opy2on/README	2009-08-07 22:04:34 UTC (rev 150)
+++ trunk/opy2on/README	2009-08-08 07:49:21 UTC (rev 151)
@@ -8,9 +8,9 @@
 
 必要なもの
 
-- python 2.6
+- python 2.5 (できれば 2.6)
 - pycrypto
-- D-Bus を使うならば python-dbus
+- D-Bus を使うならば dbus-python
 
 起動
 

Modified: trunk/opy2on/lib/o2on_dat.py
===================================================================
--- trunk/opy2on/lib/o2on_dat.py	2009-08-07 22:04:34 UTC (rev 150)
+++ trunk/opy2on/lib/o2on_dat.py	2009-08-08 07:49:21 UTC (rev 151)
@@ -1,5 +1,7 @@
 #!/usr/bin/python
 
+from __future__ import with_statement
+
 import threading
 import cPickle
 import os.path

Modified: trunk/opy2on/lib/o2on_im.py
===================================================================
--- trunk/opy2on/lib/o2on_im.py	2009-08-07 22:04:34 UTC (rev 150)
+++ trunk/opy2on/lib/o2on_im.py	2009-08-08 07:49:21 UTC (rev 151)
@@ -1,5 +1,7 @@
 #!/usr/bin/python
 
+from __future__ import with_statement
+
 import threading
 import os.path
 import cPickle

Modified: trunk/opy2on/lib/o2on_key.py
===================================================================
--- trunk/opy2on/lib/o2on_key.py	2009-08-07 22:04:34 UTC (rev 150)
+++ trunk/opy2on/lib/o2on_key.py	2009-08-08 07:49:21 UTC (rev 151)
@@ -1,6 +1,8 @@
 #!/usr/bin/python
 # -*- coding: utf-8
 
+from __future__ import with_statement
+
 import os.path
 import re
 import cPickle
@@ -14,8 +16,6 @@
 import hashlib
 import time
 
-import sys
-
 from o2on_const import KeyDBFile, regHosts
 import o2on_config
 from o2on_util import hash_xor_bitlength

Modified: trunk/opy2on/lib/o2on_node.py
===================================================================
--- trunk/opy2on/lib/o2on_node.py	2009-08-07 22:04:34 UTC (rev 150)
+++ trunk/opy2on/lib/o2on_node.py	2009-08-08 07:49:21 UTC (rev 151)
@@ -1,6 +1,8 @@
 #!/usr/bin/python
 # -*- coding: utf-8
 
+from __future__ import with_statement
+
 import os
 from Crypto.Cipher import AES # pycrypto
 import xml.dom.minidom
@@ -166,8 +168,11 @@
                 raise NodeRemovable
             except socket.error, inst:
                 socket.setdefaulttimeout(None)
-                if inst.errno in (113, 111): raise NodeRemovable
-                if inst.errno in (110, 104): raise NodeRefused
+                errno = None
+                if hasattr(inst, 'errno'): errno = inst.errno
+                else: errno =  inst[0]
+                if errno in (113, 111): raise NodeRemovable
+                if errno in (110, 104): raise NodeRefused
                 else: raise inst
             except httplib.BadStatusLine: 
                 socket.setdefaulttimeout(None)

Modified: trunk/opy2on/lib/o2on_server.py
===================================================================
--- trunk/opy2on/lib/o2on_server.py	2009-08-07 22:04:34 UTC (rev 150)
+++ trunk/opy2on/lib/o2on_server.py	2009-08-08 07:49:21 UTC (rev 151)
@@ -19,6 +19,8 @@
 import traceback
 import sys
 from xml.parsers.expat import ExpatError
+import threading
+import select
 
 import o2on_config
 from o2on_const import regHosts, ProtocolVer, AppName
@@ -35,6 +37,32 @@
                                            handler)
         self.glob = g
         self.requests = []
+        self.__is_shut_down = threading.Event()
+        self.__serving = False
+    def serve_forever(self, poll_interval=0.5):
+        #hasattr(BaseHTTPServer.HTTPServer, '_handle_request_noblock'):
+        if sys.hexversion >= 0x020600f0:
+            BaseHTTPServer.HTTPServer.serve_forever(self, poll_interval) # 2.6
+        else:
+            self._serve_forever(poll_interval) # 2.5
+    def _serve_forever(self, poll_interval=0.5):
+        """Handle one request at a time until shutdown.
+
+        Polls for shutdown every poll_interval seconds. Ignores
+        self.timeout. If you need to do periodic tasks, do them in
+        another thread.
+        """
+        self.__serving = True
+        self.__is_shut_down.clear()
+        while self.__serving:
+            # XXX: Consider using another file descriptor or
+            # connecting to the socket to wake this up instead of
+            # polling. Polling reduces our responsiveness to a
+            # shutdown request and wastes cpu at all other times.
+            r, w, e = select.select([self], [], [], poll_interval)
+            if r:
+                self.handle_request()
+        self.__is_shut_down.set()
     def shutdown(self):
         for r in self.requests: 
             try:
@@ -42,7 +70,11 @@
                 r.close()
             except Exception:
                 pass
-        BaseHTTPServer.HTTPServer.shutdown(self)
+        if hasattr(BaseHTTPServer.HTTPServer, 'shutdown'):
+            BaseHTTPServer.HTTPServer.shutdown(self)
+        else:
+            self.__serving = False
+            self.__is_shut_down.wait()
     def finish_request(self, request, client_address):
         self.requests.append(request)
         try:
@@ -50,7 +82,11 @@
         except socket.timeout:
             pass
         except Exception,inst:
-            if isinstance(inst, socket.error) and inst.errno in (104, 32):
+            errno = None
+            if isinstance(inst, socket.error): # 2.6
+                if hasattr(inst, 'errno'): errno = inst.errno
+                else: errno =  inst[0]
+            if  errno in (104, 32): # 2.5
                 pass
             else:
                 if o2on_config.OutputErrorFile:

Modified: trunk/opy2on/lib/o2on_util.py
===================================================================
--- trunk/opy2on/lib/o2on_util.py	2009-08-07 22:04:34 UTC (rev 150)
+++ trunk/opy2on/lib/o2on_util.py	2009-08-08 07:49:21 UTC (rev 151)
@@ -1,5 +1,7 @@
 #!/usr/bin/python
 
+from __future__ import with_statement
+
 import random
 from struct import pack 
 import threading




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