OPSI.web2.static module

I deal with static resources.

class OPSI.web2.static.Data(data, type)

Bases: OPSI.web2.resource.Resource

This is a static, in-memory resource.

contentLength()
contentType()
creationDate()
etag()
lastModified()
render(req)
class OPSI.web2.static.File(path, defaultType='text/plain', ignoredExts=(), processors=None, indexNames=None)

Bases: OPSI.web2.static.StaticRenderMixin

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 .

contentEncoding()
contentEncodings = {'.bz2': 'bzip2', '.gz': 'gzip'}
contentLength()
contentType()
contentTypes
createSimilarFile(path)
creationDate()
directoryListing()
displayName()
etag()
exists()
getChild(name)

Look up a child resource. @return: the child of this resource with the given name.

ignoreExt(ext)

Ignore the given extension.

Serve file.ext if file is requested

indexNames = ['index', 'index.html', 'index.htm', 'index.trp', 'index.rpy']
lastModified()
listChildren()

@return: a sequence of the names of all known children of this resource.

locateChild(req, segments)

See L{IResource}C{.locateChild}.

processors = {}
putChild(name, child)

Register a child with the given name with this resource. @param name: the name of the child (a URI path segment) @param child: the child to register

render(req)

You know what you doing.

renderHTTP(req)
type = None
class OPSI.web2.static.FileSaver(destination, expectedFields=[], allowedTypes=None, maxBytes=1000000, permissions=420)

Bases: OPSI.web2.resource.PostableResource

allowedTypes = (MimeType('text', 'plain', {}), MimeType('text', 'html', {}), MimeType('text', 'css', {}))
isSafeToWrite(filename, mimetype, filestream)

Returns True if it’s “safe” to write this file, otherwise it raises an exception.

makeUniqueName(filename)

Called when a unique filename is needed.

filename is the name of the file as given by the client.

Returns the fully qualified path of the file to create. The file must not yet exist.

render(req)
writeFile(filename, mimetype, fileobject)

Does the I/O dirty work after it calls isWriteable to make sure it’s safe to write this file.

class OPSI.web2.static.MetaDataMixin

Bases: object

Mix-in class for L{iweb.IResource} which provides methods for accessing resource metadata specified by HTTP.

contentEncoding()

@return: The encoding of the resource if available, None otherwise.

contentLength()

@return: The size in bytes of the resource if available, None otherwise.

contentType()

@return: The MIME type of the resource if available, None otherwise.

creationDate()

@return: The creation date of the resource if available, None otherwise.

displayName()

@return: The display name of the resource if available, None otherwise.

etag()

@return: The current etag for the resource if available, None otherwise.

exists()

@return: True if the resource exists on the server, False otherwise.

lastModified()

@return: The last modified time of the resource if available, None otherwise.

class OPSI.web2.static.StaticRenderMixin

Bases: OPSI.web2.resource.RenderMixin, OPSI.web2.static.MetaDataMixin

checkPreconditions(request)
renderHTTP(request)

See L{resource.RenderMixIn.renderHTTP}.

This implementation automatically sets some headers on the response based on data available from L{MetaDataMixin} methods.

OPSI.web2.static.addSlash(request)
OPSI.web2.static.getTypeAndEncoding(filename, types, encodings, defaultType)
OPSI.web2.static.isDangerous(path)
OPSI.web2.static.loadMimeTypes(mimetype_locations=['/etc/mime.types'])

Multiple file locations containing mime-types can be passed as a list. The files will be sourced in that order, overriding mime-types from the files sourced beforehand, but only if a new entry explicitly overrides the current entry.