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


Python __builtin__.open方法代码示例

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


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

示例1: test_write

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import open [as 别名]
def test_write(self):
    expected_dict = {
        'project_id': 'test_project',
        'client_id': 'test_client_id',
        'client_secret': 'test_client_secret',
        'bucket': 'test_project.appspot.com',
    }
    self.fs.CreateFile('/this/config/file.yaml', contents=_EMPTY_CONFIG)
    test_config = common.ProjectConfig(
        'asdf', 'test_project', 'test_client_id', 'test_client_secret', None,
        '/this/config/file.yaml',
    )
    test_config.write()
    with open('/this/config/file.yaml') as config_file:
      config = yaml.safe_load(config_file)
    self.assertEqual(config['asdf'], expected_dict) 
开发者ID:google,项目名称:loaner,代码行数:18,代码来源:common_test.py

示例2: setUp

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ 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) 
开发者ID:google,项目名称:loaner,代码行数:19,代码来源:auth_test.py

示例3: get_source

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import open [as 别名]
def get_source(self, fullname):
    """Returns the source for the module specified by fullname.

    This implements part of the extensions to the PEP 302 importer protocol.

    Args:
      fullname: The fullname of the module.

    Returns:
      The source for the module.
    """
    full_path, _, _, loader = self._get_module_info(fullname)
    if loader:
      return loader.get_source(fullname)
    if full_path is None:
      return None
    source_file = open(full_path)
    try:
      return source_file.read()
    finally:
      source_file.close() 
开发者ID:elsigh,项目名称:browserscope,代码行数:23,代码来源:sandbox.py

示例4: GetVersionObject

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import open [as 别名]
def GetVersionObject(isfile=os.path.isfile, open_fn=open):
  """Gets the version of the SDK by parsing the VERSION file.

  Args:
    isfile: used for testing.
    open_fn: Used for testing.

  Returns:
    A Yaml object or None if the VERSION file does not exist.
  """
  version_filename = os.path.join(os.path.dirname(google.appengine.__file__),
                                  VERSION_FILE)
  if not isfile(version_filename):
    logging.error('Could not find version file at %s', version_filename)
    return None

  version_fh = open_fn(version_filename, 'r')
  try:
    version = yaml.safe_load(version_fh)
  finally:
    version_fh.close()

  return version 
开发者ID:elsigh,项目名称:browserscope,代码行数:25,代码来源:dev_appserver.py

示例5: __init__

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ 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 
开发者ID:glmcdona,项目名称:meddle,代码行数:26,代码来源:codecs.py

示例6: open

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import open [as 别名]
def open(fn, *args, **kwargs):
    '''
    Open a file in the current output directory
    args same as for open()
    '''
    return _open(filename(fn), *args, **kwargs) 
开发者ID:hjimce,项目名称:Depth-Map-Prediction,代码行数:8,代码来源:logutil.py

示例7: setUp

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ 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) 
开发者ID:google,项目名称:loaner,代码行数:13,代码来源:common_test.py

示例8: tearDown

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

示例9: tearDown

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

示例10: tearDown

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import open [as 别名]
def tearDown(self):
    super(ConfigurationTest, self).tearDown()
    self.stubs.UnsetAll()
    __builtin__.open = self.real_open
    __builtin__.file = self.real_file 
开发者ID:google,项目名称:loaner,代码行数:7,代码来源:config_model_test.py

示例11: __init__

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import open [as 别名]
def __init__(self, name, mode):
        mode = {
            "r": os.O_RDONLY,
            "w": os.O_WRONLY | os.O_CREAT | os.O_TRUNC,
        }[mode]
        if hasattr(os, "O_BINARY"):
            mode |= os.O_BINARY
        self.fd = os.open(name, mode, 0o666) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:10,代码来源:tarfile.py

示例12: bz2open

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import open [as 别名]
def bz2open(cls, name, mode="r", fileobj=None, compresslevel=9, **kwargs):
        """Open bzip2 compressed tar archive name for reading or writing.
           Appending is not allowed.
        """
        if len(mode) > 1 or mode not in "rw":
            raise ValueError("mode must be 'r' or 'w'.")

        try:
            import bz2
        except ImportError:
            raise CompressionError("bz2 module is not available")

        if fileobj is not None:
            fileobj = _BZ2Proxy(fileobj, mode)
        else:
            fileobj = bz2.BZ2File(name, mode, compresslevel=compresslevel)

        try:
            t = cls.taropen(name, mode, fileobj, **kwargs)
        except (IOError, EOFError):
            fileobj.close()
            raise ReadError("not a bzip2 file")
        t._extfileobj = False
        return t

    # All *open() methods are registered here. 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:28,代码来源:tarfile.py

示例13: _check

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import open [as 别名]
def _check(self, mode=None):
        """Check if TarFile is still open, and if the operation's mode
           corresponds to TarFile's mode.
        """
        if self.closed:
            raise IOError("%s is closed" % self.__class__.__name__)
        if mode is not None and self.mode not in mode:
            raise IOError("bad operation for mode %r" % self.mode) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:10,代码来源:tarfile.py

示例14: is_tarfile

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import open [as 别名]
def is_tarfile(name):
    """Return True if name points to a tar archive that we
       are able to handle, else return False.
    """
    try:
        t = open(name)
        t.close()
        return True
    except TarError:
        return False 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:12,代码来源:tarfile.py

示例15: _find_module_or_loader

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import open [as 别名]
def _find_module_or_loader(self, submodule_name, fullname, path):
    """Acts like imp.find_module with support for path hooks.

    Args:
      submodule_name: The name of the submodule within its parent package.
      fullname: The full name of the module to load.
      path: A list containing the paths to search for the module.

    Returns:
      A tuple (source_file, path_name, description, loader) where:
        source_file: An open file or None.
        path_name: A str containing the the path to the module.
        description: A description tuple like the one imp.find_module returns.
        loader: A PEP 302 compatible path hook. If this is not None, then the
            other elements will be None.

    Raises:
      ImportError: The module could not be imported.
    """
    for path_entry in path + [None]:
      result = self._find_path_hook(submodule_name, fullname, path_entry)
      if result is not None:
        break
    else:
      raise ImportError('No module named %s' % fullname)
    if isinstance(result, tuple):
      return result + (None,)
    else:
      return None, None, None, result.find_module(fullname) 
开发者ID:elsigh,项目名称:browserscope,代码行数:31,代码来源:sandbox.py


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