Ejemplo n.º 1
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)}
        response = self.connection.get_object(self.bucket, name, headers)
        if (response.status / 100) != 2:
            raise IOError('OSSStorageError: %s' % response.read())

        header_map = convert_header2map(response.getheaders())
        content_len = safe_get_element('content-length', header_map)
        etag = safe_get_element('etag', header_map).upper()
        return response.read(), etag, content_len
Ejemplo n.º 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)}
        response = self.connection.get_object(self.bucket, name, headers)
        if (response.status / 100) != 2:
            raise IOError("OSSStorageError: %s" % response.read())

        header_map = convert_header2map(response.getheaders())
        content_len = safe_get_element("content-length", header_map)
        etag = safe_get_element("etag", header_map).upper()
        return response.read(), etag, content_len
Ejemplo n.º 3
0
 def modified_time(self, name):
     try:
         from dateutil import parser, tz
     except ImportError:
         raise NotImplementedError()
     name = self._clean_name(name)
     response = self.connection.head_object(self.bucket, name)
     header_map = convert_header2map(response.getheaders())
     last_modified = response.getheader('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 is 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)
Ejemplo n.º 4
0
 def size(self, name):
     name = self._clean_name(name)
     response = self.connection.head_object(self.bucket, name)
     header_map = convert_header2map(response.getheaders())
     content_len = safe_get_element('content-length', header_map)
     return content_len and int(content_len) or 0
Ejemplo n.º 5
0
 def size(self, name):
     name = self._clean_name(name)
     response = self.connection.head_object(self.bucket, name)
     header_map = convert_header2map(response.getheaders())
     content_len = safe_get_element("content-length", header_map)
     return content_len and int(content_len) or 0