t.w.s.File(resource.Resource, styles.Versioned, filepath.FilePath) : class documentation

Part of twisted.web.static View Source View In Hierarchy

File is a resource that represents a plain non-interpreted file (although it can look for an extension like .rpy or .cgi and hand the file to a processor for interpretation if you wish). Its constructor takes a file path.

Alternatively, you can give a directory path to the constructor. In this case the resource will represent that directory, and its children will be files underneath that directory. This provides access to an entire filesystem tree with a single Resource.

If you map the URL 'http://server/FILE' to a resource created as File('/tmp'), then http://server/FILE/ will return an HTML-formatted listing of the /tmp/ directory, and http://server/FILE/foo/bar.html will return the contents of /tmp/foo/bar.html .
Class VariableschildNotFoundResource used to render 404 Not Found error pages.
Method upgradeToVersion6 Undocumented
Method upgradeToVersion5 Undocumented
Method upgradeToVersion4 Undocumented
Method upgradeToVersion3 Undocumented
Method upgradeToVersion2 Undocumented
Method upgradeToVersion1 Undocumented
Method __init__ Create a file with the given path.
Method ignoreExt Ignore the given extension.
Method directoryListing Undocumented
Method getChild If this File's path refers to a directory, return a File referring to the file named path in that directory.
Method openForReading Open a file and return it.
Method getFileSize Return file size.
Method makeProducer Make a StaticProducer that will produce the body of this response.
Method render_GET Begin sending the contents of this File (or a subset of the contents, based on the 'range' header) to the given request.
Method redirect Undocumented
Method listNames Undocumented
Method listEntities Undocumented
Method createPickleChild Undocumented
Method createSimilarFile Undocumented
Method _parseRangeHeader Parse the value of a Range header into (start, stop) pairs.
Method _rangeToOffsetAndSize Convert a start and end from a Range header to an offset and size.
Method _contentRange Return a string suitable for the value of a Content-Range header for a range with the given offset and size.
Method _doSingleRangeRequest Set up the response for Range headers that specify a single range.
Method _doMultipleRangeRequest Set up the response for Range headers that specify a single range.
Method _setContentHeaders Set the Content-length and Content-type headers for this request.

Inherited from Resource:

Method listStaticNames Undocumented
Method listStaticEntities Undocumented
Method listDynamicNames Undocumented
Method listDynamicEntities Undocumented
Method getStaticEntity Undocumented
Method getDynamicEntity Undocumented
Method delEntity Undocumented
Method reallyPutEntity Undocumented
Method getChildWithDefault Retrieve a static or dynamically generated child resource from me.
Method getChildForRequest Undocumented
Method putChild Register a static child.
Method render Render a given resource. See IResource's render method.
Method render_HEAD Default handling of HEAD method.

Inherited from Versioned:

Method __setstate__ Undocumented
Method __getstate__ Get state, adding a version number to it on its way out.
Method versionUpgrade (internal) Do a version upgrade.

Inherited from FilePath:

