def _make_digest_auth_header(username, password, method, uri, nonce,<EOL>realm=None, opaque=None, algorithm=None,<EOL>qop=None, cnonce=None, nc=None, body=None):
assert username<EOL>assert password<EOL>assert nonce<EOL>assert method<EOL>assert uri<EOL>assert algorithm in ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>', None)<EOL>a1 = '<STR_LIT::>'.join([username, realm or '<STR_LIT>', password])<EOL>ha1 = _hash(a1.encode('<STR_LIT:utf-8>'), algorithm)<EOL>a2 = '<STR_LIT::>'.join([method, uri])<EOL>if qop == '<STR_LIT>':<EOL><INDENT>a2 = '<STR_LIT::>'.join([a2, _hash(body or b'<STR_LIT>', algorithm)])<EOL><DEDENT>ha2 = _hash(a2.encode('<STR_LIT:utf-8>'), algorithm)<EOL>a3 = '<STR_LIT::>'.join([ha1, nonce])<EOL>if qop in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>assert cnonce<EOL>assert nc<EOL>a3 = '<STR_LIT::>'.join([a3, nc, cnonce, qop])<EOL><DEDENT>a3 = '<STR_LIT::>'.join([a3, ha2])<EOL>auth_response = _hash(a3.encode('<STR_LIT:utf-8>'), algorithm)<EOL>auth_header ='<STR_LIT>'.format(username, auth_response, uri, nonce)<EOL>if realm != None:<EOL><INDENT>auth_header += '<STR_LIT>'.format(realm)<EOL><DEDENT>if opaque != None:<EOL><INDENT>auth_header += '<STR_LIT>'.format(opaque)<EOL><DEDENT>if algorithm:<EOL><INDENT>auth_header += '<STR_LIT>'.format(algorithm)<EOL><DEDENT>if cnonce:<EOL><INDENT>auth_header += '<STR_LIT>'.format(cnonce)<EOL><DEDENT>if nc:<EOL><INDENT>auth_header += '<STR_LIT>'.format(nc)<EOL><DEDENT>if qop:<EOL><INDENT>auth_header += '<STR_LIT>'.format(qop)<EOL><DEDENT>return auth_header<EOL>
Compile a digest authentication header string.

    Arguments:
    - `nonce`: nonce string, received within "WWW-Authenticate" header
    - `realm`: realm string, received within "WWW-Authenticate" header
    - `opaque`: opaque string, received within "WWW-Authenticate" header
    - `algorithm`: type of hashing algorithm, used by the client
    - `qop`: type of quality-of-protection, used by the client
    - `cnonce`: client nonce, required if qop is "auth" or "auth-int"
    - `nc`: client nonce count, required if qop is "auth" or "auth-int"
    - `body`: body of the outgoing request (bytes), used if qop is "auth-int"