本文整理匯總了Python中builtins.open方法的典型用法代碼示例。如果您正苦於以下問題:Python builtins.open方法的具體用法?Python builtins.open怎麽用?Python builtins.open使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類builtins
的用法示例。
在下文中一共展示了builtins.open方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import open [as 別名]
def __init__(self, pos_features, pipeline_obj_path):
"""
Args:
pos_features: list of positional features to use
pipeline_obj_path: path to the serialized pipeline obj_path
"""
self.pos_features = pos_features
self.pipeline_obj_path = pipeline_obj_path
# deserialize the pickle file
with open(self.pipeline_obj_path, "rb") as f:
pipeline_obj = pickle.load(f)
self.POS_FEATURES = pipeline_obj[0]
self.minmax_scaler = pipeline_obj[1]
self.imp = pipeline_obj[2]
self.funct_transform = FunctionTransformer(func=sign_log_func,
inverse_func=sign_log_func_inverse)
# for simplicity, assume all current pos_features are the
# same as from before
assert self.POS_FEATURES == self.pos_features
示例2: __init__
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import open [as 別名]
def __init__(self, stream, errors='strict'):
""" Creates a StreamWriter instance.
stream must be a file-like object open for writing
(binary) data.
The StreamWriter may use different error handling
schemes by providing the errors keyword argument. These
parameters are predefined:
'strict' - raise a ValueError (or a subclass)
'ignore' - ignore the character and continue with the next
'replace'- replace with a suitable replacement character
'xmlcharrefreplace' - Replace with the appropriate XML
character reference.
'backslashreplace' - Replace with backslashed escape
sequences (only for encoding).
The set of allowed parameter values can be extended via
register_error.
"""
self.stream = stream
self.errors = errors
示例3: setUp
# 需要導入模塊: import builtins [as 別名]
# 或者: from 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')
示例4: setUp
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import open [as 別名]
def setUp(self):
super(AuthTest, self).setUp()
self._test_project = 'test_project'
self._test_client_id = 'test_client_id'
self._test_client_secret = 'test_client_secret'
self._test_config = common.ProjectConfig(
'test_key', self._test_project, self._test_client_id,
self._test_client_secret, None, '/test/path.yaml')
# 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.stubs = mox3_stubout.StubOutForTesting()
self.stubs.SmartSet(builtins, 'open', self.open)
self.stubs.SmartSet(auth, 'os', self.os)
示例5: __init__
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import open [as 別名]
def __init__(self, stream, errors='strict'):
""" Creates a StreamWriter instance.
stream must be a file-like object open for writing.
The StreamWriter may use different error handling
schemes by providing the errors keyword argument. These
parameters are predefined:
'strict' - raise a ValueError (or a subclass)
'ignore' - ignore the character and continue with the next
'replace'- replace with a suitable replacement character
'xmlcharrefreplace' - Replace with the appropriate XML
character reference.
'backslashreplace' - Replace with backslashed escape
sequences.
'namereplace' - Replace with \\N{...} escape sequences.
The set of allowed parameter values can be extended via
register_error.
"""
self.stream = stream
self.errors = errors
示例6: __init__
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import open [as 別名]
def __init__(self, file, mode='r', *, search=524288, _idx=0, _am=None):
if mode != 'r':
raise NotImplementedError("mode != 'r' not implemented")
if isinstance(file, str):
self.__file = builtins.open(file, 'rb')
self.__filename = file
else:
if not file.seekable():
raise TypeError("file must be filename or "
"seekable file-like object")
self.__file = file
self.__filename = '-'
self.__file.seek(0, 2)
self.__filesize = self.__file.tell()
self.__main_header = None
self.__file_headers = []
self.__all_headers = []
try:
self._parse_headers(search)
if self.__main_header == None:
raise CorruptedArchiveError("no main header")
except:
self.close()
raise
示例7: _open
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import open [as 別名]
def _open(cls, file, mode='r', *, search=524288):
"""
Open archive from *file*, which is either a filename or seekable
file-like object, and return an instance of :class:`AceArchive`
representing the opened archive that can function as a context
manager.
Only *mode* 'r' is implemented.
If *search* is 0, the archive must start at position 0 in *file*,
otherwise the first *search* bytes are searched for the magic bytes
``**ACE**`` that mark the ACE main header.
For 1:1 compatibility with the official unace, 1024 sectors are
searched by default, even though none of the SFX stubs that come with
ACE compressors are that large.
Multi-volume archives are represented by a single :class:`AceArchive`
object to the caller, all operations transparently read into subsequent
volumes as required.
To load a multi-volume archive, either open the first volume of the
series by filename, or provide a list or tuple of all file-like
objects or filenames in the correct order in *file*.
"""
return cls(file, mode, search=search)
示例8: __getattr__
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import open [as 別名]
def __getattr__(self, name,
getattr=getattr):
""" Inherit all other methods from the underlying stream.
"""
return getattr(self.stream, name)
# these are needed to make "with codecs.open(...)" work properly
示例9: open
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import open [as 別名]
def open(filename):
"""Open a file in read only mode using the encoding detected by
detect_encoding().
"""
buffer = builtins.open(filename, 'rb')
encoding, lines = detect_encoding(buffer.readline)
buffer.seek(0)
text = TextIOWrapper(buffer, encoding, line_buffering=True)
text.mode = 'r'
return text
示例10: tearDown
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import open [as 別名]
def tearDown(self):
super(DeployImplTest, self).tearDown()
self.stubs.UnsetAll()
builtins.open = self.real_open
示例11: testManifestCheck
# 需要導入模塊: import builtins [as 別名]
# 或者: from 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'
示例12: setUp
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import open [as 別名]
def setUp(self):
super(CommonTest, 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.stubs = mox3_stubout.StubOutForTesting()
self.stubs.SmartSet(builtins, 'open', self.open)
self.stubs.SmartSet(common, 'os', self.os)
示例13: tearDown
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import open [as 別名]
def tearDown(self):
super(CommonTest, self).tearDown()
self.stubs.UnsetAll()
builtins.open = self.real_open
示例14: tearDown
# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import open [as 別名]
def tearDown(self):
super(AuthTest, self).tearDown()
self.stubs.UnsetAll()
builtins.open = self.real_open
示例15: setUp
# 需要導入模塊: import builtins [as 別名]
# 或者: from 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())