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 InsecureError(FileError):
33 """ 34 I am raised when trying to build an insecure path using FilePath. 35 For example, when trying to retrieve a child with a name that 36 contains insecure characters like os.sep . 37 """
38 39
40 -class NotFoundError(FileError):
41 """ 42 I am raised when trying to retrieve a child that does nor exists, 43 or do an operation on a file that does not exists. 44 """
45 46
47 -class CannotOpenError(FileError):
48 """ 49 I am raised when trying to open a path that is not a file. 50 """
51 52
53 -class AccessError(FileError):
54 """ 55 I am raised when a file operation failed because of right restriction. 56 """
57 58
59 -class FileClosedError(FileError):
60 """ 61 I am raised when trying to do some operation on a closed file. 62 """
63 64
65 -class FilePath(object):
66 """ 67 I am pointing at a path in the file repository. 68 I can point at a file or at a directory. 69 I can open the pointed file object. 70 I'm used to browse file repository to lookup for file. 71 """ 72
73 - def getMimeType(self):
74 """ 75 @return: the mime type of the pointed file or None if unknown 76 @rtype: str 77 """
78 mimeType = property(getMimeType) 79
80 - def child(self, name):
81 """ 82 @param name: the name of a child of the pointed directory 83 @type name: str 84 85 @return: a FilePath that point at the specified child 86 @rtype: L{MediaPath} 87 @raises NotFoundError: if the child does not exists 88 @raises InsecureError: if the specified name compromise security 89 """
90
91 - def open(self):
92 """ 93 @return: the pointed file opened as an asynchronous file 94 @rtype: L{AsyncFile} 95 @raises NotFoundError: if the file does not exists anymore 96 @raises AccessError: if the file cannot be opened 97 because of right restriction 98 """
99 100
101 -class File(object):
102 """ 103 I am an asynchronous interface to a file. 104 I can be read and written asynchronously. 105 """ 106
107 - def getMimeType(self):
108 """ 109 @return: the mime type of the file or None if unknown 110 @rtype: str 111 """
112 mimeType = property(getMimeType) 113
114 - def getmtime(self):
115 """ 116 @return: the modification time of the file 117 @rtype: int 118 """
119
120 - def getsize(self):
121 """ 122 @return: the size of the file 123 @rtype: long 124 """
125
126 - def tell(self):
127 """ 128 @returns: the current read/write position in the file 129 @rtype: long 130 """
131
132 - def seek(self, offset):
133 """ 134 Moves the reading/writing position inside the file. 135 Only support absolute offset from file start. 136 137 @param offset: the byte offset from the start of the file to go to 138 @type offset: long 139 """
140
141 - def read(self, size):
142 """ 143 Reads the specified amount of data asynchronously. 144 145 @param size: the amount of byte to read from the file 146 @type size: int 147 148 @return: a deferred fired with the read data or a failure. 149 The data can be empty or smaller than the wanted size 150 if the end of file is reached. 151 @type: L{defer.Deferred} 152 """
153
154 - def close(self):
155 """ 156 Close and cleanup the file. 157 """
158
159 - def getLogFields(self):
160 """ 161 @returns: a dictionary of log fields related to the file usage 162 @rtype: dict 163 """
164 165
166 -class FileProviderPlug(plugbase.ComponentPlug):
167 """ 168 I am a plug that provide a root FilePath instance 169 that can be used to lookup and open file objects. 170 """ 171
172 - def startStatsUpdates(self, updater):
173 """ 174 Start updating statistics. 175 """
176
177 - def stopStatsUpdates(self):
178 """ 179 Stop updating statistics. 180 """
181
182 - def getRootPath(self):
183 """ 184 @return: the root of the file repository 185 @rtype: L{FilePath} 186 """
187