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


Python __builtin__.file方法代码示例

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


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

示例1: setUp

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import file [as 别名]
def setUp(self):
    super(ConfigurationTest, self).setUp()
    # Save the real modules for clean up.
    self.real_open = __builtin__.open
    self.real_file = __builtin__.file
    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(__builtin__, 'open', self.open)
    self.stubs.SmartSet(os, 'path', self.os.path)

    config_file = constants.CONFIG_DEFAULTS_PATH
    self.fs.CreateFile(config_file, contents=_config_defaults_yaml)

    config_model.Config(id='string_config', string_value='config value 1').put()
    config_model.Config(id='integer_config', integer_value=1).put()
    config_model.Config(id='bool_config', bool_value=True).put()
    config_model.Config(id='list_config', list_value=['email1', 'email2']).put() 
开发者ID:google,项目名称:loaner,代码行数:21,代码来源:config_model_test.py

示例2: find_module

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import file [as 别名]
def find_module(self, fullname, path=None):
    if fullname in _WHITE_LIST_C_MODULES:
      return None
    if any(regex.match(fullname) for regex in self._enabled_regexes):
      return None
    _, _, submodule_name = fullname.rpartition('.')
    try:
      result = imp.find_module(submodule_name, path)
    except ImportError:
      return None
    f, _, description = result
    _, _, file_type = description
    if isinstance(f, file):
      f.close()
    if file_type == imp.C_EXTENSION:
      return self
    return None 
开发者ID:elsigh,项目名称:browserscope,代码行数:19,代码来源:sandbox.py

示例3: CopyStreamPart

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import file [as 别名]
def CopyStreamPart(source, destination, content_size):
  """Copy a portion of a stream from one file-like object to another.

  Args:
    source: Source stream to copy from.
    destination: Destination stream to copy to.
    content_size: Maximum bytes to copy.

  Returns:
    Number of bytes actually copied.
  """
  bytes_copied = 0
  bytes_left = content_size
  while bytes_left > 0:
    bytes = source.read(min(bytes_left, COPY_BLOCK_SIZE))
    bytes_read = len(bytes)
    if bytes_read == 0:
      break
    destination.write(bytes)
    bytes_copied += bytes_read
    bytes_left -= bytes_read
  return bytes_copied 
开发者ID:elsigh,项目名称:browserscope,代码行数:24,代码来源:dev_appserver.py

示例4: EndRedirect

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import file [as 别名]
def EndRedirect(self, dispatched_output, original_output):
    """Process the end of an internal redirect.

    This method is called after all subsequent dispatch requests have finished.
    By default the output from the dispatched process is copied to the original.

    This will not be called on dispatchers that do not return an internal
    redirect.

    Args:
      dispatched_output: StringIO buffer containing the results from the
       dispatched
      original_output: The original output file.

    Returns:
      None if request handling is complete.
      A new AppServerRequest instance if internal redirect is required.
    """
    original_output.write(dispatched_output.read()) 
开发者ID:elsigh,项目名称:browserscope,代码行数:21,代码来源:dev_appserver.py

示例5: CheckScriptExists

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import file [as 别名]
def CheckScriptExists(cgi_path, handler_path):
  """Check that the given handler_path is a file that exists on disk.

  Args:
    cgi_path: Absolute path to the CGI script file on disk.
    handler_path: CGI path stored in the application configuration (as a path
      like 'foo/bar/baz.py'). May contain $PYTHON_LIB references.

  Raises:
    CouldNotFindModuleError: if the given handler_path is a file and doesn't
    have the expected extension.
  """
  if handler_path.startswith(PYTHON_LIB_VAR + '/'):

    return

  if (not os.path.isdir(cgi_path) and
      not os.path.isfile(cgi_path) and
      os.path.isfile(cgi_path + '.py')):
    raise CouldNotFindModuleError(
        'Perhaps you meant to have the line "script: %s.py" in your app.yaml' %
        handler_path) 
开发者ID:elsigh,项目名称:browserscope,代码行数:24,代码来源:dev_appserver.py

示例6: __init__

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import file [as 别名]
def __init__(self,
               config,
               module_dict,
               root_path,
               path_adjuster,
               setup_env=SetupEnvironment,
               exec_cgi=ExecuteCGI):
    """Initializer.

    Args:
      config: AppInfoExternal instance representing the parsed app.yaml file.
      module_dict: Dictionary in which application-loaded modules should be
        preserved between requests. This dictionary must be separate from the
        sys.modules dictionary.
      path_adjuster: Instance of PathAdjuster to use for finding absolute
        paths of CGI files on disk.
      setup_env, exec_cgi: Used for dependency injection.
    """
    self._config = config
    self._module_dict = module_dict
    self._root_path = root_path
    self._path_adjuster = path_adjuster
    self._setup_env = setup_env
    self._exec_cgi = exec_cgi 
开发者ID:elsigh,项目名称:browserscope,代码行数:26,代码来源:dev_appserver.py

