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


Python cloudstorage.NotFoundError方法代码示例

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


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

示例1: test_content_gcs_missing

# 需要导入模块: import cloudstorage [as 别名]
# 或者: from cloudstorage import NotFoundError [as 别名]
def test_content_gcs_missing(self):
    content = 'Foo'
    compressed = zlib.compress(content)
    namespace = 'default-gzip'
    hashhex = hashlib.sha1(content).hexdigest()

    def read_file(bucket, key):
      self.assertEqual(u'sample-app', bucket)
      self.assertEqual(namespace + '/' + hashhex, key)
      raise cloudstorage.NotFoundError('Someone deleted the file from GCS')
    self.mock(gcs, 'read_file', read_file)

    key = model.get_entry_key(namespace, hashhex)
    model.new_content_entry(
        key,
        is_isolated=False,
        compressed_size=len(compressed),
        expanded_size=len(content),
        is_verified=True).put()

    self.set_as_reader()
    self.app.get(
        '/content?namespace=default-gzip&digest=%s' % hashhex, status=404)
    self.assertEqual(None, key.get()) 
开发者ID:luci,项目名称:luci-py,代码行数:26,代码来源:handlers_frontend_test.py

示例2: next

# 需要导入模块: import cloudstorage [as 别名]
# 或者: from cloudstorage import NotFoundError [as 别名]
def next(self):
    """Returns the next input from this input reader, a block of bytes.

    Non existent files will be logged and skipped. The file might have been
    removed after input splitting.

    Returns:
      The next input from this input reader in the form of a cloudstorage
      ReadBuffer that supports a File-like interface (read, readline, seek,
      tell, and close). An error may be raised if the file can not be opened.

    Raises:
      StopIteration: The list of files has been exhausted.
    """
    options = {}
    if self._buffer_size:
      options["read_buffer_size"] = self._buffer_size
    if self._account_id:
      options["_account_id"] = self._account_id
    while True:
      filename = self._next_file()
      if filename is None:
        raise StopIteration()
      try:
        start_time = time.time()
        handle = cloudstorage.open(filename, **options)

        ctx = context.get()
        if ctx:
          operation.counters.Increment(
              COUNTER_IO_READ_MSEC, int((time.time() - start_time) * 1000))(ctx)

        return handle
      except cloudstorage.NotFoundError:
        logging.warning("File %s may have been removed. Skipping file.",
                        filename) 
开发者ID:singhj,项目名称:locality-sensitive-hashing,代码行数:38,代码来源:input_readers.py

示例3: next

# 需要导入模块: import cloudstorage [as 别名]
# 或者: from cloudstorage import NotFoundError [as 别名]
def next(self):
    """Returns a handler to the next file.

    Non existent files will be logged and skipped. The file might have been
    removed after input splitting.

    Returns:
      The next input from this input reader in the form of a cloudstorage
      ReadBuffer that supports a File-like interface (read, readline, seek,
      tell, and close). An error may be raised if the file can not be opened.

    Raises:
      StopIteration: The list of files has been exhausted.
    """
    options = {}
    if self._buffer_size:
      options["read_buffer_size"] = self._buffer_size
    if self._account_id:
      options["_account_id"] = self._account_id
    while True:
      filename = self._next_file()
      if filename is None:
        raise StopIteration()
      if (self._path_filter and
          not self._path_filter.accept(self._slice_ctx, filename)):
        continue
      try:
        start_time = time.time()
        handle = cloudstorage.open(filename, **options)
        self._slice_ctx.incr(self.COUNTER_IO_READ_MSEC,
                             int(time.time() - start_time) * 1000)
        self._slice_ctx.incr(self.COUNTER_FILE_READ)
        return handle
      except cloudstorage.NotFoundError:
        logging.warning("File %s may have been removed. Skipping file.",
                        filename)
        self._slice_ctx.incr(self.COUNTER_FILE_MISSING) 
开发者ID:singhj,项目名称:locality-sensitive-hashing,代码行数:39,代码来源:_gcs.py

示例4: delete_files

