diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2018-01-13 09:50:17 -0500 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2018-01-13 09:50:17 -0500 |
commit | c63d070973356a3fa06e48cfe608b841ae8d3e3d (patch) | |
tree | 9ba8210be17e45a70d46415a6d065804508000fa /cherrypy | |
parent | 821e1553d080aac3c2441dd38909b1130e99e005 (diff) | |
download | cherrypy-git-c63d070973356a3fa06e48cfe608b841ae8d3e3d.tar.gz |
Deprecate httpauth module. Ref #1688.
Diffstat (limited to 'cherrypy')
-rw-r--r-- | cherrypy/lib/auth.py | 19 | ||||
-rw-r--r-- | cherrypy/lib/httpauth.py | 7 |
2 files changed, 25 insertions, 1 deletions
diff --git a/cherrypy/lib/auth.py b/cherrypy/lib/auth.py index bb9e69fc..2da37154 100644 --- a/cherrypy/lib/auth.py +++ b/cherrypy/lib/auth.py @@ -7,12 +7,27 @@ Look to auth_basic and auth_digest instead. import warnings import cherrypy -from cherrypy.lib import httpauth + + +# import late to avoid deprecation warning on import +httpauth = None + + +def import_httpauth(): + """ + Late-import cherrypy.lib.httpauth into globals. + Then replace this function so it does nothing. + """ + globals().update( + httpauth=__import__('cherrypy.lib.httpauth').lib.httpauth, + import_httpauth=lambda: None + ) def check_auth(users, encrypt=None, realm=None): """If an authorization header contains credentials, return True or False. """ + import_httpauth() msg = ( "`basic_auth` and `digest_auth` tools are deprecated. Use " "`auth_basic` and `auth_digest` instead." @@ -75,6 +90,7 @@ def basic_auth(realm, users, encrypt=None, debug=False): if None it defaults to a md5 encryption. """ + import_httpauth() if check_auth(users, encrypt): if debug: cherrypy.log('Auth successful', 'TOOLS.BASIC_AUTH') @@ -97,6 +113,7 @@ def digest_auth(realm, users, debug=False): A dict of the form: {username: password} or a callable returning a dict. """ + import_httpauth() if check_auth(users, realm=realm): if debug: cherrypy.log('Auth successful', 'TOOLS.DIGEST_AUTH') diff --git a/cherrypy/lib/httpauth.py b/cherrypy/lib/httpauth.py index e3a9b85e..88797b51 100644 --- a/cherrypy/lib/httpauth.py +++ b/cherrypy/lib/httpauth.py @@ -24,6 +24,7 @@ SUPPORTED_QOP - list of supported 'Digest' 'qop'. """ import time +import warnings from hashlib import md5 from six.moves.urllib.request import parse_http_list, parse_keqv_list @@ -33,6 +34,12 @@ from cherrypy._cpcompat import ( ) +warnings.warn( + "`httpauth` module is deprecated. Do not use.", + DeprecationWarning, +) + + __version__ = 1, 0, 1 __author__ = 'Tiago Cogumbreiro <cogumbreiro@users.sf.net>' __credits__ = """ |