当前位置: 首页>>代码示例>>Python>>正文


Python builtins.open方法代码示例

本文整理汇总了Python中six.moves.builtins.open方法的典型用法代码示例。如果您正苦于以下问题:Python builtins.open方法的具体用法?Python builtins.open怎么用?Python builtins.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在six.moves.builtins的用法示例。


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

示例1: setUp

# 需要导入模块: from six.moves import builtins [as 别名]
# 或者: from six.moves.builtins import open [as 别名]
def setUp(self):
    super(DeployImplTest, self).setUp()
    # Save the real modules for clean up.
    self.real_open = builtins.open
    # Create a fake file system and stub out builtin modules.
    self.fs = fake_filesystem.FakeFilesystem()
    self.os = fake_filesystem.FakeOsModule(self.fs)
    self.open = fake_filesystem.FakeFileOpen(self.fs)
    self.shutil = fake_filesystem_shutil.FakeShutilModule(self.fs)
    self.stubs = mox3_stubout.StubOutForTesting()
    self.stubs.SmartSet(builtins, 'open', self.open)
    self.stubs.SmartSet(deploy_impl, 'os', self.os)
    self.stubs.SmartSet(deploy_impl, 'shutil', self.shutil)
    # Populate the fake file system with the expected directories and files.
    self.fs.CreateDirectory('/this/is/a/workspace/loaner/web_app/frontend/dist')
    self.fs.CreateDirectory('/this/is/a/workspace/loaner/chrome_app/dist')
    self.fs.CreateFile('/this/is/a/workspace/loaner/web_app/app.yaml')
    self.fs.CreateFile('/this/is/a/workspace/loaner/web_app/endpoints.yaml') 
开发者ID:google,项目名称:loaner,代码行数:20,代码来源:deploy_impl_test.py

示例2: open

# 需要导入模块: from six.moves import builtins [as 别名]
# 或者: from six.moves.builtins import open [as 别名]
def open(patch, name, mode="r", buffering=0):
    """
	Open a file, returning an object of the file type described in section
	File Objects.
	If the file cannot be opened, IOError is raised.
	When opening a file, its preferable to use open() instead of invoking
	the file constructor directly.
	"""
    path = os.path.abspath(os.path.join(os.getcwd(), name))
    manager = get_manager()
    fsi, relpath, readonly = manager.get_fsi(path)
    if fsi is None:
        return _org_open(relpath, mode, buffering)
    elif (("w" in mode) or ("a" in mode) or ("+" in mode)) and readonly:
        raise IOError("[Errno 1] Operation not permitted: '{p}'".format(p=path))
    else:
        try:
            return fsi.open(relpath, mode, buffering)
        except OperationFailure:
            raise os.error("[Errno 2] No such file or directory: '{p}'".format(p=path)) 
开发者ID:ywangd,项目名称:stash,代码行数:22,代码来源:mount_base.py

示例3: tearDown

# 需要导入模块: from six.moves import builtins [as 别名]
# 或者: from six.moves.builtins import open [as 别名]
def tearDown(self):
    super(DeployImplTest, self).tearDown()
    self.stubs.UnsetAll()
    builtins.open = self.real_open 
开发者ID:google,项目名称:loaner,代码行数:6,代码来源:deploy_impl_test.py

示例4: testManifestCheck

# 需要导入模块: from six.moves import builtins [as 别名]
# 或者: from six.moves.builtins import open [as 别名]
def testManifestCheck(self, mock_rawinput):
    """Test the manifest file check opens and loads json data."""
    file_name = '/this/is/a/workspace/loaner/chrome_app/manifest.json'
    self.fs.CreateFile(file_name, contents=_CORRECT_JSON)
    test_chrome_app_config = self.CreateTestChromeAppConfig()
    test_chrome_app_config._ManifestCheck()
    assert mock_rawinput.call_count == 1
    with open(file_name, 'r') as f:
      data = json.load(f)
      assert data['version'] == '1.0' 
