Emit proper warnings
diff --git a/OpenSSL/SSL.py b/OpenSSL/SSL.py
index ff0259a..5d9c360 100644
--- a/OpenSSL/SSL.py
+++ b/OpenSSL/SSL.py
@@ -1,3 +1,4 @@
+import warnings
 from sys import platform
 from functools import wraps, partial
 from itertools import count
@@ -313,7 +314,7 @@
 
         # Backward compatibility
         if isinstance(cafile, _text_type):
-            DeprecationWarning("str object in cafile is no longer accepted, use bytes")
+            warnings.warn("str object in cafile is no longer accepted, use bytes", DeprecationWarning)
             cafile = cafile.encode('utf-8')
 
         if cafile is None:
@@ -979,7 +980,7 @@
 
         # Backward compatibility
         if isinstance(buf, _text_type):
-            DeprecationWarning("str object in buf is no longer accepted, use bytes")
+            warnings.warn("str object in buf is no longer accepted, use bytes", DeprecationWarning)
             buf = buf.encode('utf-8')
 
         if isinstance(buf, _memoryview):
@@ -1009,7 +1010,7 @@
 
         # Backward compatibility
         if isinstance(buf, _text_type):
-            DeprecationWarning("str object in buf is no longer accepted, use bytes")
+            warnings.warn("str object in buf is no longer accepted, use bytes", DeprecationWarning)
             buf = buf.encode('utf-8')
 
         if isinstance(buf, _memoryview):
@@ -1100,7 +1101,7 @@
 
         # Backward compatibility
         if isinstance(buf, _text_type):
-            DeprecationWarning("str object in buf is no longer accepted, use bytes")
+            warnings.warn("str object in buf is no longer accepted, use bytes", DeprecationWarning)
             buf = buf.encode("ascii")
 
         if self._into_ssl is None:
diff --git a/OpenSSL/crypto.py b/OpenSSL/crypto.py
index 0aa140a..e8b6d3c 100644
--- a/OpenSSL/crypto.py
+++ b/OpenSSL/crypto.py
@@ -1,3 +1,4 @@
+import warnings
 from time import time
 from base64 import b16encode
 from functools import partial
@@ -1955,7 +1956,7 @@
 
         # Backward compatibility
         if isinstance(passphrase, _text_type):
-            DeprecationWarning("str object in passphrase is no longer accepted, use bytes")
+            warnings.warn("str object in passphrase is no longer accepted, use bytes", DeprecationWarning)
             passphrase = passphrase.encode('utf-8')
 
         if self._cacerts is None:
@@ -2258,7 +2259,7 @@
 
     # Backward compatibility
     if isinstance(data, _text_type):
-        DeprecationWarning("str object in passphrase is no longer accepted, use bytes")
+        warnings.warn("str object in passphrase is no longer accepted, use bytes", DeprecationWarning)
         data = data.encode('utf-8')
 
     digest_obj = _lib.EVP_get_digestbyname(_byte_string(digest))
@@ -2298,7 +2299,7 @@
 
     # Backward compatibility
     if isinstance(data, _text_type):
-        DeprecationWarning("str object in passphrase is no longer accepted, use bytes")
+        warnings.warn("str object in passphrase is no longer accepted, use bytes", DeprecationWarning)
         data = data.encode('utf-8')
 
     digest_obj = _lib.EVP_get_digestbyname(_byte_string(digest))
@@ -2395,7 +2396,7 @@
 
     # Backward compatibility
     if isinstance(passphrase, _text_type):
-        DeprecationWarning("str object in passphrase is no longer accepted, use bytes")
+        warnings.warn("str object in passphrase is no longer accepted, use bytes", DeprecationWarning)
         passphrase = passphrase.encode('utf-8')
 
     if isinstance(buffer, _text_type):