Beispiel #1
0
 def _json2item(self, entry, prefix=False):
     
     if prefix :
         ''' 目录 
             {
                 "Prefix": "10000/"
             },
         '''
         isPrefix=True
         return (entry['Prefix'], isPrefix)
     else:
         ''' 文件
             {
                 "SHA1": "61bb70865c151ee0d7ed49ccafd509",
                 "Name": "aa.pdf",
                 "Expiration-Time": null,
                 "Last-Modified": "Tue, 25 Mar 2014 11:16:06 UTC",
                 "Owner": "SINA00000",
                 "MD5": "8ce3e6c0a9818162151",
                 "Content-Type": "application/pdf",
                 "Size": 2430
             },
         '''
         get = lambda tag: entry[tag]
         sha1 = get("SHA1")
         name = get("Name")
         expiration_time = rfc822_parsedate(get("Expiration-Time")) if get("Expiration-Time") else None
         modify = rfc822_parsedate(get("Last-Modified"))
         owner = get("Owner")
         md5 = get("MD5")
         content_type = get("Content-Type")
         size = int(get("Size"))
         isPrefix=False
         return (name, isPrefix, sha1, expiration_time, modify, owner, md5, content_type, size)
Beispiel #2
0
 def list_buckets(self):
     """
         List buckets.
         Yields tuples of (Name, CreationDate).
     """
     scsResponse = self.send(self.request(key=''))
     bucketJsonObj = json.loads(scsResponse.read())
     scsResponse.close()
     
     for item in bucketJsonObj['Buckets']:
         entry = (item['Name'],rfc822_parsedate(item['CreationDate']))
         yield entry