[pypy-svn] r76923 - in pypy/trunk/pypy: module/_socket/test rlib

fijal at codespeak.net fijal at codespeak.net
Tue Sep 7 18:15:56 CEST 2010


Author: fijal
Date: Tue Sep  7 18:15:54 2010
New Revision: 76923

Modified:
   pypy/trunk/pypy/module/_socket/test/test_sock_app.py
   pypy/trunk/pypy/rlib/rsocket.py
Log:
A test for untested piece of code (initializing raw addresses). Also kill
a sanity check that was in wrong place at the very least. Reintroduce if
needed, but with tests please


Modified: pypy/trunk/pypy/module/_socket/test/test_sock_app.py
==============================================================================
--- pypy/trunk/pypy/module/_socket/test/test_sock_app.py	(original)
+++ pypy/trunk/pypy/module/_socket/test/test_sock_app.py	Tue Sep  7 18:15:54 2010
@@ -221,6 +221,21 @@
                         "(_socket, host, port): return _socket.getaddrinfo(host, port)")
     assert space.unwrap(w_l) == info
 
+def test_unknown_addr_as_object():
+    from pypy.rlib import rsocket
+    from pypy.rpython.lltypesystem import lltype, rffi
+    
+    c_addr = lltype.malloc(rsocket._c.sockaddr, flavor='raw')
+    c_addr.c_sa_data[0] = 'c'
+    rffi.setintfield(c_addr, 'c_sa_family', 15)
+    # XXX what size to pass here? for the purpose of this test it has
+    #     to be short enough so we have some data, 1 sounds good enough
+    #     + sizeof USHORT
+    w_obj = rsocket.Address(c_addr, 1 + 2).as_object(space)
+    assert space.is_true(space.isinstance(w_obj, space.w_tuple))
+    assert space.int_w(space.getitem(w_obj, space.wrap(0))) == 15
+    assert space.str_w(space.getitem(w_obj, space.wrap(1))) == 'c'
+
 def test_getnameinfo():
     host = "127.0.0.1"
     port = 25
@@ -440,7 +455,6 @@
         s2 = s.dup()
         assert s.fileno() != s2.fileno()
         assert s.getsockname() == s2.getsockname()
-    
 
     def test_buffer_or_unicode(self):
         # Test that send/sendall/sendto accept a buffer or a unicode as arg

Modified: pypy/trunk/pypy/rlib/rsocket.py
==============================================================================
--- pypy/trunk/pypy/rlib/rsocket.py	(original)
+++ pypy/trunk/pypy/rlib/rsocket.py	Tue Sep  7 18:15:54 2010
@@ -100,8 +100,6 @@
     def lock(self, TYPE=_c.sockaddr):
         """Return self.addr_p, cast as a pointer to TYPE.  Must call unlock()!
         """
-        if not (self.minlen <= self.addrlen <= self.maxlen):
-            raise RSocketError("invalid address")
         return rffi.cast(lltype.Ptr(TYPE), self.addr_p)
     lock._annspecialcase_ = 'specialize:ll'
 



More information about the Pypy-commit mailing list