コード例 #1
0
ファイル: object_storage.py プロジェクト: fvennetier/oiopy
 def _connect_put(chunk):
     raw_url = chunk["url"]
     parsed = urlparse(raw_url)
     try:
         chunk_path = parsed.path.split('/')[-1]
         hdrs = {}
         hdrs["transfer-encoding"] = "chunked"
         hdrs[chunk_headers["content_id"]] = sysmeta['id']
         hdrs[chunk_headers["content_version"]] = sysmeta['version']
         hdrs[chunk_headers["content_path"]] = utils.quote(obj_name)
         hdrs[chunk_headers["content_size"]] = sysmeta['content_length']
         hdrs[chunk_headers["content_chunkmethod"]] = \
             sysmeta['chunk_method']
         hdrs[chunk_headers["content_mimetype"]] = sysmeta['mime_type']
         hdrs[chunk_headers["content_policy"]] = sysmeta['policy']
         hdrs[chunk_headers["content_chunksnb"]] = len(chunks)
         hdrs[chunk_headers["container_id"]] = \
             utils.name2cid(account, container)
         hdrs[chunk_headers["chunk_pos"]] = chunk["pos"]
         hdrs[chunk_headers["chunk_id"]] = chunk_path
         with ConnectionTimeout(CONNECTION_TIMEOUT):
             conn = http_connect(
                 parsed.netloc, 'PUT', parsed.path, hdrs)
             conn.chunk = chunk
         return conn
     except (Exception, Timeout):
         pass
コード例 #2
0
ファイル: io.py プロジェクト: carriercomm/oiopy
 def _get_request(self, chunk):
     # connect to chunk
     try:
         with ConnectionTimeout(self.connection_timeout):
             raw_url = chunk["url"]
             parsed = urlparse(raw_url)
             conn = http_connect(parsed.netloc, 'GET', parsed.path,
                                 self.request_headers)
         with Timeout(self.response_timeout):
             source = conn.getresponse(True)
             source.conn = conn
     except (Exception, Timeout):
         logger.exception('Connection failed to %s', chunk)
         return False
     if source.status in (200, 206):
         self.status = source.status
         self._headers = source.getheaders()
         self.sources.append((source, chunk))
         return True
     else:
         logger.warn("Invalid GET response from %s", chunk)
     return False
コード例 #3
0
ファイル: object_storage.py プロジェクト: fvennetier/oiopy
    def _get_chunk_source(self):
        source = None
        for chunk in self.chunks:
            try:
                with ConnectionTimeout(CONNECTION_TIMEOUT):
                    raw_url = chunk["url"]
                    parsed = urlparse(raw_url)
                    conn = http_connect(parsed.netloc, 'GET', parsed.path,
                                        self.headers)
                source = conn.getresponse(True)
                source.conn = conn

            except (Timeout, Exception):
                self.failed_chunks.append(chunk)
                continue
            if source.status not in (200, 206):
                self.failed_chunks.append(chunk)
                close_source(source)
                source = None
            else:
                break

        return source