def calcHA1(pszAlg, pszUserName, pszRealm, pszPassword, pszNonce, pszCNonce, preHA1=None):
 if (preHA1 and (pszUserName or pszRealm or pszPassword)):
  raise TypeError('preHA1 is incompatible with the pszUserName, pszRealm, and pszPassword arguments')
 if (preHA1 is None):
  m = algorithms[pszAlg]()
  m.update(pszUserName)
  m.update(':')
  m.update(pszRealm)
  m.update(':')
  m.update(pszPassword)
  HA1 = hexlify(m.digest())
 else:
  HA1 = preHA1
 if (pszAlg == 'md5-sess'):
  m = algorithms[pszAlg]()
  m.update(HA1)
  m.update(':')
  m.update(pszNonce)
  m.update(':')
  m.update(pszCNonce)
  HA1 = hexlify(m.digest())
 return HA1

def calcHA1 ( pszAlg , pszUserName , pszRealm , pszPassword , pszNonce , pszCNonce , preHA1 = None ) : if ( preHA1 and ( pszUserName or pszRealm or pszPassword ) ) : raise TypeError ( 'preHA1 is incompatible with the pszUserName, pszRealm, and pszPassword arguments' ) if ( preHA1 is None ) : m = algorithms [ pszAlg ] ( ) m . update ( pszUserName ) m . update ( ':' ) m . update ( pszRealm ) m . update ( ':' ) m . update ( pszPassword ) HA1 = hexlify ( m . digest ( ) ) else : HA1 = preHA1 if ( pszAlg == 'md5-sess' ) : m = algorithms [ pszAlg ] ( ) m . update ( HA1 ) m . update ( ':' ) m . update ( pszNonce ) m . update ( ':' ) m . update ( pszCNonce ) HA1 = hexlify ( m . digest ( ) ) return HA1
compute h from rfc 2617 .