Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions
CMFCore.FSFile.FSFile Class Reference
Inheritance diagram for CMFCore.FSFile.FSFile:
Inheritance graph
[legend]
Collaboration diagram for CMFCore.FSFile.FSFile:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def __str__
 The following is mainly taken from OFS/File.py ###.
def modified
def index_html
def getContentType

Public Attributes

 content_type

Static Public Attributes

string meta_type = 'Filesystem File'
string content_type = 'unknown/unknown'
tuple manage_options = ({'label':'Customize', 'action':'manage_main'},)
tuple security = ClassSecurityInfo()
tuple manage_main = Globals.DTMLFile('custfile', _dtmldir)
 manage_FTPget = index_html

Private Member Functions

def _createZODBClone
def _get_content_type
def _readFile
def _setOldCacheHeaders

Detailed Description

FSFiles act like images but are not directly
modifiable from the management interface.

Definition at line 39 of file FSFile.py.


Constructor & Destructor Documentation

def CMFCore.FSFile.FSFile.__init__ (   self,
  id,
  filepath,
  fullname = None,
  properties = None 
)

Definition at line 56 of file FSFile.py.

00056 
00057     def __init__(self, id, filepath, fullname=None, properties=None):
00058         id = fullname or id # Use the whole filename.
00059         FSObject.__init__(self, id, filepath, fullname, properties)


Member Function Documentation

The following is mainly taken from OFS/File.py ###.

Definition at line 107 of file FSFile.py.

00107 
00108     def __str__(self):
00109         self._updateFromFS()
00110         return str( self._readFile( 0 ) )

Here is the call graph for this function:

def CMFCore.FSFile.FSFile._createZODBClone (   self) [private]

Definition at line 60 of file FSFile.py.

00060 
00061     def _createZODBClone(self):
00062         return File(self.getId(), '', self._readFile(1))

Here is the caller graph for this function:

def CMFCore.FSFile.FSFile._get_content_type (   self,
  file,
  body,
  id,
  content_type = None 
) [private]

Definition at line 63 of file FSFile.py.

00063 
00064     def _get_content_type(self, file, body, id, content_type=None):
00065         # Consult self.content_type first, this is either
00066         # the default (unknown/unknown) or it got a value from a
00067         # .metadata file
00068         default_type = 'unknown/unknown'
00069         if getattr(self, 'content_type', default_type) != default_type:
00070             return self.content_type
00071 
00072         # Next, look at file headers
00073         headers=getattr(file, 'headers', None)
00074         if headers and headers.has_key('content-type'):
00075             content_type=headers['content-type']
00076         else:
00077             # Last resort: Use the (imperfect) content type guessing
00078             # mechanism from OFS.Image, which ultimately uses the
00079             # Python mimetypes module.
00080             if not isinstance(body, basestring):
00081                 body = body.data
00082             content_type, enc=guess_content_type(
00083                 getattr(file, 'filename',id), body, content_type)
00084             if (enc is None
00085                 and (content_type.startswith('text/') or
00086                      content_type.startswith('application/'))
00087                 and body.startswith(codecs.BOM_UTF8)):
00088                 content_type += '; charset=utf-8'
00089 
00090         return content_type

def CMFCore.FSFile.FSFile._readFile (   self,
  reparse 
) [private]
Read the data from the filesystem.

Definition at line 91 of file FSFile.py.

00091 
00092     def _readFile(self, reparse):
00093         """Read the data from the filesystem.
00094         """
00095         file = open(self._filepath, 'rb')
00096         try:
00097             data = file.read()
00098         finally:
00099             file.close()
00100 
00101         if reparse or self.content_type == 'unknown/unknown':
00102             self.ZCacheable_invalidate()
00103             self.content_type=self._get_content_type(file, data, self.id)
00104         return data

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 151 of file FSFile.py.

00151 
00152     def _setOldCacheHeaders(self):
00153         # return False to disable this simple caching behaviour
00154         return _FSCacheHeaders(self)

Here is the call graph for this function:

Here is the caller graph for this function:

Get the content type of a file or image.

Returns the content type (MIME type) of a file or image.

Definition at line 156 of file FSFile.py.

00156 
00157     def getContentType(self):
00158         """Get the content type of a file or image.
00159 
00160         Returns the content type (MIME type) of a file or image.
00161         """
00162         self._updateFromFS()
00163         return self.content_type

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFCore.FSFile.FSFile.index_html (   self,
  REQUEST,
  RESPONSE 
)
The default view of the contents of a File or Image.

Returns the contents of the file or image.  Also, sets the
Content-Type HTTP header to the objects content type.

Definition at line 115 of file FSFile.py.

00115 
00116     def index_html(self, REQUEST, RESPONSE):
00117         """
00118         The default view of the contents of a File or Image.
00119 
00120         Returns the contents of the file or image.  Also, sets the
00121         Content-Type HTTP header to the objects content type.
00122         """
00123         self._updateFromFS()
00124         view = _ViewEmulator().__of__(self)
00125 
00126         # If we have a conditional get, set status 304 and return
00127         # no content
00128         if _checkConditionalGET(view, extra_context={}):
00129             return ''
00130 
00131         RESPONSE.setHeader('Content-Type', self.content_type)
00132 
00133         # old-style If-Modified-Since header handling.
00134         if self._setOldCacheHeaders():
00135             # Make sure the CachingPolicyManager gets a go as well
00136             _setCacheHeaders(view, extra_context={})
00137             return ''
00138 
00139         data = self._readFile(0)
00140         data_len = len(data)
00141         RESPONSE.setHeader('Content-Length', data_len)
00142 
00143         #There are 2 Cache Managers which can be in play....
00144         #need to decide which to use to determine where the cache headers
00145         #are decided on.
00146         if self.ZCacheable_getManager() is not None:
00147             self.ZCacheable_set(None)
00148         else:
00149             _setCacheHeaders(view, extra_context={})
00150         return data

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 111 of file FSFile.py.

00111 
00112     def modified(self):
00113         return self.getModTime()

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

string CMFCore.FSFile.FSFile.content_type = 'unknown/unknown' [static]

Definition at line 46 of file FSFile.py.

Definition at line 100 of file FSFile.py.

Definition at line 165 of file FSFile.py.

tuple CMFCore.FSFile.FSFile.manage_main = Globals.DTMLFile('custfile', _dtmldir) [static]

Definition at line 54 of file FSFile.py.

tuple CMFCore.FSFile.FSFile.manage_options = ({'label':'Customize', 'action':'manage_main'},) [static]

Definition at line 48 of file FSFile.py.

string CMFCore.FSFile.FSFile.meta_type = 'Filesystem File' [static]

Definition at line 45 of file FSFile.py.

tuple CMFCore.FSFile.FSFile.security = ClassSecurityInfo() [static]

Definition at line 50 of file FSFile.py.


The documentation for this class was generated from the following file: