示例#1
0
    def test_update_path_environment_windows_py2(self):
        class MockOs(object):
            environ = {'PATH': b'c:\\windows;C:Program Files'}
            pathsep = ';'

        unicode_path = u'c:\\bin\\foo\udcb1bar'
        command.update_path_environment(unicode_path, MockOs)
        assert {
            'PATH': 'c:\\bin\\foo?bar;c:\\windows;C:Program Files'
        } == MockOs.environ
示例#2
0
    def test_update_path_environment_windows_from_unicode(self):
        class MockOs(object):
            environ = {u'PATH': u'c:\\windows;C:Program Files'}
            pathsep = u';'

        unicode_path = u'foo\udcb1bar'
        command.update_path_environment(unicode_path, MockOs)
        assert {
            u'PATH': u'foo\udcb1bar;c:\\windows;C:Program Files'
        } == MockOs.environ

        unicode_path = u'foo\udcb1bar'
        command.update_path_environment(unicode_path, MockOs)
        assert {
            u'PATH': u'foo\udcb1bar;c:\\windows;C:Program Files'
        } == MockOs.environ
示例#3
0
def load_lib():
    """
    Return the loaded libmagic shared library object from vendored paths.
    """
    # FIXME: use command.load_lib instead
    root_dir = command.get_base_dirs(bin_dir)[0]
    _bin_dir, lib_dir = command.get_bin_lib_dirs(root_dir)
    magic_so = os.path.join(lib_dir, 'libmagic' + system.lib_ext)

    # add lib path to the front of the PATH env var
    command.update_path_environment(lib_dir)

    if os.path.exists(magic_so):
        if not isinstance(magic_so, bytes):
            # ensure that the path is not Unicode...
            magic_so = fsencode(magic_so)
        lib = ctypes.CDLL(magic_so)
        if lib and lib._name:
            return lib
    raise ImportError('Failed to load libmagic from %(magic_so)r' % locals())
示例#4
0
def load_lib():
    """
    Return the loaded libmagic shared library object from vendored paths.
    """
    # FIXME: use command.load_lib instead
    root_dir = command.get_base_dirs(bin_dir)[0]
    _bin_dir, lib_dir = command.get_bin_lib_dirs(root_dir)
    magic_so = os.path.join(lib_dir, 'libmagic' + system.lib_ext)

    # add lib path to the front of the PATH env var
    command.update_path_environment(lib_dir)

    if os.path.exists(magic_so):
        if not isinstance(magic_so, bytes):
            # ensure that the path is not Unicode...
            magic_so = fsencode(magic_so)
        lib = ctypes.CDLL(magic_so)
        if lib and lib._name:
            return lib
    raise ImportError('Failed to load libmagic from %(magic_so)r' % locals())
def load_lib():
    """
    Return the loaded libarchive shared library object from default "vendored" paths.
    e.g. this assumes that libarchive is stored in a well known location under
    exttractcode/bin with subdirectories for each supported OS.
    """
    # FIXME: use command.load_lib instead
    root_dir = command.get_base_dirs(extractcode.root_dir)[0]
    _bin_dir, lib_dir = command.get_bin_lib_dirs(root_dir)
    libarchive = os.path.join(lib_dir, 'libarchive' + system.lib_ext)

    # add lib path to the front of the PATH env var
    command.update_path_environment(lib_dir)

    if os.path.exists(libarchive):
        if not isinstance(libarchive, bytes):
            # ensure that the path is not Unicode...
            libarchive = fsencode(libarchive)
        lib = ctypes.CDLL(libarchive)
        if lib and lib._name:
            return lib
    raise ImportError('Failed to load libarchive: %(libarchive)s' % locals())