# 需要导入模块: import cloudstorage [as 别名]
# 或者: from cloudstorage import NotFoundError [as 别名]
def delete_files(self):
        self.response.write('Deleting files...\n')
        for filename in self.tmp_filenames_to_clean_up:
            self.response.write('Deleting file {}\n'.format(filename))
            try:
                cloudstorage.delete(filename)
            except cloudstorage.NotFoundError:
                pass
# [END delete_files] 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:11,代码来源:main.py

示例5: get

# 需要导入模块: import cloudstorage [as 别名]
# 或者: from cloudstorage import NotFoundError [as 别名]
def get(self, name, version, filename):
        try:
            package = Package(self.get_storage(), name, version)
            with package.get_file(filename) as gcs_file:
                self.response.content_type = 'application/octet-stream'
                self.response.headers.add('Content-Disposition', 'attachment; filename={0}'.format(filename))
                self.response.write(gcs_file.read())
        except NotFoundError:
            self.write404() 
开发者ID:ml2grow,项目名称:GAEPyPI,代码行数:11,代码来源:_handlers.py

示例6: next

# 需要导入模块: import cloudstorage [as 别名]
# 或者: from cloudstorage import NotFoundError [as 别名]
def next(self):
    """Returns the next input from this input reader, a block of bytes.

    Non existent files will be logged and skipped. The file might have been
    removed after input splitting.

    Returns:
      The next input from this input reader in the form of a cloudstorage
      ReadBuffer that supports a File-like interface (read, readline, seek,
      tell, and close). An error may be raised if the file can not be opened.

    Raises:
      StopIteration: The list of files has been exhausted.
    """
    options = {}
    if self._buffer_size:
      options["read_buffer_size"] = self._buffer_size
    if self._account_id:
      options["_account_id"] = self._account_id
    while True:
      filename = self._next_file()
      if filename is None:
        raise StopIteration()
      try:
        start_time = time.time()
        handle = cloudstorage.open(filename, **options)

        ctx = context.get()
        if ctx:
          operation.counters.Increment(
              COUNTER_IO_READ_MSEC, int((time.time() - start_time) * 1000))(ctx)

        return handle
      except cloudstorage.NotFoundError:
        # Fail the job if we're strict on missing input.
        if getattr(self, "_fail_on_missing_input", False):
          raise errors.FailJobError(
              "File missing in GCS, aborting: %s" % filename)
        # Move on otherwise.
        logging.warning("File %s may have been removed. Skipping file.",
                        filename) 
开发者ID:GoogleCloudPlatform,项目名称:appengine-mapreduce,代码行数:43,代码来源:input_readers.py

示例7: next

# 需要导入模块: import cloudstorage [as 别名]
# 或者: from cloudstorage import NotFoundError [as 别名]
def next(self):
    """Returns the next input from this input reader, a block of bytes.

    Non existent files will be logged and skipped. The file might have been
    removed after input splitting.

    Returns:
      The next input from this input reader in the form of a cloudstorage
      ReadBuffer that supports a File-like interface (read, readline, seek,
      tell, and close). An error may be raised if the file can not be opened.

    Raises:
      StopIteration: The list of files has been exhausted.
    """
    options = {}
    if self._buffer_size:
      options["read_buffer_size"] = self._buffer_size
    if self._account_id:
      options["_account_id"] = self._account_id
    while True:
      filename = self._next_file()
      if filename is None:
        raise StopIteration()
      try:
        start_time = time.time()
        handle = cloudstorage.open(filename, **options)

        ctx = context.get()
        if ctx:
          operation.counters.Increment(
              COUNTER_IO_READ_MSEC, int((time.time() - start_time) * 1000))(ctx)

        return handle
      except cloudstorage.NotFoundError:
        self._on_missing_input_file(filename)

        if getattr(self, "_fail_on_missing_input", False):
          raise errors.FailJobError(
              "File missing in GCS, aborting: %s" % filename)

        logging.warning("File %s may have been removed. Skipping file.",
                        filename) 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:44,代码来源:input_readers.py


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