Back to index

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

List of all members.

Public Member Functions

def __init__
def __setstate__
def update
def transform
def __str__
def __len__
def isBinary
def get_size
def getRaw
def portalEncoding
def getContentType
def setContentType
def getFilename
def setFilename
def index_html
 index_html
def PUT
 webDAV me this, webDAV me that
def manage_FTPget

Public Attributes

 id
 mimetype
 binary
 original_encoding
 raw
 size
 filename

Static Public Attributes

int isUnit = 1
tuple security = ClassSecurityInfo()
 content_type = getContentType

Private Member Functions

def _cacheExpire

Private Attributes

 __name__

Static Private Attributes

 __implements__ = WriteLockInterface,z2IBaseUnit
 __call__ = __str__

Detailed Description

Definition at line 24 of file BaseUnit.py.


Constructor & Destructor Documentation

def Archetypes.BaseUnit.BaseUnit.__init__ (   self,
  name,
  file = '',
  instance = None,
  kw 
)

Definition at line 32 of file BaseUnit.py.

00032 
00033     def __init__(self, name, file='', instance=None, **kw):
00034         self.id = self.__name__ = name
00035         self.update(file, instance, **kw)

Here is the caller graph for this function:


Member Function Documentation

Definition at line 131 of file BaseUnit.py.

00131 
00132     def __len__(self):
00133         return self.get_size()

Here is the call graph for this function:

def Archetypes.BaseUnit.BaseUnit.__setstate__ (   self,
  dict 
)

Definition at line 36 of file BaseUnit.py.

00036 
00037     def __setstate__(self, dict):
00038         mimetype = dict.get('mimetype', None)
00039         if IMimetype.isImplementedBy(mimetype):
00040             dict['mimetype'] = str(mimetype)
00041             dict['binary'] = not not mimetype.binary
00042         assert(dict.has_key('mimetype'), 'no mimetype in setstate dict')
00043         File.__setstate__(self, dict)

Definition at line 126 of file BaseUnit.py.

00126 
00127     def __str__(self):
00128         return self.getRaw()

Here is the call graph for this function:

Definition at line 224 of file BaseUnit.py.

00224 
00225     def _cacheExpire(self):
00226         if shasattr(self, '_v_transform_cache'):
00227             delattr(self, '_v_transform_cache')

Here is the call graph for this function:

Here is the caller graph for this function:

Return the file size.

Definition at line 150 of file BaseUnit.py.

00150 
00151     def get_size(self):
00152         """Return the file size.
00153         """
00154         return self.size

Here is the caller graph for this function:

Return the file mimetype string.

Definition at line 189 of file BaseUnit.py.

00189 
00190     def getContentType(self):
00191         """Return the file mimetype string.
00192         """
00193         return self.mimetype

Here is the caller graph for this function:

Return the file name.

Definition at line 209 of file BaseUnit.py.

00209 
00210     def getFilename(self):
00211         """Return the file name.
00212         """
00213         return self.filename

Here is the caller graph for this function:

def Archetypes.BaseUnit.BaseUnit.getRaw (   self,
  encoding = None,
  instance = None 
)
Return the file encoded raw value.

Definition at line 155 of file BaseUnit.py.

00155 
00156     def getRaw(self, encoding=None, instance=None):
00157         """Return the file encoded raw value.
00158         """
00159         # fix AT 1.0 backward problems
00160         if not hasattr(aq_base(self),'raw'):
00161             self.raw = self.data
00162             self.size = len(self.raw)
00163 
00164         if self.isBinary():
00165             return self.raw
00166         # FIXME: backward compat, non binary data
00167         # should always be stored as unicode
00168         if not type(self.raw) is type(u''):
00169             return self.raw
00170         if encoding is None:
00171             if instance is None:
00172                 encoding ='UTF-8'
00173             else:
00174                 # FIXME: fallback to portal encoding or original encoding ?
00175                 encoding = self.portalEncoding(instance)
00176         return self.raw.encode(encoding)

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.BaseUnit.BaseUnit.index_html (   self,
  REQUEST,
  RESPONSE 
)

index_html

download method

Definition at line 230 of file BaseUnit.py.

00230 
00231     def index_html(self, REQUEST, RESPONSE):
00232         """download method"""
00233         filename = self.getFilename()
00234         if filename:
00235             RESPONSE.setHeader('Content-Disposition',
00236                                'attachment; filename=%s' % filename)
00237         RESPONSE.setHeader('Content-Type', self.getContentType())
00238         RESPONSE.setHeader('Content-Length', self.get_size())
00239 
00240         RESPONSE.write(self.getRaw(encoding=self.original_encoding))
00241         return ''

