• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python qtutils.savefile_open函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中qutebrowser.utils.qtutils.savefile_open函数的典型用法代码示例。如果您正苦于以下问题:Python savefile_open函数的具体用法?Python savefile_open怎么用?Python savefile_open使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了savefile_open函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: save

    def save(self, name, last_window=False, load_next_time=False):
        """Save a named session.

        Args:
            last_window: If set, saves the saved self._last_window_session
                         instead of the currently open state.
            load_next_time: If set, prepares this session to be load next time.
        """
        path = self._get_session_path(name)

        log.misc.debug("Saving session {} to {}...".format(name, path))
        if last_window:
            data = self._last_window_session
            assert data is not None
        else:
            data = self._save_all()
        log.misc.vdebug("Saving data: {}".format(data))
        try:
            with qtutils.savefile_open(path) as f:
                yaml.dump(data, f, Dumper=YamlDumper, default_flow_style=False,
                          encoding='utf-8', allow_unicode=True)
        except (OSError, UnicodeEncodeError, yaml.YAMLError) as e:
            raise SessionError(e)
        else:
            self.update_completion.emit()
        if load_next_time:
            state_config = objreg.get('state-config')
            state_config['general']['session'] = name
开发者ID:JIVS,项目名称:qutebrowser,代码行数:28,代码来源:sessions.py


示例2: save

 def save(self):
     """Save the config file."""
     if not os.path.exists(self._configdir):
         os.makedirs(self._configdir, 0o755)
     log.destroy.debug("Saving config to {}".format(self._configfile))
     with qtutils.savefile_open(self._configfile) as f:
         self.write(f)
开发者ID:JIVS,项目名称:qutebrowser,代码行数:7,代码来源:ini.py


示例3: test_binary

 def test_binary(self, tmpdir):
     """Test with binary data."""
     filename = tmpdir / 'foo'
     with qtutils.savefile_open(str(filename), binary=True) as f:
         f.write(b'\xde\xad\xbe\xef')
     assert tmpdir.listdir() == [filename]
     assert filename.read_binary() == b'\xde\xad\xbe\xef'
开发者ID:t-wissmann,项目名称:qutebrowser,代码行数:7,代码来源:test_qtutils.py


示例4: save

 def save(self):
     """Save the key config file."""
     if self._configfile is None:
         return
     log.destroy.debug("Saving key config to {}".format(self._configfile))
     with qtutils.savefile_open(self._configfile, encoding='utf-8') as f:
         data = str(self)
         f.write(data)
开发者ID:addictedtoflames,项目名称:qutebrowser,代码行数:8,代码来源:keyconf.py


示例5: test_utf8

 def test_utf8(self, data, tmpdir):
     """Test with UTF8 data."""
     filename = tmpdir / 'foo'
     filename.write("Old data")
     with qtutils.savefile_open(str(filename)) as f:
         f.write(data)
     assert tmpdir.listdir() == [filename]
     assert filename.read_text(encoding='utf-8') == data
开发者ID:t-wissmann,项目名称:qutebrowser,代码行数:8,代码来源:test_qtutils.py


示例6: save

 def save(self):
     """Save the config file."""
     limit = config.get(*self._limit)
     if limit == 0:
         return
     self._prepare_save()
     with qtutils.savefile_open(self._configfile, self._binary) as f:
         self._write(f, self.data[-limit:])
开发者ID:JIVS,项目名称:qutebrowser,代码行数:8,代码来源:lineparser.py


示例7: save

 def save(self):
     """Save the config file."""
     if self._configdir is None:
         return
     configfile = os.path.join(self._configdir, self._fname)
     log.destroy.debug("Saving config to {}".format(configfile))
     with qtutils.savefile_open(configfile) as f:
         f.write(str(self))
开发者ID:LucasRMehl,项目名称:qutebrowser,代码行数:8,代码来源:config.py


示例8: test_failing_commit

    def test_failing_commit(self, tmpdir):
        """Test with the file being closed before committing."""
        filename = tmpdir / 'foo'
        with pytest.raises(OSError, match='Commit failed!'):
            with qtutils.savefile_open(str(filename), binary=True) as f:
                f.write(b'Hello')
                f.dev.cancelWriting()  # provoke failing commit

        assert tmpdir.listdir() == []
开发者ID:Harrison97,项目名称:qutebrowser,代码行数:9,代码来源:test_qtutils.py


示例9: test_failing_flush

    def test_failing_flush(self, tmpdir):
        """Test with the file being closed before flushing."""
        filename = tmpdir / 'foo'
        with pytest.raises(ValueError, match="IO operation on closed device!"):
            with qtutils.savefile_open(str(filename), binary=True) as f:
                f.write(b'Hello')
                f.dev.commit()  # provoke failing flush

        assert tmpdir.listdir() == [filename]
开发者ID:Harrison97,项目名称:qutebrowser,代码行数:9,代码来源:test_qtutils.py


示例10: _save

    def _save(self):
        """Save the changed settings to the YAML file."""
        data = {'config_version': self.VERSION, 'global': self.values}
        with qtutils.savefile_open(self._filename) as f:
            f.write(textwrap.dedent("""
                # DO NOT edit this file by hand, qutebrowser will overwrite it.
                # Instead, create a config.py - see :help for details.

            """.lstrip('\n')))
            utils.yaml_dump(data, f)
开发者ID:swalladge,项目名称:qutebrowser,代码行数:10,代码来源:configfiles.py


示例11: test_mock_exception

    def test_mock_exception(self, qsavefile_mock):
        """Test with a mock and an exception in the block."""
        qsavefile_mock.open.return_value = True

        with pytest.raises(SavefileTestException):
            with qtutils.savefile_open('filename'):
                raise SavefileTestException

        qsavefile_mock.open.assert_called_once_with(QIODevice.WriteOnly)
        qsavefile_mock.cancelWriting.assert_called_once_with()
