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