Here is the call graph for this function:

Here is the caller graph for this function:

Return true if this contains a binary value, else false.

Definition at line 134 of file BaseUnit.py.

00134 
00135     def isBinary(self):
00136         """Return true if this contains a binary value, else false.
00137         """
00138         try:
00139             return self.binary
00140         except AttributeError:
00141             # XXX workaround for "[ 1040514 ] AttributeError on some types after
00142             # migration 1.2.4rc5->1.3.0"
00143             # Somehow and sometimes the binary attribute gets lost magically
00144             self.binary = not str(self.mimetype).startswith('text')
00145             log("BaseUnit: Failed to access attribute binary for mimetype %s. "
00146                 "Setting binary to %s" % (self.mimetype, self.binary),
00147                 level=ERROR)
00148             return self.binary

Here is the caller graph for this function:

def Archetypes.BaseUnit.BaseUnit.manage_FTPget (   self,
  REQUEST,
  RESPONSE 
)
Get the raw content for this unit.

Also used for the WebDAV SRC.

Definition at line 265 of file BaseUnit.py.

00265 
00266     def manage_FTPget(self, REQUEST, RESPONSE):
00267         """Get the raw content for this unit.
00268 
00269         Also used for the WebDAV SRC.
00270         """
00271         RESPONSE.setHeader('Content-Type', self.getContentType())
00272         RESPONSE.setHeader('Content-Length', self.get_size())
00273         return self.getRaw(encoding=self.original_encoding)
00274 
00275 InitializeClass(BaseUnit)

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.BaseUnit.BaseUnit.portalEncoding (   self,
  instance 
)
Return the default portal encoding, using an external python script.

Look the archetypes skin directory for the default implementation.

Definition at line 177 of file BaseUnit.py.

00177 
00178     def portalEncoding(self, instance):
00179         """Return the default portal encoding, using an external python script.
00180 
00181         Look the archetypes skin directory for the default implementation.
00182         """
00183         try:
00184             return instance.getCharset()
00185         except AttributeError:
00186             # that occurs during object initialization
00187             # (no acquisition wrapper)
00188             return 'UTF8'

Here is the caller graph for this function:

def Archetypes.BaseUnit.BaseUnit.PUT (   self,
  REQUEST,
  RESPONSE 
)

webDAV me this, webDAV me that

Handle HTTP PUT requests

Definition at line 244 of file BaseUnit.py.

00244 
00245     def PUT(self, REQUEST, RESPONSE):
00246         """Handle HTTP PUT requests"""
00247         self.dav__init(REQUEST, RESPONSE)
00248         self.dav__simpleifhandler(REQUEST, RESPONSE, refresh=1)
00249         mimetype=REQUEST.get_header('Content-Type', None)
00250 
00251         file = REQUEST.get('BODYFILE', _marker)
00252         if file is _marker:
00253             data = REQUEST.get('BODY', _marker)
00254             if data is _marker:
00255                 raise AttributeError, 'REQUEST neither has a BODY nor a BODYFILE'
00256         else:
00257             data = file.read()
00258             file.seek(0)
00259 
00260         self.update(data, self.aq_parent, mimetype=mimetype)
00261 
00262         self.aq_parent.reindexObject()
00263         RESPONSE.setStatus(204)
00264         return RESPONSE

def Archetypes.BaseUnit.BaseUnit.setContentType (   self,
  instance,
  value 
)
Set the file mimetype string.

Definition at line 197 of file BaseUnit.py.

00197 
00198     def setContentType(self, instance, value):
00199         """Set the file mimetype string.
00200         """
00201         mtr = getToolByName(instance, 'mimetypes_registry')
00202         result = mtr.lookup(value)
00203         if not result:
00204             raise ValueError('Unknown mime type %s' % value)
00205         mimetype = result[0]
00206         self.mimetype = str(mimetype)
00207         self.binary = mimetype.binary
00208         self._cacheExpire()

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.BaseUnit.BaseUnit.setFilename (   self,
  filename 
)
Set the file name.

Definition at line 214 of file BaseUnit.py.

00214 
00215     def setFilename(self, filename):
00216         """Set the file name.
00217         """
00218         if type(filename) is StringType:
00219             filename = os.path.basename(filename)
00220             self.filename = filename.split("\\")[-1]
00221         else:
00222             self.filename = filename
00223         self._cacheExpire()