示例#6
0
    def test_update_path_environment_windows_from_unicode(self):
        class MockOs(object):
            environ = {b'PATH': b'c:\\windows;C:Program Files'}
            pathsep = b':'

        unicode_path = u'foo\udcb1bar'
        command.update_path_environment(unicode_path, MockOs)
        {'PATH': 'foo\xb1bar;c:\\windows;C:Program Files'}

        bytes_path = b'c:\\bin\\foo\xb1bar'
        command.update_path_environment(bytes_path, MockOs)
        {'PATH': 'c:\\bin\\foo\xb1bar;foo\xb1bar;c:\\windows;C:Program Files'}

        unicode_path = u'foo\udcb1bar'
        command.update_path_environment(unicode_path, MockOs)
        {'PATH': 'c:\\bin\\foo\xb1bar;foo\xb1bar;c:\\windows;C:Program Files'}
    def test_update_path_environment_windows_from_unicode(self):

        class MockOs(object):
            environ = {b'PATH': b'c:\\windows;C:Program Files'}
            pathsep = b':'

        unicode_path = u'foo\udcb1bar'
        command.update_path_environment(unicode_path, MockOs)
        {'PATH': 'foo\xb1bar;c:\\windows;C:Program Files'}

        bytes_path = b'c:\\bin\\foo\xb1bar'
        command.update_path_environment(bytes_path, MockOs)
        {'PATH': 'c:\\bin\\foo\xb1bar;foo\xb1bar;c:\\windows;C:Program Files'}

        unicode_path = u'foo\udcb1bar'
        command.update_path_environment(unicode_path, MockOs)
        {'PATH': 'c:\\bin\\foo\xb1bar;foo\xb1bar;c:\\windows;C:Program Files'}
    def test_update_path_environment_mac_from_unicode(self):

        class MockOs(object):
            environ = {b'PATH': b'/usr/bin:/usr/local'}
            pathsep = b':'

        unicode_path = u'foo\udcb1bar'
        command.update_path_environment(unicode_path, MockOs)
        assert {'PATH': 'foo\xb1bar:/usr/bin:/usr/local'} == MockOs.environ

        bytes_path = b'/bin/foo\xb1bar'
        command.update_path_environment(bytes_path, MockOs)
        assert {'PATH': '/bin/foo\xb1bar:foo\xb1bar:/usr/bin:/usr/local'} == MockOs.environ

        unicode_path = u'foo\udcb1bar'
        command.update_path_environment(unicode_path, MockOs)
        assert {'PATH': '/bin/foo\xb1bar:foo\xb1bar:/usr/bin:/usr/local'} == MockOs.environ
示例#9
0
    def test_update_path_environment_linux_from_unicode(self):
        class MockOs(object):

            if py2:
                environ = {b'PATH': b'/usr/bin:/usr/local'}
                pathsep = b':'
            else:
                environ = {'PATH': '/usr/bin:/usr/local'}
                pathsep = ':'

        unicode_path = u'foo\udcb1bar'
        command.update_path_environment(unicode_path, MockOs)

        if py2:
            assert {
                b'PATH': b'foo\xb1bar:/usr/bin:/usr/local'
            } == MockOs.environ
        else:
            assert {
                'PATH': 'foo\udcb1bar:/usr/bin:/usr/local'
            } == MockOs.environ

        bytes_path = b'/bin/foo\xb1bar'
        command.update_path_environment(bytes_path, MockOs)

        if py2:
            assert {
                b'PATH': b'/bin/foo\xb1bar:foo\xb1bar:/usr/bin:/usr/local'
            } == MockOs.environ
        else:
            assert {
                'PATH': '/bin/foo\udcb1bar:foo\udcb1bar:/usr/bin:/usr/local'
            } == MockOs.environ

        unicode_path = u'foo\udcb1bar'
        command.update_path_environment(unicode_path, MockOs)

        if py2:
            assert {
                b'PATH': b'/bin/foo\xb1bar:foo\xb1bar:/usr/bin:/usr/local'
            } == MockOs.environ
        else:
            assert {
                'PATH': '/bin/foo\udcb1bar:foo\udcb1bar:/usr/bin:/usr/local'
            } == MockOs.environ
示例#10
0
    def test_update_path_environment_mac_from_bytes(self):
        class MockOs(object):
            environ = {b'PATH': b'/usr/bin:/usr/local'}
            pathsep = b':'

        bytes_path = b'foo\xb1bar'
        command.update_path_environment(bytes_path, MockOs)
        assert {'PATH': 'foo\xb1bar:/usr/bin:/usr/local'} == MockOs.environ

        unicode_path = u'/bin/foo\udcb1bar'
        command.update_path_environment(unicode_path, MockOs)
        assert {
            'PATH': '/bin/foo\xb1bar:foo\xb1bar:/usr/bin:/usr/local'
        } == MockOs.environ

        bytes_path = b'foo\xb1bar'
        command.update_path_environment(bytes_path, MockOs)
        assert {
            'PATH': '/bin/foo\xb1bar:foo\xb1bar:/usr/bin:/usr/local'
        } == MockOs.environ