[pypy-commit] pypy cffi-libs2: add cffi implementation of crypt

mattip pypy.commits at gmail.com
Wed May 29 14:40:07 EDT 2019


Author: Matti Picus <matti.picus at gmail.com>
Branch: cffi-libs2
Changeset: r96712:4e4d2be6ff04
Date: 2019-05-29 20:55 +0300
http://bitbucket.org/pypy/pypy/changeset/4e4d2be6ff04/

Log:	add cffi implementation of crypt

diff --git a/lib-python/conftest.py b/lib-python/conftest.py
--- a/lib-python/conftest.py
+++ b/lib-python/conftest.py
@@ -176,7 +176,7 @@
     RegrTest('test_copy_reg.py', core=True),
     RegrTest('test_cpickle.py', core=True),
     RegrTest('test_cprofile.py'),
-    RegrTest('test_crypt.py', usemodules='crypt'),
+    RegrTest('test_crypt.py'),
     RegrTest('test_csv.py', usemodules='_csv'),
     RegrTest('test_ctypes.py', usemodules="_rawffi thread cpyext"),
     RegrTest('test_curses.py'),
diff --git a/lib_pypy/crypt/__init__.py b/lib_pypy/crypt/__init__.py
new file mode 100644
--- /dev/null
+++ b/lib_pypy/crypt/__init__.py
@@ -0,0 +1,21 @@
+"""
+CFFI based implementation of the crypt module
+"""
+
+import sys
+import cffi
+
+ffi = cffi.FFI()
+ffi.cdef('char *crypt(char *word, char *salt);')
+
+try:
+    lib = ffi.dlopen('crypt')
+except OSError:
+    raise ImportError('crypt not available')
+
+
+def crypt(word, salt):
+    res = lib.crypt(word, salt)
+    if not res:
+        return None
+    return ffi.string(res)
diff --git a/pypy/config/pypyoption.py b/pypy/config/pypyoption.py
--- a/pypy/config/pypyoption.py
+++ b/pypy/config/pypyoption.py
@@ -31,13 +31,13 @@
 working_modules = default_modules.copy()
 working_modules.update([
     "_socket", "unicodedata", "mmap", "fcntl", "_locale", "pwd",
-    "select", "zipimport", "_lsprof", "crypt", "signal", "_rawffi", "termios",
+    "select", "zipimport", "_lsprof", "signal", "_rawffi", "termios",
     "zlib", "bz2", "struct", "_md5", "_sha", "_minimal_curses",
     "cStringIO", "thread", "itertools", "pyexpat", "cpyext", "array",
     "binascii", "_multiprocessing", '_warnings', "_collections",
     "_multibytecodec", "micronumpy", "_continuation", "_cffi_backend",
     "_csv", "_cppyy", "_pypyjson", "_jitlog",
-    #" _ssl", "_hashlib"
+    #" _ssl", "_hashlib", "crypt"
 ])
 
 import rpython.rlib.rvmprof.cintf


More information about the pypy-commit mailing list