def basic_auth_handler(url, method, timeout, headers, data, username=None, password=None):
def handle():<EOL><INDENT>"""<STR_LIT>"""<EOL>if username is not None and password is not None:<EOL><INDENT>auth_value = '<STR_LIT>'.format(username, password).encode('<STR_LIT:utf-8>')<EOL>auth_token = base64.b64encode(auth_value)<EOL>auth_header = b'<STR_LIT>' + auth_token<EOL>headers.append(['<STR_LIT>', auth_header])<EOL><DEDENT>default_handler(url, method, timeout, headers, data)()<EOL><DEDENT>return handle<EOL>
Handler that implements HTTP/HTTPS connections with Basic Auth.

    Sets auth headers using supplied 'username' and 'password', if set.
    Used by the push_to_gateway functions. Can be re-used by other handlers.