def make_bare_url(self, bucket, key):
     
     buf = ["https://" if self.is_secure else "http://"]
     buf.append(self.server + ":" + str(self.port) + "/" + bucket)        
     buf.append("/" + Utils.urlencode(key))
     
     return ''.join(item for item in buf)
 def generate_url(self, method, bucket, key, path_args, headers):
     
     expires = long(0)
     
     if self.expiresin:
         expires = long(round(time.time() * 1000)) + long(self.expiresin)  #time.time()*1000获取当前时间的毫秒数
     elif self.expires:
         expires = long(self.expires)
     else:
         raise Exception("Illegal expires state")
    
     #单位转换为秒
     expires /= 1000
     canonical_string = Utils.make_canonicalstring(method, bucket, key, path_args, headers, str(expires))
     encoded_canonical = Utils.encode(self.secret_access_key, canonical_string, True)
     
     path_args = path_args if path_args else {}
     path_args["Signature"] = encoded_canonical
     path_args["Expires"] = str(expires)  #将long型转换为string型
     path_args["AWSAccessKeyId"] = self.access_key_id
            
     calling_format = Utils.get_callingformat_for_bucket(self.calling_format, bucket)
     
     if self.is_secure and not isinstance(calling_format, PathFormat) and bucket.find( "." ) != -1:
         raise Exception("You are making an SSL connection, however, the bucket contains periods and \
                          the wildcard certificate will not match by default.  Please consider using HTTP.") 
     
     #需要进行异常检查
     try:
         return_string = calling_format.get_full_url(self.is_secure, self.server, self.port, bucket, key, path_args)
     except Exception as e:
         return_string = "Exception generating url " + e.strerror
            
     return return_string
     
     
     
     
     
 def parse_buckets(xml):
     
     root = ET.fromstring(xml)
     buckets = root.find('{0}Buckets'.format(ListAllMyBuckets.NS)).findall('{0}Bucket'.format(ListAllMyBuckets.NS))
     entries = []
     
     for bucket in buckets:
         name = bucket.find("{0}Name".format(ListAllMyBuckets.NS)).text  #获取bucket的名称
         d = bucket.find("{0}CreationDate".format(ListAllMyBuckets.NS)).text  #获取bucket的创建日期
         creation_date = Utils.transfer_date(d)  #将创建日期转换为当地时间
         
         curr_bucket = Bucket(name, creation_date) #创建bucket对象
         entries.append(curr_bucket)  #向entries列表中添加bucket对象   
     
     return entries
 def get_acl(self, bucket, key, headers):
     path_args = {}
     path_args["acl"] = None
     return self.generate_url("GET", bucket, Utils.urlencode(key), path_args, headers)
    def get(self, bucket, key, headers):

        urlstr = self.generate_url("GET", bucket, Utils.urlencode(key), None, headers)
        return urlstr