开发者ID:google,项目名称:loaner,代码行数:12,代码来源:deploy_impl_test.py

示例5: setUp

# 需要导入模块: from six.moves import builtins [as 别名]
# 或者: from six.moves.builtins import open [as 别名]
def setUp(self):
    super(ManagerTest, self).setUp()
    # Save the real modules for clean up.
    self.real_open = builtins.open
    # Create a fake file system and stub out builtin modules.
    self.fs = fake_filesystem.FakeFilesystem()
    self.os = fake_filesystem.FakeOsModule(self.fs)
    self.open = fake_filesystem.FakeFileOpen(self.fs)
    self.stdout = StringIO()
    self.stubs = mox3_stubout.StubOutForTesting()
    self.stubs.SmartSet(builtins, 'open', self.open)
    self.stubs.SmartSet(common, 'os', self.os)
    self.stubs.SmartSet(sys, 'stdout', self.stdout)

    # Setup Testdata.
    self._testdata_path = '/testdata'
    self._valid_config_path = self._testdata_path + '/valid_config.yaml'
    self._blank_config_path = self._testdata_path + '/blank_config.yaml'

    self.fs.CreateFile(self._valid_config_path, contents=_VALID_CONFIG)
    self.fs.CreateFile(self._blank_config_path, contents=_BLANK_CONFIG)

    # Load the default config.
    self._valid_default_config = common.ProjectConfig.from_yaml(
        common.DEFAULT, self._valid_config_path)

    # Create test constants.
    self._constants = {
        'test': app_constants.Constant(
            'test', 'message', '',
            parser=utils.StringParser(allow_empty_string=False),),
        'other': app_constants.Constant('other', 'other message', 'value'),
    }

    # Mock out the authentication credentials.
    self.auth_patcher = mock.patch.object(auth, 'CloudCredentials')
    self.mock_creds = self.auth_patcher.start()
    self.mock_creds.return_value.get_credentials.return_value = (
        credentials.AnonymousCredentials()) 
开发者ID:google,项目名称:loaner,代码行数:41,代码来源:gng_impl_test.py

示例6: tearDown

# 需要导入模块: from six.moves import builtins [as 别名]
# 或者: from six.moves.builtins import open [as 别名]
def tearDown(self):
    super(ManagerTest, self).tearDown()
    self.stubs.UnsetAll()
    builtins.open = self.real_open

    self.auth_patcher.stop() 
开发者ID:google,项目名称:loaner,代码行数:8,代码来源:gng_impl_test.py

示例7: _execfile

# 需要导入模块: from six.moves import builtins [as 别名]
# 或者: from six.moves.builtins import open [as 别名]
def _execfile(filename, globals, locals=None):
    """
    Python 3 implementation of execfile.
    """
    mode = 'rb'
    with open(filename, mode) as stream:
        script = stream.read()
    # compile() function in Python 2.6 and 3.1 requires LF line endings.
    if sys.version_info[:2] < (2, 7) or sys.version_info[:2] >= (3, 0) and sys.version_info[:2] < (3, 2):
        script = script.replace(b'\r\n', b'\n')
        script = script.replace(b'\r', b'\n')
    if locals is None:
        locals = globals
    code = compile(script, filename, 'exec')
    exec(code, globals, locals) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:17,代码来源:sandbox.py

示例8: run

# 需要导入模块: from six.moves import builtins [as 别名]
# 或者: from six.moves.builtins import open [as 别名]
def run(self, func):
        """Run 'func' under os sandboxing"""
        try:
            self._copy(self)
            if _file:
                builtins.file = self._file
            builtins.open = self._open
            self._active = True
            return func()
        finally:
            self._active = False
            if _file:
                builtins.file = _file
            builtins.open = _open
            self._copy(_os) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:17,代码来源:sandbox.py

示例9: _open

