'Parse out DOCTYPE info from the given XML or HTML content.
Returns a tuple of the form:
(<has-doctype-decl>, <doctype-decl>,
<name>, <public-id>, <system-id>)
The <public-id> is normalized as per this comment in the XML 1.0
spec:
Before a match is attempted, all strings of white space in the
public identifier must be normalized to single space
characters (#x20), and leading and trailing white space must
be removed.
Examples:
(False, None, None, None, None)
(True, \'<!DOCTYPE greeting SYSTEM "hello.dtd">\',
\'greeting\', None, \'hello.dtd\'),
(True,
\'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\',
\'html\',
\'-//W3C//DTD XHTML 1.0 Transitional//EN\',
\'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\')
Here is the spec for DOCTYPE decls in XML:
http://www.xml.com/axml/target.html#NT-doctypedecl
We loosely follow this to allow for some decls in HTML that isn\'t
proper XML. As well, we are only parsing out decls that reference
an external ID, as opposed to those that define entities locally.'

def _get_doctype_decl_info(self, head):

    if ('<!DOCTYPE' not in head):
        return (False, None, None, None, None)
    m = self._doctype_decl_re.search(head)
    if (not m):
        return (False, None, None, None, None)
    d = m.groupdict()
    name = d.get('name')
    system_id = (d.get('system_id_a') or d.get('system_id_b'))
    public_id = d.get('public_id_b')
    if public_id:
        public_id = re.sub('\\s+', '    ', public_id.strip())
    return (True, m.group(0), name, public_id, system_id)