Method __getstate__ Undocumented
Method child Undocumented
Method preauthChild Use me if `path' might have slashes in it, but you know they're safe.
Method childSearchPreauth Return my first existing child with a name in 'paths'.
Method siblingExtensionSearch Attempt to return a path with my name, given multiple possible extensions.
Method realpath No summary
Method siblingExtension Undocumented
Method linkTo No summary
Method open Open this file using mode or for writing if alwaysCreate is True.
Method restat Re-calculate cached effects of 'stat'. To refresh information on this path after you know the filesystem may have changed, call this method.
Method changed Clear any cached information about the state of this path on disk.
Method chmod Changes the permissions on self, if possible. Propagates errors from os.chmod up.
Method getsize Undocumented
Method getModificationTime Retrieve the time of last access from this file.
Method getStatusChangeTime Retrieve the time of the last status change for this file.
Method getAccessTime Retrieve the time that this file was last accessed.
Method exists Check if the path exists.
Method isdir Undocumented
Method isfile Undocumented
Method islink Undocumented
Method isabs Undocumented
Method listdir Undocumented
Method splitext Undocumented
Method __repr__ Undocumented
Method touch Undocumented
Method remove No summary
Method makedirs Create all directories not yet existing in path segments, using os.makedirs.
Method globChildren Assuming I am representing a directory, return a list of FilePaths representing my children that match the given pattern.
Method basename Undocumented
Method dirname Undocumented
Method parent Undocumented
Method setContent Replace the file at this path with a new file that contains the given bytes, trying to avoid data-loss in the meanwhile.
Method __cmp__ Undocumented
Method createDirectory Undocumented
Method requireCreate Undocumented
Method create Exclusively create a file, only if this file previously did not exist.
Method temporarySibling Construct a path referring to a sibling of this path.
Method copyTo Copies self to destination.
Method moveTo No summary

Inherited from _PathHelper (via FilePath):

Method getContent Undocumented
Method parents
Method children List the children of this path object.
Method walk No summary
Method sibling Undocumented
Method segmentsFrom Return a list of segments between a child and its ancestor.
Method __hash__ Hash the same as another FilePath with the same path as mine.
Method getmtime Deprecated. Use getModificationTime instead.
Method getatime Deprecated. Use getAccessTime instead.
Method getctime Deprecated. Use getStatusChangeTime instead.
def upgradeToVersion6(self): (source)
Undocumented
def upgradeToVersion5(self): (source)
Undocumented
def upgradeToVersion4(self): (source)
Undocumented
def upgradeToVersion3(self): (source)
Undocumented
def upgradeToVersion2(self): (source)
Undocumented
def upgradeToVersion1(self): (source)
Undocumented
def __init__(self, path, defaultType='text/html', ignoredExts=(), registry=None, allowExt=0): (source)
Create a file with the given path.
ParameterspathThe filename of the file from which this File will serve data. (type: str )
defaultTypeA major/minor-style MIME type specifier indicating the Content-Type with which this File's data will be served if a MIME type cannot be determined based on path's extension. (type: str )
ignoredExtsA sequence giving the extensions of paths in the filesystem which will be ignored for the purposes of child lookup. For example, if ignoredExts is (".bar",) and path is a directory containing a file named "foo.bar", a request for the "foo" child of this resource will succeed with a File pointing to "foo.bar".
registryThe registry object being used to handle this request. If None, one will be created. (type: Registry )
allowExtIgnored parameter, only present for backwards compatibility. Do not pass a value for this parameter.
def ignoreExt(self, ext): (source)

Ignore the given extension.

Serve file.ext if file is requested
def directoryListing(self): (source)
Undocumented
def getChild(self, path, request): (source)

If this File's path refers to a directory, return a File referring to the file named path in that directory.

If path is the empty string, return a DirectoryLister instead.
def openForReading(self): (source)
Open a file and return it.
def getFileSize(self): (source)
Return file size.
def _parseRangeHeader(self, range): (source)

Parse the value of a Range header into (start, stop) pairs.

In a given pair, either of start or stop can be None, signifying that no value was provided, but not both.
ReturnsA list [(start, stop)] of pairs of length at least one.
RaisesValueErrorif the header is syntactically invalid or if the Bytes-Unit is anything other than 'bytes'.
def _rangeToOffsetAndSize(self, start, end): (source)

Convert a start and end from a Range header to an offset and size.

This method checks that the resulting range overlaps with the resource being served (and so has the value of getFileSize() as an indirect input).

Either but not both of start or end can be None:
  • Omitted start means that the end value is actually a start value relative to the end of the resource.
  • Omitted end means the end of the resource should be the end of the range.

End is interpreted as inclusive, as per RFC 2616.

If this range doesn't overlap with any of this resource, (0, 0) is returned, which is not otherwise a value return value.
ParametersstartThe start value from the header, or None if one was not present.
endThe end value from the header, or None if one was not present.
Returns(offset, size) where offset is how far into this resource this resource the range begins and size is how long the range is, or (0, 0) if the range does not overlap this resource.
def _contentRange(self, offset, size): (source)

Return a string suitable for the value of a Content-Range header for a range with the given offset and size.

The offset and size are not sanity checked in any way.
ParametersoffsetHow far into this resource the range begins.
sizeHow long the range is.
ReturnsThe value as appropriate for the value of a Content-Range header.
def _doSingleRangeRequest(self, request, (start, end)): (source)

Set up the response for Range headers that specify a single range.

This method checks if the request is satisfiable and sets the response code and Content-Range header appropriately. The return value indicates which part of the resource to return.
ParametersrequestThe Request object.
startThe start of the byte range as specified by the header.
endThe end of the byte range as specified by the header. At most one of start and end may be None.
ReturnsA 2-tuple of the offset and size of the range to return. offset == size == 0 indicates that the request is not satisfiable.
def _doMultipleRangeRequest(self, request, byteRanges): (source)

Set up the response for Range headers that specify a single range.

This method checks if the request is satisfiable and sets the response code and Content-Type and Content-Length headers appropriately. The return value, which is a little complicated, indicates which parts of the resource to return and the boundaries that should separate the parts.

In detail, the return value is a tuple rangeInfo rangeInfo is a list of 3-tuples (partSeparator, partOffset, partSize). The response to this request should be, for each element of rangeInfo, partSeparator followed by partSize bytes of the resource starting at partOffset. Each partSeparator includes the MIME-style boundary and the part-specific Content-type and Content-range headers. It is convenient to return the separator as a concrete string from this method, becasue this method needs to compute the number of bytes that will make up the response to be able to set the Content-Length header of the response accurately.
ParametersrequestThe Request object.
byteRangesA list of (start, end) values as specified by the header. For each range, at most one of start and end may be None.
ReturnsSee above.
def _setContentHeaders(self, request, size=None): (source)

Set the Content-length and Content-type headers for this request.

This method is not appropriate for requests for multiple byte ranges; _doMultipleRangeRequest will set these headers in that case.
ParametersrequestThe Request object.
sizeThe size of the response. If not specified, default to self.getFileSize().
def makeProducer(self, request, fileForReading): (source)

Make a StaticProducer that will produce the body of this response.

This method will also set the response code and Content-* headers.
ParametersrequestThe Request object.
fileForReadingThe file object containing the resource.
ReturnsA StaticProducer. Calling .start() on this will begin producing the response.
def render_GET(self, request): (source)
Begin sending the contents of this File (or a subset of the contents, based on the 'range' header) to the given request.
def redirect(self, request): (source)
Undocumented
def listNames(self): (source)
Undocumented
def listEntities(self): (source)
Undocumented
def createPickleChild(self, name, child): (source)
Undocumented
def createSimilarFile(self, path): (source)
Undocumented
API Documentation for Twisted, generated by pydoctor at 2011-10-27 16:17:34.