# 需要导入模块: from six.moves import builtins [as 别名]
# 或者: from six.moves.builtins import open [as 别名]
def _open(self, path, mode='r', *args, **kw):
        if mode not in ('r', 'rt', 'rb', 'rU', 'U') and not self._ok(path):
            self._violation("open", path, mode, *args, **kw)
        return _open(path, mode, *args, **kw) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:6,代码来源:sandbox.py

示例10: open

# 需要导入模块: from six.moves import builtins [as 别名]
# 或者: from six.moves.builtins import open [as 别名]
def open(self, file, flags, mode=0o777, *args, **kw):
        """Called for low-level os.open()"""
        if flags & WRITE_FLAGS and not self._ok(file):
            self._violation("os.open", file, flags, mode, *args, **kw)
        return _os.open(file, flags, mode, *args, **kw) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:7,代码来源:sandbox.py

示例11: open

# 需要导入模块: from six.moves import builtins [as 别名]
# 或者: from six.moves.builtins import open [as 别名]
def open(path, *args, **kwargs):  # pylint: disable=redefined-builtin
  return builtins.open(extend(path), *args, **kwargs)


## os 
开发者ID:luci,项目名称:luci-py,代码行数:7,代码来源:fs.py

示例12: test_release_file

# 需要导入模块: from six.moves import builtins [as 别名]
# 或者: from six.moves.builtins import open [as 别名]
def test_release_file(self):
        version.loaded = False
        real_open = builtins.open
        real_find_file = cfg.CONF.find_file

        def fake_find_file(self, name):
            if name == "release":
                return "/etc/masakari/release"
            return real_find_file(self, name)

        def fake_open(path, *args, **kwargs):
            if path == "/etc/masakari/release":
                data = """[Masakari]
vendor = ACME Corporation
product = ACME Masakari
package = 1337"""
                return six.StringIO(data)

            return real_open(path, *args, **kwargs)

        self.stub_out('six.moves.builtins.open', fake_open)
        self.stub_out('oslo_config.cfg.ConfigOpts.find_file', fake_find_file)

        self.assertEqual(version.vendor_string(), "ACME Corporation")
        self.assertEqual(version.product_string(), "ACME Masakari")
        self.assertEqual(version.package_string(), "1337") 
开发者ID:openstack,项目名称:masakari,代码行数:28,代码来源:test_versions.py

示例13: open

# 需要导入模块: from six.moves import builtins [as 别名]
# 或者: from six.moves.builtins import open [as 别名]
def open(filename, mode="rb", compresslevel=9):
    """Shorthand for GzipFile(filename, mode, compresslevel).

    The filename argument is required; mode defaults to 'rb'
    and compresslevel defaults to 9.

    """
    return GzipFile(filename, mode, compresslevel) 
开发者ID:google,项目名称:apitools,代码行数:10,代码来源:gzip.py

示例14: open

# 需要导入模块: from six.moves import builtins [as 别名]
# 或者: from six.moves.builtins import open [as 别名]
def open(self, path, mode):
        """Wrapper on __builtin__.open used to simplify unit testing."""
        from six.moves import builtins
        return builtins.open(path, mode) 
开发者ID:openstack,项目名称:os-win,代码行数:6,代码来源:pathutils.py

示例15: temporary_file

# 需要导入模块: from six.moves import builtins [as 别名]
# 或者: from six.moves.builtins import open [as 别名]
def temporary_file(self, suffix=None, *args, **kwargs):
        """Creates a random, temporary, closed file, returning the file's

        path. It's different from tempfile.NamedTemporaryFile which returns
        an open file descriptor.
        """

        tmp_file_path = None
        try:
            tmp_file_path = self.create_temporary_file(suffix, *args, **kwargs)
            yield tmp_file_path
        finally:
            if tmp_file_path:
                fileutils.delete_if_exists(tmp_file_path) 
开发者ID:openstack,项目名称:os-win,代码行数:16,代码来源:pathutils.py


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