]> granicus.if.org Git - python/commitdiff
Merged revisions 83201 via svnmerge from
authorGeorg Brandl <georg@python.org>
Sun, 1 Aug 2010 21:16:54 +0000 (21:16 +0000)
committerGeorg Brandl <georg@python.org>
Sun, 1 Aug 2010 21:16:54 +0000 (21:16 +0000)
svn+ssh://svn.python.org/python/branches/py3k

........
  r83201 | georg.brandl | 2010-07-28 10:19:35 +0200 (Mi, 28 Jul 2010) | 1 line

  #9354: Provide getsockopt() in asyncore file_wrapper().  Patch by Lukas Langa.
........

Lib/asyncore.py
Lib/test/test_asyncore.py
Misc/ACKS
Misc/NEWS

index 44e89181cb6b904fd28718ac729b365cfad3c608..f066e769c8828ac1618c34e7e6215869557720b6 100644 (file)
@@ -598,6 +598,14 @@ if os.name == 'posix':
         def send(self, *args):
             return os.write(self.fd, *args)
 
+        def getsockopt(self, level, optname, buflen=None):
+            if (level == socket.SOL_SOCKET and
+                optname == socket.SO_ERROR and
+                not buflen):
+                return 0
+            raise NotImplementedError("Only asyncore specific behaviour "
+                                      "implemented.")
+
         read = recv
         write = send
 
index 785b2116f6f9c6837eff4f64ad68c9365999be08..c82f9b780c2de68dc3334730fa88a5f40751c971 100644 (file)
@@ -413,6 +413,19 @@ if hasattr(asyncore, 'file_wrapper'):
             w.close()
             self.assertEqual(open(TESTFN, 'rb').read(), self.d + d1 + d2)
 
+        @unittest.skipUnless(hasattr(asyncore, 'file_dispatcher'),
+                             '    asyncore.file_dispatcher required')
+        def test_dispatcher(self):
+            fd = os.open(TESTFN, os.O_RDONLY)
+            data = []
+            class FileDispatcher(asyncore.file_dispatcher):
+                def handle_read(self):
+                    data.append(self.recv(29))
+            s = FileDispatcher(fd)
+            os.close(fd)
+            asyncore.loop(timeout=0.01, use_poll=True, count=2)
+            self.assertEqual(b"".join(data), self.d)
+
 
 def test_main():
     tests = [HelperFunctionTests, DispatcherTests, DispatcherWithSendTests,
index 519dda488c47690cf2f85bf8fa968e168e367973..41c92a08bbeeed5d165e02b2c4bc1f4bed3ab118 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -426,6 +426,7 @@ Hannu Krosing
 Andrew Kuchling
 Vladimir Kushnir
 Cameron Laird
+Ɓukasz Langa
 Tino Lange
 Andrew Langmead
 Detlef Lannert
index f40c24c930d55accab1af3234dbdc4d76f136c7c..3c51288eca059b76d45ecbec5dad5effcb83ba7d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -127,6 +127,8 @@ Library
 
 - Issue #1690103: Fix initial namespace for code run with trace.main().
 
+- Issue #9354: Provide getsockopt() in asyncore's file_wrapper.
+
 - Issue #9448: Fix a leak of OS resources (mutexes or semaphores) when
   re-initializing a buffered IO object by calling its ``__init__`` method.