def sign_url(self, method, key, expires, headers=None, params=None): """生成签名URL。 常见的用法是生成加签的URL以供授信用户下载,如为log.jpg生成一个5分钟后过期的下载链接:: >>> bucket.sign_url('GET', 'log.jpg', 5 * 60) 'http://your-bucket.oss-cn-hangzhou.aliyuncs.com/logo.jpg?OSSAccessKeyId=YourAccessKeyId\&Expires=1447178011&Signature=UJfeJgvcypWq6Q%2Bm3IJcSHbvSak%3D' :param method: HTTP方法,如'GET'、'PUT'、'DELETE'等 :type method: str :param key: 文件名 :param expires: 过期时间(单位:秒),链接在当前时间再过expires秒后过期 :param headers: 需要签名的HTTP头部,如名称以x-oss-meta-开头的头部(作为用户自定义元数据)、 Content-Type头部等。对于下载,不需要填。 :type headers: 可以是dict,建议是oss2.CaseInsensitiveDict :param params: 需要签名的HTTP查询参数 :return: 签名URL。 """ key = to_string(key) req = http.Request(method, self._make_url(self.bucket_name, key), headers=headers, params=params) return self.auth._sign_url(req, self.bucket_name, key, expires)
async def _do(self, method, bucket_name, key, **kwargs): key = to_string(key) req = http.Request(method, self._make_url(bucket_name, key), app_name=self.app_name, **kwargs) self.auth._sign_request(req, bucket_name, key) resp = await self.session.do_request(req, timeout=self.timeout) return resp
def __init__(self, resp): RequestResult.__init__(self, resp) self.bucket = "" self.fileSize = 0 self.object = "" self.process_status = "" result = json.loads(to_string(resp.read())) if 'bucket' in result: self.bucket = result['bucket'] if 'fileSize' in result: self.fileSize = result['fileSize'] if 'object' in result: self.object = result['object'] if 'status' in result: self.process_status = result['status']
def _guess_error_details(body): details = {} body = to_string(body) if '<Error>' not in body or '</Error>' not in body: return details m = re.search('<Code>(.*)</Code>', body) if m: details['Code'] = m.group(1) m = re.search('<Message>(.*)</Message>', body) if m: details['Message'] = m.group(1) return details
async def _do(self, method, bucket_name, key, **kwargs): key = to_string(key) req = http.Request(method, self._make_url(bucket_name, key), app_name=self.app_name, **kwargs) self.auth._sign_request(req, bucket_name, key) resp = await self.session.do_request(req, timeout=self.timeout) if resp.status // 100 != 2: e = await exceptions.make_exception(resp) raise e content_length = models._hget(resp.headers, 'content-length', int) if content_length is not None and content_length == 0: await resp.read() return resp
def __init__(self, parent, rpath, bucket, rname): FileInfo.__init__(self, parent, rpath, bucket, rname) self.etag = etag(self.rpath) self.md5 = to_string(self.calculate_file_md5()) self.crc = to_string(self.calculate_file_crc64())