How to use the extractcode.ExtractWarningIncorrectEntry function in extractcode

To help you get started, we’ve selected a few extractcode examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nexB / scancode-toolkit / src / extractcode / sevenzip.py View on Github external
# we more than one a header, confusion entails.
        raise ExtractWarningIncorrectEntry('Incorrect 7zip listing with multiple headers')

    if len(header_tail) == 1:
        # we have only a header, likely an error condition or an empty archive
        return []

    _header, body = header_tail
    body_and_footer = re.split('\n\n\n', body, flags=re.MULTILINE)
    no_footer = len(body_and_footer) == 1
    multiple_footers = len(body_and_footer) > 2
    _footer = ''
    if no_footer:
        body = body_and_footer[0]
    elif multiple_footers:
        raise ExtractWarningIncorrectEntry('Incorrect 7zip listing with multiple footers')
    else:
        body, _footer == body_and_footer

    # FIXME: do something with header and footer?

    entries = []
    paths = re.split('\n\n', body, flags=re.MULTILINE)
    for path in paths:
        is_err = False
        errors = []
        infos = {}
        lines = path.splitlines(False)
        for line in lines:
            line = line.strip()
            if not line:
                continue
github nexB / scancode-toolkit / src / extractcode / sevenzip.py View on Github external
for line in lines:
            line = line.strip()
            if not line:
                continue
            if line.startswith(('Open Warning:', 'Errors:', 'Warnings:')):
                is_err = True
                messages = line.split(':', 1)
                errors.append(messages)
                continue
            if '=' not in line and is_err:
                # not a key = value line, an error message
                errors.append(line)
                continue
            parts = line.split('=', 1)
            if len(parts) != 2:
                raise ExtractWarningIncorrectEntry('Incorrect 7zip listing line with no key=value')
            is_err = False
            key, value = parts
            assert key not in infos, 'Duplicate keys in 7zip listing'
            infos[key.strip()] = value.strip() or ''
        if infos:
            entries.append(as_entry(infos))

    return entries
github nexB / scancode-toolkit / src / extractcode / sevenzip.py View on Github external
- blank line
    - two blank lines
    - footer sometimes with lines with summary stats
        such as Warnings: 1 Errors: 1
    - a line with two or more dashes or an empty line
    """
    if utf:
        text = codecs.open(location, encoding='UTF-8').read()
        text = text.replace(u'\r\n', u'\n')
    else:
        text = open(location, 'rb').read()

    header_tail = re.split('\n----------\n', text, flags=re.MULTILINE)
    if len(header_tail) != 2:
        # we more than one a header, confusion entails.
        raise ExtractWarningIncorrectEntry('Incorrect 7zip listing with multiple headers')

    if len(header_tail) == 1:
        # we have only a header, likely an error condition or an empty archive
        return []

    _header, body = header_tail
    body_and_footer = re.split('\n\n\n', body, flags=re.MULTILINE)
    no_footer = len(body_and_footer) == 1
    multiple_footers = len(body_and_footer) > 2
    _footer = ''
    if no_footer:
        body = body_and_footer[0]
    elif multiple_footers:
        raise ExtractWarningIncorrectEntry('Incorrect 7zip listing with multiple footers')
    else:
        body, _footer == body_and_footer
github nexB / scancode-toolkit / src / extractcode / sevenzip.py View on Github external
e.is_broken_link = False
    e.mode = infos.get('Mode', '')
    e.user = infos.get('User')
    e.group = infos.get('Group')
    e.is_special = False
    e.is_hardlink = False
    sl = infos.get('Symbolic Link')
    if sl:
        e.is_symlink = True
        e.link_target = sl
    hl = infos.get('Hard Link')
    if hl:
        e.is_hardlink = True
        e.link_target = hl
    if sl and hl:
        raise ExtractWarningIncorrectEntry('A Symlink cannot be a hardlink too')
    e.linkcount = infos.get('Links', 0)
    e.host = infos.get('Host OS')
    e.comment = infos.get('Comment')
    e.encrypted = infos.get('Encrypted')
    return e