[o2on-svn] [166] Decoding is now compatible with o2on.

Back to archive index

o2on svn commit o2on-****@lists*****
2009年 8月 16日 (日) 22:28:38 JST


Revision: 166
          http://sourceforge.jp/projects/o2on/svn/view?view=rev&revision=166
Author:   nawota
Date:     2009-08-16 22:28:38 +0900 (Sun, 16 Aug 2009)

Log Message:
-----------
Decoding is now compatible with o2on.

Modified Paths:
--------------
    trunk/opy2on/lib/o2on_key.py
    trunk/opy2on/lib/o2on_server.py

Modified: trunk/opy2on/lib/o2on_key.py
===================================================================
--- trunk/opy2on/lib/o2on_key.py	2009-08-16 07:12:02 UTC (rev 165)
+++ trunk/opy2on/lib/o2on_key.py	2009-08-16 13:28:38 UTC (rev 166)
@@ -16,6 +16,7 @@
 import hashlib
 import time
 import errno
+import codecs
 
 from o2on_const import KeyDBFile, regHosts
 import o2on_config
@@ -23,6 +24,14 @@
 import o2on_dat
 import o2on_node
 
+def my_replace_handler(inst):
+    return ((u"\u30fb", inst.start+2))
+
+try: 
+    codecs.lookup_error('opy2on_replace')
+except LookupError:
+    codecs.register_error('opy2on_replace', my_replace_handler) 
+
 class Key:
     def __init__(self):
         self.hash = None
@@ -56,12 +65,12 @@
         self.size = len(data)
         first = data.split("\n",1)[0]
         try:
-            first = first.replace("\x86\xa6", "\x81E").decode('cp932').encode('utf-8')
+            first = first.decode('cp932').encode('utf-8')
         except UnicodeDecodeError, inst:
             try:
                 first = first.decode('euc_jp').encode('utf-8')
             except UnicodeDecodeError, inst: 
-                raise Exception("Couldn't decode first line %s" % dat.datpath())
+                first = first.decode('cp932','opy2on_replace').encode('utf-8')
         m = re.compile(r'^.*<>.*<>.*<>.*<>(.*)$').match(first)
         if m: self.title = m.group(1)
         self.url = "http://xxx.%s/test/read.cgi/%s/%s/" % (dat.domain,

Modified: trunk/opy2on/lib/o2on_server.py
===================================================================
--- trunk/opy2on/lib/o2on_server.py	2009-08-16 07:12:02 UTC (rev 165)
+++ trunk/opy2on/lib/o2on_server.py	2009-08-16 13:28:38 UTC (rev 166)
@@ -22,6 +22,7 @@
 import threading
 import select
 from errno import ECONNRESET, EPIPE, ETIMEDOUT
+import codecs
 
 import o2on_config
 from o2on_const import regHosts, ProtocolVer, AppName
@@ -32,6 +33,14 @@
 import o2on_im
 import o2on_util
 
+def my_replace_handler(inst):
+    return ((u"\u30fb", inst.start+2))
+
+try: 
+    codecs.lookup_error('opy2on_replace')
+except LookupError:
+    codecs.register_error('opy2on_replace', my_replace_handler) 
+
 class O2ONServer(BaseHTTPServer.HTTPServer):
     def __init__(self, handler, port, g):
         BaseHTTPServer.HTTPServer.__init__(self,
@@ -68,7 +77,7 @@
     def shutdown(self):
         for r in self.requests: 
             try:
-                #r.shutdown(socket.SHUT_RDWR)
+                r.shutdown(socket.SHUT_RDWR)
                 r.close()
             except Exception:
                 pass
@@ -196,11 +205,12 @@
         m = re.compile(r'^.*<>.*<>.*<>.*<>(.*)$').match(first)
         if not m: return ""
         try:
-            first = first.replace("\x86\xa6", "\x81E").decode('cp932').encode('utf-8')
+            first = first.decode('cp932').encode('utf-8')
         except UnicodeDecodeError, inst:
             try:
                 first = first.decode('euc_jp').encode('utf-8')
-            except UnicodeDecodeError, inst: raise inst
+            except UnicodeDecodeError, inst: 
+                first = first.decode('cp932','opy2on_replace').encode('utf-8')
         m = re.compile(r'^.*<>.*<>.*<>.*<>(.*)$').match(first)
         if not m: return ""
         return m.group(1)




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