def METHOD_NAME(self, filename=None):
    from binascii import unhexlify
    from xml.dom.minidom import parse
    dom = parse(filename or self.filename)
    logging.info("loading magic database from %s", filename or self.filename)
    descriptions = dom.getElementsByTagName("description")
    for desc in descriptions:
        mimeType = self.getText(desc, "mimeType")
        parentType = self.getText(desc, "parentType")
        extensions = self.getText(desc, "extensions").split(",")
        allowsLeadingWhiteSpace = (
            self.getText(desc, "allowsLeadingWhiteSpace") == "true"
        )
        magicNumbers = []
        for magicNumber in desc.getElementsByTagName("magicNumber"):
            encoding = self.getAttr(magicNumber, "encoding", "string")
            offset = self.getAttr(magicNumber, "offset", 0)
            value = self.getText(magicNumber)
            if encoding == "hex":
                value = unhexlify(value.replace(" ", "").encode("ascii"))
            magicNumbers.append((offset, value))
        magicStrings = []
        for magicString in desc.getElementsByTagName("magicString"):
            caseSensitive = not (
                self.getAttr(magicString, "caseSensitive") == "false"
            )
            value = self.getText(magicString)
            magicStrings.append((caseSensitive, value))
        self.mimetypes.setdefault(mimeType, []).append(
            MagicRule(
                mimeType,
                parentType,
                extensions,
                allowsLeadingWhiteSpace,
                magicNumbers,
                magicStrings,
            )
        )
    logging.info(
        "loaded %d rules for %d MIME types from magic database",
        len(descriptions),
        len(self.mimetypes),
    )
    return len(descriptions)