コード例 #1
0
def test_is_hidden(tmp_path):
    root = str(tmp_path)
    subdir1_path = tmp_path / 'subdir'
    subdir1_path.mkdir()
    subdir1 = str(subdir1_path)
    assert not is_hidden(subdir1, root)
    assert not is_file_hidden(subdir1)

    subdir2_path = tmp_path / '.subdir2'
    subdir2_path.mkdir()
    subdir2 = str(subdir2_path)
    assert is_hidden(subdir2, root)
    assert is_file_hidden(subdir2)

    subdir34_path = tmp_path / 'subdir3' / '.subdir4'
    subdir34_path.mkdir(parents=True)
    subdir34 = str(subdir34_path)
    assert is_hidden(subdir34, root)
    assert is_hidden(subdir34)

    subdir56_path = tmp_path / '.subdir5' / 'subdir6'
    subdir56_path.mkdir(parents=True)
    subdir56 = str(subdir56_path)
    assert is_hidden(subdir56, root)
    assert is_hidden(subdir56)
    assert not is_file_hidden(subdir56)
    assert not is_file_hidden(subdir56, os.stat(subdir56))
コード例 #2
0
ファイル: test_utils.py プロジェクト: willingc/jupyter_server
def test_is_hidden():
    with TemporaryDirectory() as root:
        subdir1 = os.path.join(root, 'subdir')
        os.makedirs(subdir1)
        nt.assert_equal(is_hidden(subdir1, root), False)
        nt.assert_equal(is_file_hidden(subdir1), False)

        subdir2 = os.path.join(root, '.subdir2')
        os.makedirs(subdir2)
        nt.assert_equal(is_hidden(subdir2, root), True)
        nt.assert_equal(is_file_hidden(subdir2), True)#
        # root dir is always visible
        nt.assert_equal(is_hidden(subdir2, subdir2), False)

        subdir34 = os.path.join(root, 'subdir3', '.subdir4')
        os.makedirs(subdir34)
        nt.assert_equal(is_hidden(subdir34, root), True)
        nt.assert_equal(is_hidden(subdir34), True)

        subdir56 = os.path.join(root, '.subdir5', 'subdir6')
        os.makedirs(subdir56)
        nt.assert_equal(is_hidden(subdir56, root), True)
        nt.assert_equal(is_hidden(subdir56), True)
        nt.assert_equal(is_file_hidden(subdir56), False)
        nt.assert_equal(is_file_hidden(subdir56, os.stat(subdir56)), False)
コード例 #3
0
ファイル: test_utils.py プロジェクト: fred521/jupyter_server
def test_is_hidden(tmp_path):
    root = str(tmp_path)
    subdir1_path = tmp_path / "subdir"
    subdir1_path.mkdir()
    subdir1 = str(subdir1_path)
    assert not is_hidden(subdir1, root)
    assert not is_file_hidden(subdir1)

    subdir2_path = tmp_path / ".subdir2"
    subdir2_path.mkdir()
    subdir2 = str(subdir2_path)
    assert is_hidden(subdir2, root)
    assert is_file_hidden(subdir2)

    subdir34_path = tmp_path / "subdir3" / ".subdir4"
    subdir34_path.mkdir(parents=True)
    subdir34 = str(subdir34_path)
    assert is_hidden(subdir34, root)
    assert is_hidden(subdir34)

    subdir56_path = tmp_path / ".subdir5" / "subdir6"
    subdir56_path.mkdir(parents=True)
    subdir56 = str(subdir56_path)
    assert is_hidden(subdir56, root)
    assert is_hidden(subdir56)
    assert not is_file_hidden(subdir56)
    assert not is_file_hidden(subdir56, os.stat(subdir56))
コード例 #4
0
def test_is_hidden_win32(tmp_path):
    root = str(tmp_path)
    root = cast_unicode(root)
    subdir1 = tmp_path / 'subdir'
    subdir1.mkdir()
    assert not is_hidden(str(subdir1), root)
    ctypes.windll.kernel32.SetFileAttributesW(str(subdir1), 0x02)
    assert is_hidden(str(subdir1), root)
    assert is_file_hidden(str(subdir1))
コード例 #5
0
    def _dir_model(self, path, content=True):
        """Build a model for a directory

        if content is requested, will include a listing of the directory
        """
        os_path = self._get_os_path(path)

        four_o_four = u"directory does not exist: %r" % path

        if not os.path.isdir(os_path):
            raise web.HTTPError(404, four_o_four)
        elif is_hidden(os_path, self.root_dir) and not self.allow_hidden:
            self.log.info(
                "Refusing to serve hidden directory %r, via 404 Error",
                os_path)
            raise web.HTTPError(404, four_o_four)

        model = self._base_model(path)
        model["type"] = "directory"
        model["size"] = None
        if content:
            model["content"] = contents = []
            os_dir = self._get_os_path(path)
            for name in os.listdir(os_dir):
                try:
                    os_path = os.path.join(os_dir, name)
                except UnicodeDecodeError as e:
                    self.log.warning("failed to decode filename '%s': %s",
                                     name, e)
                    continue

                try:
                    st = os.lstat(os_path)
                except OSError as e:
                    # skip over broken symlinks in listing
                    if e.errno == errno.ENOENT:
                        self.log.warning("%s doesn't exist", os_path)
                    else:
                        self.log.warning("Error stat-ing %s: %s", os_path, e)
                    continue

                if (not stat.S_ISLNK(st.st_mode)
                        and not stat.S_ISREG(st.st_mode)
                        and not stat.S_ISDIR(st.st_mode)):
                    self.log.debug("%s not a regular file", os_path)
                    continue

                if self.should_list(name):
                    if self.allow_hidden or not is_file_hidden(os_path,
                                                               stat_res=st):
                        contents.append(
                            self.get(path="%s/%s" % (path, name),
                                     content=False))

            model["format"] = "json"

        return model
コード例 #6
0
ファイル: test_utils.py プロジェクト: willingc/jupyter_server
def test_is_hidden_win32():
    with TemporaryDirectory() as root:
        root = cast_unicode(root)
        subdir1 = os.path.join(root, u'subdir')
        os.makedirs(subdir1)
        assert not is_hidden(subdir1, root)
        r = ctypes.windll.kernel32.SetFileAttributesW(subdir1, 0x02)
        print(r)
        assert is_hidden(subdir1, root)
        assert is_file_hidden(subdir1)