Andrews Medina committed 8886e79

fixed support for pwd stdlib 2.7.4

  • Participants
  • Parent commits 0f6b593
  • Branches stdlib-2.7.4-pwd-fix

Comments (0)

Files changed (2)

File pypy/module/pwd/

 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(
     return space.call_function(w_passwd_struct, w_tuple)
-def getpwuid(space, uid):
+def getpwuid(space, w_uid):
     getpwuid(uid) -> (pw_name,pw_passwd,pw_uid,
     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.wrap(sys.maxint)),
+                    , 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,
     return space.newlist(users_w)

File pypy/module/pwd/test/

             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