Package flumotion :: Package component :: Package misc :: Package httpserver :: Module fileprovider
[hide private]

Source Code for Module flumotion.component.misc.httpserver.fileprovider

  1  # -*- Mode: Python; test-case-name: -*- 
  2  # vi:si:et:sw=4:sts=4:ts=4 
  3   
  4  # Flumotion - a streaming media server 
  5  # Copyright (C) 2004,2005,2006,2007,2008,2009 Fluendo, S.L. 
  6  # Copyright (C) 2010,2011 Flumotion Services, S.A. 
  7  # All rights reserved. 
  8  # 
  9  # This file may be distributed and/or modified under the terms of 
 10  # the GNU Lesser General Public License version 2.1 as published by 
 11  # the Free Software Foundation. 
 12  # This file is distributed without any warranty; without even the implied 
 13  # warranty of merchantability or fitness for a particular purpose. 
 14  # See "LICENSE.LGPL" in the source distribution for more information. 
 15  # 
 16  # Headers in this file shall remain intact. 
 17   
 18  from flumotion.component.plugs import base as plugbase 
 19   
 20   
21 -class FileError(Exception):
22 """ 23 I am raised when a File or a FilePath operation failed. 24 Like trying to get the size or open a file that does not exists. 25 """
26 27
28 -class FileOutOfDate(FileError):
29 """ 30 I am raised when trying an operation on a file that changed since 31 it has been open, and nothing can be done to ensure the integrity 32 of the data. 33 """
34 35
36 -class InsecureError(FileError):
37 """ 38 I am raised when trying to build an insecure path using FilePath. 39 For example, when trying to retrieve a child with a name that 40 contains insecure characters like os.sep . 41 """
42 43
44 -class NotFoundError(FileError):
45 """ 46 I am raised when trying to retrieve a child that does nor exists, 47 or do an operation on a file that does not exists. 48 """
49 50
51 -class CannotOpenError(FileError):
52 """ 53 I am raised when trying to open a path that is not a file. 54 """
55 56
57 -class AccessError(FileError):
58 """ 59 I am raised when a file operation failed because of right restriction. 60 """
61 62
63 -class FileClosedError(FileError):
64 """ 65 I am raised when trying to do some operation on a closed file. 66 """
67 68
69 -class UnavailableError(FileError):
70 """ 71 I am raised when a plug cannot provide the requested service. 72 """
73 74
75 -class FilePath(object):
76 """ 77 I am pointing at a path in the file repository. 78 I can point at a file or at a directory. 79 I can open the pointed file object. 80 I'm used to browse file repository to lookup for file. 81 """ 82
83 - def getMimeType(self):
84 """ 85 @return: the mime type of the pointed file or None if unknown 86 @rtype: str 87 """
88 mimeType = property(getMimeType) 89
90 - def child(self, name):
91 """ 92 @param name: the name of a child of the pointed directory 93 @type name: str 94 95 @return: a FilePath that point at the specified child 96 @rtype: L{MediaPath} 97 @raises NotFoundError: if the child does not exists 98 @raises InsecureError: if the specified name compromise security 99 """
100
101 - def open(self):
102 """ 103 @return: the pointed file opened as an asynchronous file 104 or a deferred that will be called back with one. 105 @rtype: L{AsyncFile} | L{defer.Deferred} 106 @raises NotFoundError: if the file does not exists anymore 107 @raises AccessError: if the file cannot be opened 108 because of right restriction 109 """
110 111
112 -class File(object):
113 """ 114 I am an asynchronous interface to a file. 115 I can be read and written asynchronously. 116 """ 117
118 - def getMimeType(self):
119 """ 120 @return: the mime type of the file or None if unknown 121 @rtype: str 122 """
123 mimeType = property(getMimeType) 124
125 - def getmtime(self):
126 """ 127 @return: the modification time of the file 128 @rtype: int 129 """
130
131 - def getsize(self):
132 """ 133 @return: the size of the file 134 @rtype: long 135 """
136
137 - def tell(self):
138 """ 139 @returns: the current read/write position in the file 140 @rtype: long 141 """
142
143 - def seek(self, offset):
144 """ 145 Moves the reading/writing position inside the file. 146 Only support absolute offset from file start. 147 148 @param offset: the byte offset from the start of the file to go to 149 @type offset: long 150 """
151
152 - def read(self, size):
153 """ 154 Reads the specified amount of data asynchronously. 155 156 @param size: the amount of byte to read from the file 157 @type size: int 158 159 @return: a deferred fired with the read data or a failure. 160 The data can be empty or smaller than the wanted size 161 if the end of file is reached. 162 @type: L{defer.Deferred} 163 """
164
165 - def close(self):
166 """ 167 Close and cleanup the file. 168 """
169
170 - def getLogFields(self):
171 """ 172 @returns: a dictionary of log fields related to the file usage 173 @rtype: dict 174 """
175 176
177 -class FileProviderPlug(plugbase.ComponentPlug):
178 """ 179 I am a plug that provide a root FilePath instance 180 that can be used to lookup and open file objects. 181 """ 182
183 - def startStatsUpdates(self, updater):
184 """ 185 Start updating statistics. 186 """
187
188 - def stopStatsUpdates(self):
189 """ 190 Stop updating statistics. 191 """
192
193 - def getRootPath(self):
194 """ 195 @return: the root of the file repository 196 @rtype: L{FilePath} 197 """
198