"""
Functions related to HTTP Basic Authorization

"""

from functools import wraps

from flask import request, Response, current_app


def basic_auth(original_function):
    """
    Wrapper.  Verify that request.authorization exists and that its
    contents match the application's config.basic_auth_credentials
    dict.

    Args:
        original_function (function): The function to wrap.

    Returns:
        flask.Response: When credentials are missing or don't match.
        original_function (function): The original function.

    """
    @wraps(original_function)
    def decorated(*args, **kwargs):
        try:
            assert request.authorization.username == \
                current_app.config['APP_USERNAME']
            assert request.authorization.password == \
                current_app.config['APP_PASSWORD']
        except AttributeError:
            return Response(
                'You must provide access credentials for this url.', 401,
                {'WWW-Authenticate': 'Basic'})
        except AssertionError:
            return Response(
                'Could not verify your access level for that URL.\n'
                'You have to login with proper credentials', 401,
                {'WWW-Authenticate': 'Basic'})

        return original_function(*args, **kwargs)
    return decorated
@@ -105,24 +105,23 @@
 equest, 
-Response
+jsonify
 , curren
@@ -536,24 +536,25 @@
 n.%0A%0A    %22%22%22%0A
+%0A
     @wraps(o
@@ -624,39 +624,40 @@
 ry:%0A            
-asser
+if no
 t 
+(
 request.authoriz
@@ -670,21 +670,17 @@
 username
- == %5C
+,
 %0A       
@@ -692,61 +692,11 @@
     
-current_app.config%5B'APP_USERNAME'%5D%0A            assert
+   
  req
@@ -726,14 +726,19 @@
 word
+)
  == 
-%5C%0A
+(%0A    
     
@@ -771,24 +771,44 @@
 nfig
-%5B'APP_PASSWORD
+.basic_auth_credentials%5B'username
 '%5D
+,
 %0A   
@@ -816,133 +816,363 @@
     
-except AttributeError:%0A            return Response(%0A                'You must provide access credentials for this url.',
+            current_app.config.basic_auth_credentials%5B'password'%5D):%0A                unauthorized_response = jsonify(%0A                    %7B'message': 'Could not verify your access level '%0A                                'for that URL. %5CnYou have to login '%0A                                'with proper credentials',%0A                     'statusCode':
  401
-,
+%7D)
 %0A   
@@ -1188,38 +1188,92 @@
     
-%7B'WWW-Authenticate': 'Basic'%7D)
+unauthorized_response.status_code = 401%0A                return unauthorized_response
 %0A   
@@ -1289,16 +1289,16 @@
 pt A
-ssertion
+ttribute
 Erro
@@ -1316,23 +1316,39 @@
     
-return Response
+unauthorized_response = jsonify
 (%0A  
@@ -1360,16 +1360,28 @@
         
+ %7B'message':
  'Could 
@@ -1413,60 +1413,104 @@
 vel 
-for that URL.%5Cn'%0A                'You have to login 
+'%0A                            'for that URL. %5CnYou have to login '%0A                            '
 with
@@ -1534,13 +1534,8 @@
 ls',
- 401,
 %0A   
@@ -1551,38 +1551,80 @@
     
-%7B'WWW-Authenticate': 'Basic'%7D)
+ 'statusCode': 401%7D)%0A            unauthorized_response.status_code = 401
 %0A%0A  

Remove use of assert statements since this does not conform to general best practice.