summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions/docs/server2/offline_file_system.py
blob: 281ef5dd3fc8bea9f01c8f1d195a0e88ca06b699 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

from file_system import FileSystem, FileNotFoundError

class OfflineFileSystem(FileSystem):
  '''An offline FileSystem which masquerades as another file system. It throws
  FileNotFound error for all operations, and overrides GetName and GetVersion.
  '''
  def __init__(self, cls):
    self._cls = cls

  def Read(self, paths, binary=False):
    raise FileNotFoundError('File system is offline, cannot read %s' % paths)

  def Stat(self, path):
    raise FileNotFoundError('File system is offline, cannot read %s' % path)

  # HACK: despite GetName/GetVersion being @classmethods, these need to be
  # instance methods so that we can grab the name and version from the class
  # given on construction.

  def GetName(self):
    return self._cls.GetName()

  def GetVersion(self):
    return self._cls.GetVersion()