How to use the commoncode.compat.unicode function in commoncode

To help you get started, we’ve selected a few commoncode 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 / tests / packagedcode / test_rpm.py View on Github external
'license': 'LGPL',
            'name': 'python-glc',
            'os': 'linux',
            'packager': None,
            'release': '1',
            'patch': None,
            'source_rpm': None,
            'summary': 'ctypes Python bindings for QuesoGLC',
            'url': 'ftp://ftp.graviscom.de/pub/python-glc/',
            'vendor': 'Arno Pähler ',
            'version': '0.7.1',
        }

        assert expected == alltags
        # tests that tags are all unicode
        assert all([isinstance(v, compat.unicode) for v in alltags.values() if v])
github nexB / scancode-toolkit / src / cluecode / finder.py View on Github external
def get_ip(s):
    """
    Return True is string s is an IP address
    """
    if not is_ip(s):
        return False

    try:
        ip = ipaddress.ip_address(compat.unicode(s))
        return ip
    except ValueError:
        return False
github nexB / scancode-toolkit / src / extractcode / archive.py View on Github external
def extract_with_fallback(location, target_dir, extractor1, extractor2):
    """
    Extract archive at `location` to `target_dir` trying first `extractor1` function.
    If extract fails, attempt extraction again with the `extractor2` function.
    Return a list of warning messages. Raise exceptions on errors.

    Note: there are a few cases where the primary extractor for a type may fail and
    a secondary extractor will succeed.
    """
    abs_location = os.path.abspath(os.path.expanduser(location))
    abs_target_dir = compat.unicode(os.path.abspath(os.path.expanduser(target_dir)))
    # attempt extract first to a temp dir
    temp_target1 = compat.unicode(fileutils.get_temp_dir(prefix='scancode-extract1-'))
    try:
        warnings = extractor1(abs_location, temp_target1)
        if TRACE:
            logger.debug('extract_with_fallback: temp_target1: %(temp_target1)r' % locals())
        fileutils.copytree(temp_target1, abs_target_dir)
    except:
        try:
            temp_target2 = compat.unicode(fileutils.get_temp_dir(prefix='scancode-extract2-'))
            warnings = extractor2(abs_location, temp_target2)
            if TRACE:
                logger.debug('extract_with_fallback: temp_target2: %(temp_target2)r' % locals())
            fileutils.copytree(temp_target2, abs_target_dir)
        finally:
            fileutils.delete(temp_target2)
    finally:
        fileutils.delete(temp_target1)