def Archetypes.BaseUnit.BaseUnit.transform (   self,
  instance,
  mt,
  kwargs 
)
Takes a mimetype so object.foo.transform('text/plain') should return
a plain text version of the raw content

return None if no data or if data is untranformable to desired output
mime type

Definition at line 75 of file BaseUnit.py.

00075 
00076     def transform(self, instance, mt, **kwargs):
00077         """Takes a mimetype so object.foo.transform('text/plain') should return
00078         a plain text version of the raw content
00079 
00080         return None if no data or if data is untranformable to desired output
00081         mime type
00082         """
00083         encoding = self.original_encoding
00084         orig = self.getRaw(encoding, instance)
00085         if not orig:
00086             return None
00087 
00088         #on ZODB Transaction commit there is by specification
00089         #no acquisition context. If it is not present, take
00090         #the untransformed getRaw, this is necessary for
00091         #being used with APE
00092         # Also don't break if transform was applied with a stale instance
00093         # from the catalog while rebuilding the catalog
00094         if not hasattr(instance, 'aq_parent'):
00095             return orig
00096 
00097         transformer = getToolByName(instance, 'portal_transforms')
00098         data = transformer.convertTo(mt, orig, object=self, usedby=self.id,
00099                                      context=instance,
00100                                      mimetype=self.mimetype,
00101                                      filename=self.filename)
00102 
00103         if data:
00104             assert idatastream.isImplementedBy(data)
00105             _data = data.getData()
00106             instance.addSubObjects(data.getSubObjects())
00107             portal_encoding = kwargs.get('encoding',None) or \
00108                              self.portalEncoding(instance)
00109             encoding = data.getMetadata().get("encoding") or encoding \
00110                        or portal_encoding
00111             if portal_encoding != encoding:
00112                 _data = unicode(_data, encoding).encode(portal_encoding)
00113             return _data
00114 
00115         # we have not been able to transform data
00116         # return the raw data if it's not binary data
00117         # FIXME: is this really the behaviour we want ?
00118         if not self.isBinary():
00119             portal_encoding = kwargs.get('encoding',None) or \
00120                              self.portalEncoding(instance)
00121             if portal_encoding != encoding:
00122                 orig = self.getRaw(portal_encoding)
00123             return orig
00124 
00125         return None

Here is the call graph for this function:

def Archetypes.BaseUnit.BaseUnit.update (   self,
  data,
  instance,
  kw 
)

Definition at line 44 of file BaseUnit.py.

00044 
00045     def update(self, data, instance, **kw):
00046         #Convert from str to unicode as needed
00047         mimetype = kw.get('mimetype', None)
00048         filename = kw.get('filename', None)
00049         encoding = kw.get('encoding', None)
00050         context  = kw.get('context', instance)
00051 
00052         adapter = getToolByName(context, 'mimetypes_registry')
00053         data, filename, mimetype = adapter(data, **kw)
00054 
00055         assert mimetype
00056         self.mimetype = str(mimetype)
00057         self.binary = mimetype.binary
00058         if not self.isBinary():
00059             assert type(data) is type(u'')
00060             if encoding is None:
00061                 try:
00062                     encoding = adapter.guess_encoding(data)
00063                 except UnboundLocalError:
00064                     # adapter is not defined, we are in object creation
00065                     import site
00066                     encoding = site.encoding
00067             self.original_encoding = encoding
00068         else:
00069             self.original_encoding = None
00070         self.raw  = data
00071         self.size = len(data)
00072         # taking care of stupid IE
00073         self.setFilename(filename)
00074         self._cacheExpire()

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 129 of file BaseUnit.py.

Archetypes.BaseUnit.BaseUnit.__implements__ = WriteLockInterface,z2IBaseUnit [static, private]

Definition at line 25 of file BaseUnit.py.

Definition at line 33 of file BaseUnit.py.

Definition at line 56 of file BaseUnit.py.

Definition at line 195 of file BaseUnit.py.

Definition at line 219 of file BaseUnit.py.

Definition at line 33 of file BaseUnit.py.

Definition at line 28 of file BaseUnit.py.

Definition at line 55 of file BaseUnit.py.

Definition at line 66 of file BaseUnit.py.

Definition at line 69 of file BaseUnit.py.

tuple Archetypes.BaseUnit.BaseUnit.security = ClassSecurityInfo() [static]

Definition at line 30 of file BaseUnit.py.

Definition at line 70 of file BaseUnit.py.


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