Пример #1
0
 def size(self, name):
     name = self._clean_name(name)
     if self.entries:
         entry = self.entries.get(name)
         if entry:
             return int(entry[3])
         return 0
     
     res = self.connection.head_object(self.bucket, name, self.headers)
     if (res.status / 100) == 2:
         header_map = convert_header2map(res.getheaders())
         content_length = safe_get_element("content-length", header_map)
     
     return content_length and int(content_length) or 0
Пример #2
0
    def _read(self, name, start_range=None, end_range=None):
        name = self._clean_name(name)
        if start_range is None:
            headers = {}
        else:
            headers = {'Range': 'bytes=%s-%s' % (start_range, end_range)}
        
        res = self.connection.get_object(self.bucket, name, headers)
        
        if (res.status / 100) == 2:
            header_map = convert_header2map(res.getheaders())
            etag = safe_get_element("etag", header_map).upper()
            content_range = safe_get_element("content-range", header_map)

            if self.encrypt:
                pass

            return res.read(), etag, content_range
        else:
            raise IOError("OssStorageError: %s" % res.read())
Пример #3
0
 def modified_time(self, name):
     try:
        from dateutil import parser, tz
     except ImportError:
         raise NotImplementedError()
     name = self._clean_name(name)
     if self.entries:
         last_modified = self.entries.get(name)[1]
     else:
         res = self.connection.head_object(self.bucket, name)
         header_map = convert_header2map(res.getheaders())
         last_modified = safe_get_element('Last-Modified', header_map)
         last_modified = unicode(last_modified)
     
     # convert to string to date
     last_modified_date = parser.parse(last_modified)
     # if the date has no timzone, assume UTC
     if last_modified_date.tzinfo == None:
         last_modified_date = last_modified_date.replace(tzinfo=tz.tzutc())
     # convert date to local time w/o timezone
     return last_modified_date.astimezone(tz.tzlocal()).replace(tzinfo=None)