def _load_install_rdf(err, package, expectation):
    try:
        install_rdf = RDFParser(err, package.read('install.rdf'))
    except (RDFException, DefusedXmlException) as ex:
        if isinstance(ex, DefusedXmlException):
            url = 'https://pypi.python.org/pypi/defusedxml/0.3#attack-vectors'
            reason = 'Malicious XML was detected, see {0}.'.format(url)
            line = 0
        else:
            reason = 'Try validating your RDF with the W3 validator: http://www.w3.org/RDF/Validator/.'
            line = ex.line()
        err.error(err_id=('main', 'test_package', 'parse_error'), error='Could not parse `install.rdf`.', description=('The RDF parser was unable to parse the install.rdf file included with this add-on.', reason), filename='install.rdf', line=line)
        return
    else:
        if (install_rdf.rdf is None):
            err.error(err_id=('main', 'test_package', 'cannot_parse_installrdf'), error='Cannot read `install.rdf`', description='The install.rdf file could not be parsed.', filename='install.rdf')
            return
        else:
            err.save_resource('has_install_rdf', True, pushable=True)
            err.save_resource('install_rdf', install_rdf, pushable=True)
    results = detect_type(err, install_rdf, package)
    if (results is None):
        err.error(err_id=('main', 'test_package', 'undeterminable_type'), error='Unable to determine add-on type', description='The type detection algorithm could not determine the type of the add-on.')
        return
    else:
        err.detected_type = results
    if (expectation not in (PACKAGE_ANY, results)):
        err.warning(err_id=('main', 'test_package', 'extension_type_mismatch'), warning='Extension Type Mismatch', description=("We detected that the add-on's type does not match the expected type.", ('Type "%s" expected, found "%s"' % (types[expectation], types[results]))))
def _load_install_rdf(err, package, expectation):
    try:
        install_rdf = RDFParser(err, package.read('install.rdf'))
    except (RDFException, DefusedXmlException) as ex:
        if isinstance(ex, DefusedXmlException):
            url = 'https://pypi.python.org/pypi/defusedxml/0.3#attack-vectors'
            reason = 'Malicious XML was detected, see {0}.'.format(url)
            line = 0
        else:
            reason = 'Try validating your RDF with the W3 validator: http://www.w3.org/RDF/Validator/.'
            line = ex.line()
        err.error(err_id=('main', 'test_package', 'parse_error'), error='Could not parse `install.rdf`.', description=('The RDF parser was unable to parse the install.rdf file included with this add-on.', reason), filename='install.rdf', line=line)
        return
    else:
        if (install_rdf.rdf is None):
            err.error(err_id=('main', 'test_package', 'cannot_parse_installrdf'), error='Cannot read `install.rdf`', description='The install.rdf file could not be parsed.', filename='install.rdf')
            return
        else:
            err.save_resource('has_install_rdf', True, pushable=True)
            err.save_resource('install_rdf', install_rdf, pushable=True)
    results = detect_type(err, install_rdf, package)
    if (results is None):
        err.error(err_id=('main', 'test_package', 'undeterminable_type'), error='Unable to determine add-on type', description='The type detection algorithm could not determine the type of the add-on.')
        return
    else:
        err.detected_type = results
    if (expectation not in (PACKAGE_ANY, results)):
        err.warning(err_id=('main', 'test_package', 'extension_type_mismatch'), warning='Extension Type Mismatch', description=("We detected that the add-on's type does not match the expected type.", ('Type "%s" expected, found "%s"' % (types[expectation], types[results]))))