Author: Richard Plangger <[email protected]>
Branch: py3.5-ssl
Changeset: r88703:582cca1fe05c
Date: 2016-11-28 16:40 +0100
http://bitbucket.org/pypy/pypy/changeset/582cca1fe05c/

Log:    remove zeroterm parameter of _str_to_ffi_buffer

diff --git a/lib_pypy/_cffi_ssl/_stdssl/__init__.py 
b/lib_pypy/_cffi_ssl/_stdssl/__init__.py
--- a/lib_pypy/_cffi_ssl/_stdssl/__init__.py
+++ b/lib_pypy/_cffi_ssl/_stdssl/__init__.py
@@ -678,6 +678,11 @@
 
 def _fs_decode(name):
     return name.decode(sys.getfilesystemencoding())
+def _fs_converter(name):
+    """ name must not be None """
+    if isinstance(name, str):
+        return name.encode(sys.getfilesystemencoding())
+    return bytes(name)
 
 
 def cipher_to_tuple(cipher):
@@ -1048,7 +1053,7 @@
         ffi.errno = 0
         if filepath is None:
             raise TypeError("filepath must not be None")
-        buf = _str_to_ffi_buffer(filepath, zeroterm=True)
+        buf = _fs_converter(filepath)
         mode = ffi.new("char[]",b"r")
         ffi.errno = 0
         bio = lib.BIO_new_file(buf, mode)
@@ -1096,7 +1101,10 @@
         return _list
 
     def set_ecdh_curve(self, name):
-        buf = _str_to_ffi_buffer(name, zeroterm=True)
+        # needs to be zero terminated
+        if name is None:
+            raise TypeError()
+        buf = _fs_converter(name)
         nid = lib.OBJ_sn2nid(buf)
         if nid == 0:
             raise ValueError("unknown elliptic curve name '%s'" % name)
diff --git a/lib_pypy/_cffi_ssl/_stdssl/utility.py 
b/lib_pypy/_cffi_ssl/_stdssl/utility.py
--- a/lib_pypy/_cffi_ssl/_stdssl/utility.py
+++ b/lib_pypy/_cffi_ssl/_stdssl/utility.py
@@ -13,14 +13,8 @@
 def _bytes_with_len(char_ptr, length):
     return ffi.buffer(char_ptr, length)[:]
 
-def _str_to_ffi_buffer(view, zeroterm=False):
+def _str_to_ffi_buffer(view):
     # XXX incomplete and does not work if e.g. view in (True, 0, 1, ...)
-    if zeroterm:
-        # only two cases use zeroterm=True, those are rather 'short' strings
-        if isinstance(view, str):
-            return ffi.from_buffer(bytes(view+'\x00', 'utf-8'))
-        return ffi.from_buffer(bytes(view)+b'\x00')
-
     try:
         buf = ffi.from_buffer(view)
         return buf
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to