'Checks if the result XML byte string specifies the encoding.'

def assertEncodingDeclaration(self, result, encoding):

    enc_re = '<\\?xml[^>]+    encoding=[\\"\']([^\\"\']+)[\\"\']'
    if isinstance(result, str):
        has_encoding = re.compile(enc_re).match
    else:
        has_encoding = re.compile(_bytes(enc_re)).match
    self.assertTrue(has_encoding(result))
    result_encoding = has_encoding(result).group(1)
    self.assertEqual(result_encoding.upper(), encoding.upper())