示例7: AdjustPath

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import file [as 别名]
def AdjustPath(self, path):
    """Adjusts application file paths to relative to the application.

    More precisely this method adjusts application file path to paths
    relative to the application or external library directories.

    Handler paths that start with $PYTHON_LIB will be converted to paths
    relative to the google directory.

    Args:
      path: File path that should be adjusted.

    Returns:
      The adjusted path.
    """
    if path.startswith(PYTHON_LIB_VAR):
      path = os.path.join(SDK_ROOT, path[len(PYTHON_LIB_VAR) + 1:])
    else:
      path = os.path.join(self._root_path, path)

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

示例8: GetMimeType

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import file [as 别名]
def GetMimeType(self, path):
    """Returns the mime type that we should use when serving the specified file.

    Args:
      path: A string containing the file's path relative to the app.

    Returns:
      String containing the mime type to use. Will be 'application/octet-stream'
      if we have no idea what it should be.
    """
    url_map = self._FirstMatch(path)
    if url_map.mime_type is not None:
      return url_map.mime_type


    unused_filename, extension = os.path.splitext(path)
    return mimetypes.types_map.get(extension, 'application/octet-stream') 
开发者ID:elsigh,项目名称:browserscope,代码行数:19,代码来源:dev_appserver.py

示例9: GetExpiration

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import file [as 别名]
def GetExpiration(self, path):
    """Returns the cache expiration duration to be users for the given file.

    Args:
      path: A string containing the file's path relative to the app.

    Returns:
      Integer number of seconds to be used for browser cache expiration time.
    """

    if self._default_expiration is None:
      return 0

    url_map = self._FirstMatch(path)
    if url_map.expiration is None:
      return self._default_expiration

    return appinfo.ParseExpiration(url_map.expiration) 
开发者ID:elsigh,项目名称:browserscope,代码行数:20,代码来源:dev_appserver.py

示例10: _RemainingDataSize

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import file [as 别名]
def _RemainingDataSize(input_buffer):
  """Computes how much data is remaining in the buffer.

  It leaves the buffer in its initial state.

  Args:
    input_buffer: a file-like object with seek and tell methods.

  Returns:
    integer representing how much data is remaining in the buffer.
  """
  current_position = input_buffer.tell()
  input_buffer.seek(0, 2)
  remaining_data_size = input_buffer.tell() - current_position
  input_buffer.seek(current_position)
  return remaining_data_size 
开发者ID:elsigh,项目名称:browserscope,代码行数:18,代码来源:dev_appserver.py

示例11: GetModuleFile

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import file [as 别名]
def GetModuleFile(module, is_file=os.path.isfile):
    """Helper method to try to determine modules source file.

    Args:
      module: Module object to get file for.
      is_file: Function used to determine if a given path is a file.

    Returns:
      Path of the module's corresponding Python source file if it exists, or
      just the module's compiled Python file. If the module has an invalid
      __file__ attribute, None will be returned.
    """
    module_file = getattr(module, '__file__', None)
    if module_file is None:
      return None


    source_file = module_file[:module_file.rfind('py') + 2]

    if is_file(source_file):
      return source_file
    return module.__file__ 
开发者ID:elsigh,项目名称:browserscope,代码行数:24,代码来源:dev_appserver.py

示例12: GetVersionObject

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import file [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

示例13: ReadAppConfig

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import file [as 别名]
def ReadAppConfig(appinfo_path, parse_app_config=appinfo_includes.Parse):
  """Reads app.yaml file and returns its app id and list of URLMap instances.

  Args:
    appinfo_path: String containing the path to the app.yaml file.
    parse_app_config: Used for dependency injection.

  Returns:
    AppInfoExternal instance.

  Raises:
    If the config file could not be read or the config does not contain any
    URLMap instances, this function will raise an InvalidAppConfigError
    exception.
  """
  try:
    appinfo_file = file(appinfo_path, 'r')
  except IOError, unused_e:
    raise InvalidAppConfigError(
        'Application configuration could not be read from "%s"' % appinfo_path) 
开发者ID:elsigh,项目名称:browserscope,代码行数:22,代码来源:dev_appserver.py

示例14: ReadCronConfig

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import file [as 别名]
def ReadCronConfig(croninfo_path, parse_cron_config=croninfo.LoadSingleCron):
  """Reads cron.yaml file and returns a list of CronEntry instances.

  Args:
    croninfo_path: String containing the path to the cron.yaml file.
    parse_cron_config: Used for dependency injection.

  Returns:
    A CronInfoExternal object.

  Raises:
    If the config file is unreadable, empty or invalid, this function will
    raise an InvalidAppConfigError or a MalformedCronConfiguration exception.
  """
  try:
    croninfo_file = file(croninfo_path, 'r')
  except IOError, e:
    raise InvalidAppConfigError(
        'Cron configuration could not be read from "%s": %s'
        % (croninfo_path, e)) 
开发者ID:elsigh,项目名称:browserscope,代码行数:22,代码来源:dev_appserver.py

示例15: tearDown

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import file [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


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