示例#1
0
def run_checks(container):

    errors = []

    # Check parsing
    xml_items, html_items, raster_images, stylesheets = [], [], [], []
    for name, mt in container.mime_map.iteritems():
        items = None
        if mt in XML_TYPES:
            items = xml_items
        elif mt in OEB_DOCS:
            items = html_items
        elif mt in OEB_STYLES:
            items = stylesheets
        elif is_raster_image(mt):
            items = raster_images
        if items is not None:
            items.append((name, mt, container.open(name, "rb").read()))
    errors.extend(run_checkers(check_html_size, html_items))
    errors.extend(run_checkers(check_xml_parsing, xml_items))
    errors.extend(run_checkers(check_xml_parsing, html_items))
    errors.extend(run_checkers(check_raster_images, raster_images))

    for err in errors:
        if err.level > WARN:
            return errors

    # cssutils is not thread safe
    for name, mt, raw in stylesheets:
        if not raw:
            errors.append(EmptyFile(name))
            continue
        errors.extend(check_css_parsing(name, raw))

    for name, mt, raw in html_items + xml_items:
        errors.extend(check_encoding_declarations(name, container))

    for name, mt, raw in html_items:
        if not raw:
            continue
        root = container.parsed(name)
        for style in root.xpath('//*[local-name()="style"]'):
            if style.get("type", "text/css") == "text/css" and style.text:
                errors.extend(check_css_parsing(name, style.text, line_offset=style.sourceline - 1))
        for elem in root.xpath("//*[@style]"):
            raw = elem.get("style")
            if raw:
                errors.extend(check_css_parsing(name, raw, line_offset=elem.sourceline - 1, is_declaration=True))

    errors += check_mimetypes(container)
    errors += check_links(container) + check_link_destinations(container)
    errors += check_fonts(container)
    errors += check_filenames(container)
    errors += check_ids(container)
    errors += check_markup(container)
    errors += check_opf(container)

    return errors
示例#2
0
文件: main.py 项目: wynick27/calibre
def run_checks(container):

    errors = []

    # Check parsing
    xml_items, html_items, raster_images, stylesheets = [], [], [], []
    for name, mt in container.mime_map.iteritems():
        items = None
        if mt in XML_TYPES:
            items = xml_items
        elif mt in OEB_DOCS:
            items = html_items
        elif mt in OEB_STYLES:
            items = stylesheets
        elif is_raster_image(mt):
            items = raster_images
        if items is not None:
            items.append((name, mt, container.open(name, 'rb').read()))
    errors.extend(run_checkers(check_html_size, html_items))
    errors.extend(run_checkers(check_xml_parsing, xml_items))
    errors.extend(run_checkers(check_xml_parsing, html_items))
    errors.extend(run_checkers(check_raster_images, raster_images))

    for err in errors:
        if err.level > WARN:
            return errors

    # cssutils is not thread safe
    for name, mt, raw in stylesheets:
        if not raw:
            errors.append(EmptyFile(name))
            continue
        errors.extend(check_css_parsing(name, raw))

    for name, mt, raw in html_items + xml_items:
        errors.extend(check_encoding_declarations(name, container))

    for name, mt, raw in html_items:
        if not raw:
            continue
        root = container.parsed(name)
        for style in root.xpath('//*[local-name()="style"]'):
            if style.get('type', 'text/css') == 'text/css' and style.text:
                errors.extend(check_css_parsing(name, style.text, line_offset=style.sourceline - 1))
        for elem in root.xpath('//*[@style]'):
            raw = elem.get('style')
            if raw:
                errors.extend(check_css_parsing(name, raw, line_offset=elem.sourceline - 1, is_declaration=True))

    errors += check_mimetypes(container)
    errors += check_links(container) + check_link_destinations(container)
    errors += check_fonts(container)
    errors += check_ids(container)
    errors += check_filenames(container)
    errors += check_markup(container)
    errors += check_opf(container)

    return errors
示例#3
0
文件: main.py 项目: kmshi/calibre
def run_checks(container):

    errors = []

    # Check parsing
    xml_items, html_items, raster_images, stylesheets = [], [], [], []
    for name, mt in container.mime_map.iteritems():
        items = None
        if mt in XML_TYPES:
            items = xml_items
        elif mt in OEB_DOCS:
            items = html_items
        elif mt in OEB_STYLES:
            items = stylesheets
        elif is_raster_image(mt):
            items = raster_images
        if items is not None:
            items.append((name, mt, container.open(name, 'rb').read()))
    errors.extend(run_checkers(check_xml_parsing, xml_items))
    errors.extend(run_checkers(check_xml_parsing, html_items))
    errors.extend(run_checkers(check_raster_images, raster_images))

    # cssutils is not thread safe
    for name, mt, raw in stylesheets:
        errors.extend(check_css_parsing(name, raw))
    for name, mt, raw in html_items:
        root = container.parsed(name)
        for style in root.xpath('//*[local-name()="style"]'):
            if style.get('type', 'text/css') == 'text/css':
                errors.extend(
                    check_css_parsing(name,
                                      style.text,
                                      line_offset=style.sourceline - 1))
        for elem in root.xpath('//*[@style]'):
            raw = elem.get('style')
            if raw:
                errors.extend(
                    check_css_parsing(name,
                                      raw,
                                      line_offset=elem.sourceline - 1,
                                      is_declaration=True))

    errors += check_links(container)
    errors += check_fonts(container)

    return errors
示例#4
0
文件: main.py 项目: kutanari/calibre
def run_checks(container):

    errors = []

    # Check parsing
    xml_items, html_items = [], []
    for name, mt in container.mime_map.iteritems():
        items = None
        if mt in XML_TYPES:
            items = xml_items
        elif mt in OEB_DOCS:
            items = html_items
        if items is not None:
            items.append((name, mt, container.open(name, 'rb').read()))
    errors.extend(run_checkers(check_xml_parsing, xml_items))
    errors.extend(run_checkers(check_xml_parsing, html_items))

    return errors
示例#5
0
文件: main.py 项目: Hainish/calibre
def run_checks(container):

    errors = []

    # Check parsing
    xml_items, html_items, raster_images, stylesheets = [], [], [], []
    for name, mt in container.mime_map.iteritems():
        items = None
        if mt in XML_TYPES:
            items = xml_items
        elif mt in OEB_DOCS:
            items = html_items
        elif mt in OEB_STYLES:
            items = stylesheets
        elif is_raster_image(mt):
            items = raster_images
        if items is not None:
            items.append((name, mt, container.open(name, 'rb').read()))
    errors.extend(run_checkers(check_html_size, html_items))
    errors.extend(run_checkers(check_xml_parsing, xml_items))
    errors.extend(run_checkers(check_xml_parsing, html_items))
    errors.extend(run_checkers(check_raster_images, raster_images))

    # cssutils is not thread safe
    for name, mt, raw in stylesheets:
        errors.extend(check_css_parsing(name, raw))
    for name, mt, raw in html_items:
        root = container.parsed(name)
        for style in root.xpath('//*[local-name()="style"]'):
            if style.get('type', 'text/css') == 'text/css' and style.text:
                errors.extend(check_css_parsing(name, style.text, line_offset=style.sourceline - 1))
        for elem in root.xpath('//*[@style]'):
            raw = elem.get('style')
            if raw:
                errors.extend(check_css_parsing(name, raw, line_offset=elem.sourceline - 1, is_declaration=True))

    errors += check_mimetypes(container)
    errors += check_links(container) + check_link_destinations(container)
    errors += check_fonts(container)
    errors += check_filenames(container)
    errors += check_ids(container)
    errors += check_opf(container)

    return errors