[pypy-commit] pypy stdlib-2.7.4-pwd-fix: fixed support for pwd stdlib 2.7.4

andrewsmedina noreply at buildbot.pypy.org
Mon Aug 12 09:47:39 CEST 2013


Author: Andrews Medina <andrewsmedina at gmail.com>
Branch: stdlib-2.7.4-pwd-fix
Changeset: r66079:8886e7984343
Date: 2013-07-30 21:32 -0300
http://bitbucket.org/pypy/pypy/changeset/8886e7984343/

Log:	fixed support for pwd stdlib 2.7.4

diff --git a/pypy/module/pwd/interp_pwd.py b/pypy/module/pwd/interp_pwd.py
--- a/pypy/module/pwd/interp_pwd.py
+++ b/pypy/module/pwd/interp_pwd.py
@@ -2,7 +2,7 @@
 from rpython.rtyper.tool import rffi_platform
 from rpython.rtyper.lltypesystem import rffi, lltype
 from pypy.interpreter.gateway import unwrap_spec
-from pypy.interpreter.error import operationerrfmt
+from pypy.interpreter.error import OperationError, operationerrfmt
 from rpython.rlib.rarithmetic import intmask
 
 eci = ExternalCompilationInfo(
@@ -52,14 +52,19 @@
         ])
     return space.call_function(w_passwd_struct, w_tuple)
 
- at unwrap_spec(uid=int)
-def getpwuid(space, uid):
+def getpwuid(space, w_uid):
     """
     getpwuid(uid) -> (pw_name,pw_passwd,pw_uid,
                       pw_gid,pw_gecos,pw_dir,pw_shell)
     Return the password database entry for the given numeric user ID.
     See pwd.__doc__ for more on password database entries.
     """
+    import sys
+    if space.is_true(space.or_(space.gt(w_uid, space.wrap(sys.maxint)),
+                              space.lt(w_uid, space.wrap(-sys.maxint - 1)))):
+        msg = "getpwuid(): uid not found"
+        raise OperationError(space.w_KeyError, space.wrap(msg))
+    uid = space.int_w(w_uid)
     pw = c_getpwuid(uid)
     if not pw:
         raise operationerrfmt(space.w_KeyError,
@@ -92,4 +97,3 @@
     finally:
         c_endpwent()
     return space.newlist(users_w)
-    
diff --git a/pypy/module/pwd/test/test_pwd.py b/pypy/module/pwd/test/test_pwd.py
--- a/pypy/module/pwd/test/test_pwd.py
+++ b/pypy/module/pwd/test/test_pwd.py
@@ -20,9 +20,11 @@
         else:
             assert pw.pw_dir.startswith('/')
         assert pw.pw_shell.startswith('/')
-        #
         assert type(pw.pw_uid) is int
         assert type(pw.pw_gid) is int
+        # should be out of uid_t range
+        raises(KeyError, pwd.getpwuid, 2**128)
+        raises(KeyError, pwd.getpwuid, -2**128)
 
     def test_getpwnam(self):
         import pwd


More information about the pypy-commit mailing list