[pypy-commit] pypy default: Implement pending() method for ssl objects

amauryfa noreply at buildbot.pypy.org
Thu May 12 08:08:28 CEST 2011


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: 
Changeset: r44088:1c635389d676
Date: 2011-05-03 17:12 +0200
http://bitbucket.org/pypy/pypy/changeset/1c635389d676/

Log:	Implement pending() method for ssl objects

diff --git a/pypy/module/_ssl/interp_ssl.py b/pypy/module/_ssl/interp_ssl.py
--- a/pypy/module/_ssl/interp_ssl.py
+++ b/pypy/module/_ssl/interp_ssl.py
@@ -199,6 +199,16 @@
         else:
             raise _ssl_seterror(self.space, self, num_bytes)
 
+    def pending(self):
+        """pending() -> count
+
+        Returns the number of already decrypted bytes available for read,
+        pending on the connection."""
+        count = libssl_SSL_pending(self.ssl)
+        if count < 0:
+            raise _ssl_seterror(self.space, self, count)
+        return self.space.wrap(count)
+
     @unwrap_spec(num_bytes=int)
     def read(self, num_bytes=1024):
         """read([len]) -> string
@@ -374,6 +384,7 @@
     server = interp2app(SSLObject.server),
     issuer = interp2app(SSLObject.issuer),
     write = interp2app(SSLObject.write),
+    pending = interp2app(SSLObject.pending),
     read = interp2app(SSLObject.read),
     do_handshake=interp2app(SSLObject.do_handshake),
     shutdown=interp2app(SSLObject.shutdown),
diff --git a/pypy/module/_ssl/test/test_ssl.py b/pypy/module/_ssl/test/test_ssl.py
--- a/pypy/module/_ssl/test/test_ssl.py
+++ b/pypy/module/_ssl/test/test_ssl.py
@@ -146,6 +146,7 @@
         data = ss.read(10)
         assert isinstance(data, str)
         assert len(data) == 10
+        assert ss.pending() > 50 # many more bytes to read
         self.s.close()
 
     def test_shutdown(self):


More information about the pypy-commit mailing list