本文整理汇总了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')
示例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))
示例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
示例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'
示例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())
示例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()
示例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)
示例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)
示例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)
示例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)
示例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
示例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")
示例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)
示例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)
示例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)