@staticmethod
def _guess_encoding_from_content(content_type, webpage_bytes):
    m = re.match('[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+\\s*;\\s*charset=(.+)', content_type)
    if m:
        encoding = m.group(1)
    else:
        m = re.search(b'<meta[^>]+charset=[\\\'"]?([^\\\'")]+)[ /\\\'">]', webpage_bytes[:1024])
        if m:
            encoding = m.group(1).decode('ascii')
        elif webpage_bytes.startswith(b'\xff\xfe'):
            encoding = 'utf-16'
        else:
            encoding = 'utf-8'
    return encoding
@staticmethod
def _guess_encoding_from_content(content_type, webpage_bytes):
    m = re.match('[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+\\s*;\\s*charset=(.+)', content_type)
    if m:
        encoding = m.group(1)
    else:
        m = re.search(b'<meta[^>]+charset=[\\\'"]?([^\\\'")]+)[ /\\\'">]', webpage_bytes[:1024])
        if m:
            encoding = m.group(1).decode('ascii')
        elif webpage_bytes.startswith(b'\xff\xfe'):
            encoding = 'utf-16'
        else:
            encoding = 'utf-8'
    return encoding