开发者ID:t-wissmann,项目名称:qutebrowser,代码行数:10,代码来源:test_qtutils.py


示例12: save

 def save(self):
     """Save the config file."""
     limit = -1 if self._limit is None else config.get(*self._limit)
     if limit == 0:
         return
     if not os.path.exists(self._configdir):
         os.makedirs(self._configdir, 0o755)
     log.destroy.debug("Saving config to {}".format(self._configfile))
     with qtutils.savefile_open(self._configfile, self._binary) as f:
         self.write(f, limit)
开发者ID:HalosGhost,项目名称:qutebrowser,代码行数:10,代码来源:line.py


示例13: test_failing_flush

    def test_failing_flush(self, tmpdir):
        """Test with the file being closed before flushing."""
        filename = tmpdir / "foo"
        with pytest.raises(ValueError) as excinfo:
            with qtutils.savefile_open(str(filename), binary=True) as f:
                f.write(b"Hello")
                f.dev.commit()  # provoke failing flush

        assert str(excinfo.value) == "IO operation on closed device!"
        assert tmpdir.listdir() == [filename]
开发者ID:halfwit,项目名称:qutebrowser,代码行数:10,代码来源:test_qtutils.py


示例14: test_existing_dir

 def test_existing_dir(self, tmpdir):
     """Test with the filename already occupied by a directory."""
     filename = tmpdir / "foo"
     filename.mkdir()
     with pytest.raises(OSError) as excinfo:
         with qtutils.savefile_open(str(filename)):
             pass
     errors = ["Filename refers to a directory", "Commit failed!"]  # Qt >= 5.4  # older Qt versions
     assert str(excinfo.value) in errors
     assert tmpdir.listdir() == [filename]
开发者ID:halfwit,项目名称:qutebrowser,代码行数:10,代码来源:test_qtutils.py


示例15: test_failing_commit

    def test_failing_commit(self, tmpdir):
        """Test with the file being closed before comitting."""
        filename = tmpdir / 'foo'
        with pytest.raises(OSError) as excinfo:
            with qtutils.savefile_open(str(filename), binary=True) as f:
                f.write(b'Hello')
                f.dev.commit()  # provoke failing "real" commit

        assert str(excinfo.value) == "Commit failed!"
        assert tmpdir.listdir() == [filename]
开发者ID:t-wissmann,项目名称:qutebrowser,代码行数:10,代码来源:test_qtutils.py


示例16: test_exception

 def test_exception(self, tmpdir):
     """Test with an exception in the block."""
     filename = tmpdir / 'foo'
     filename.write("Old content")
     with pytest.raises(SavefileTestException):
         with qtutils.savefile_open(str(filename)) as f:
             f.write("Hello World!")
             raise SavefileTestException
     assert tmpdir.listdir() == [filename]
     assert filename.read_text(encoding='utf-8') == "Old content"
开发者ID:t-wissmann,项目名称:qutebrowser,代码行数:10,代码来源:test_qtutils.py


示例17: save

 def save(self):
     """Save the config file."""
     limit = config.get(*self._limit)
     if limit == 0:
         return
     do_save = self._prepare_save()
     if not do_save:
         return
     assert self._configfile is not None
     with qtutils.savefile_open(self._configfile, self._binary) as f:
         self._write(f, self.data[-limit:])
开发者ID:vyp,项目名称:qutebrowser,代码行数:11,代码来源:lineparser.py


示例18: test_mock_open_error

    def test_mock_open_error(self, qsavefile_mock):
        """Test with a mock and a failing open()."""
        qsavefile_mock.open.return_value = False
        qsavefile_mock.errorString.return_value = "Hello World"

        with pytest.raises(OSError, match="Hello World"):
            with qtutils.savefile_open('filename'):
                pass

        qsavefile_mock.open.assert_called_once_with(QIODevice.WriteOnly)
        qsavefile_mock.cancelWriting.assert_called_once_with()
开发者ID:Harrison97,项目名称:qutebrowser,代码行数:11,代码来源:test_qtutils.py


示例19: test_mock_commit_failed

    def test_mock_commit_failed(self, qsavefile_mock):
        """Test with a mock and an exception in the block."""
        qsavefile_mock.open.return_value = True
        qsavefile_mock.commit.return_value = False

        with pytest.raises(OSError, match="Commit failed!"):
            with qtutils.savefile_open('filename'):
                pass

        qsavefile_mock.open.assert_called_once_with(QIODevice.WriteOnly)
        assert not qsavefile_mock.cancelWriting.called
        assert not qsavefile_mock.errorString.called
开发者ID:Harrison97,项目名称:qutebrowser,代码行数:12,代码来源:test_qtutils.py


示例20: test_line_endings

    def test_line_endings(self, tmpdir):
        """Make sure line endings are translated correctly.

        See https://github.com/The-Compiler/qutebrowser/issues/309
        """
        filename = tmpdir / 'foo'
        with qtutils.savefile_open(str(filename)) as f:
            f.write('foo\nbar\nbaz')
        data = filename.read_binary()
        if os.name == 'nt':
            assert data == b'foo\r\nbar\r\nbaz'
        else:
            assert data == b'foo\nbar\nbaz'
开发者ID:t-wissmann,项目名称:qutebrowser,代码行数:13,代码来源:test_qtutils.py



注:本文中的qutebrowser.utils.qtutils.savefile_open函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python qtutils.serialize函数代码示例发布时间:2022-05-26
下一篇:
Python qtutils.get_args函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap