Example #1
0
def PUT_factory(self, name, typ, body):
    '''Creates ExtImage instead of plain Image.'''
    ct, w, h = getImageInfo(body)
    if ct:
        major, minor = string.split(ct, '/')
        if major == 'image':
            return ExtImage(name, '', '')
    major, minor = string.split(typ, '/')
    if major == 'image':
        return ExtImage(name, '', '')
    return None
Example #2
0
    def __init__(self, id, title, file, content_type='', precondition=''):
        try: id = id()
        except TypeError: pass

        self.__name__ = id
        self.title = title
        self.data = ''
        self.size = 0
        self.width = -1
        self.height = -1
        self.content_type = content_type
        self.precondition = precondition
        self._ext_file = ExtImage(id, title)
Example #3
0
class NyFSImage(NyFSFile):
    """ """
    width = ''
    height = ''

    def __init__(self, id, title, file, content_type='', precondition=''):
        try:
            id = id()
        except TypeError:
            pass

        self.__name__ = id
        self.title = title
        self.data = ''
        self.size = 0
        self.width = -1
        self.height = -1
        self.content_type = content_type
        self.precondition = precondition
        self._ext_file = ExtImage(id, title)

    def tag(self,
            height=None,
            width=None,
            alt=None,
            scale=0,
            xscale=0,
            yscale=0,
            css_class=None,
            title=None,
            **args):
        return self._ext_file.tag(height=height,
                                  width=width,
                                  alt=alt,
                                  scale=scale,
                                  xscale=xscale,
                                  yscale=yscale,
                                  **args)

    def __str__(self):
        return self.tag()

    def update_data(self, data, content_type=None, size=None):
        file = data
        data, size = self._read_data(data)
        content_type = self._get_content_type(file, data, self.__name__,
                                              'application/octet-stream')
        ct, width, height = getImageInfo(data)
        if ct:
            content_type = ct
        if width >= 0 and height >= 0:
            self.width = width
            self.height = height
        NyFSImage.inheritedAttribute('update_data')(self, data, content_type,
                                                    size)
Example #4
0
    def __init__(self, id, title, file, content_type='', precondition=''):
        try: id = id()
        except TypeError: pass

        self.__name__ = id
        self.title = title
        self.data = ''
        self.size = 0
        self.width = -1
        self.height = -1
        self.content_type = content_type
        self.precondition = precondition
        self._ext_file = ExtImage(id, title)
Example #5
0
def toExtImage(self, id, backup=0):
    '''Converts plain Image to ExtImage. 
	   Call this method in the Folder context and pass the id.
	   Must have threads, will not work in debugger!'''
    oldId = str(id)
    oldOb = self._getOb(oldId)
    newId = oldId + '___tmp'
    ximOb = ExtImage(oldId, oldOb.title)
    newId = self._setObject(newId, ximOb)
    newOb = self._getOb(newId)
    newOb.manage_http_upload(oldOb.absolute_url())
    newOb.content_type = oldOb.content_type
    if backup: self.manage_renameObjects([oldId], [oldId + '_bak'])
    else: self.manage_delObjects([oldId])
    self.manage_renameObjects([newId], [oldId])
Example #6
0
class NyFSImage(NyFSFile):
    """ """

    width = ""
    height = ""

    def __init__(self, id, title, file, content_type="", precondition=""):
        try:
            id = id()
        except TypeError:
            pass

        self.__name__ = id
        self.title = title
        self.data = ""
        self.size = 0
        self.width = -1
        self.height = -1
        self.content_type = content_type
        self.precondition = precondition
        self._ext_file = ExtImage(id, title)

    def tag(self, height=None, width=None, alt=None, scale=0, xscale=0, yscale=0, css_class=None, title=None, **args):
        return self._ext_file.tag(
            height=height, width=width, alt=alt, scale=scale, xscale=xscale, yscale=yscale, **args
        )

    def __str__(self):
        return self.tag()

    def update_data(self, data, content_type=None, size=None, filename=""):
        file = data
        data, size = self._read_data(data)
        if not filename:
            filename = getattr(file, "filename", "")
        content_type = self._get_content_type(file, data, self.__name__, "application/octet-stream")
        ct, width, height = getImageInfo(data)
        if ct:
            content_type = ct
        if width >= 0 and height >= 0:
            self.width = width
            self.height = height
        NyFSImage.inheritedAttribute("update_data")(self, data, content_type, size, filename)