예제 #1
0
파일: blob.py 프로젝트: 02strich/pyazure
 def delete_container(self, container_name):
     req = RequestWithMethod("DELETE", "%s/%s?restype=container" % (self.base_url, container_name))
     req.add_header("x-ms-version", "2011-08-18")
     self.credentials.sign_request(req)
     try:
         response = urlopen(req)
         return response.code
     except URLError, e:
         return e.code
예제 #2
0
 def delete_container(self, container_name):
     req = RequestWithMethod(
         "DELETE",
         "%s/%s?restype=container" % (self.base_url, container_name))
     req.add_header("x-ms-version", "2011-08-18")
     self.credentials.sign_request(req)
     try:
         response = urlopen(req)
         return response.code
     except URLError, e:
         return e.code
예제 #3
0
파일: blob.py 프로젝트: 02strich/pyazure
 def list_containers(self):
     req = RequestWithMethod("GET", "%s/?comp=list" % self.base_url)
     req.add_header("x-ms-version", "2011-08-18")
     self.credentials.sign_request(req)
     dom = etree.parse(urlopen(req))
     
     containers = dom.findall(".//Container")
     for container in containers:
         container_name = container.find("Name").text
         properties = container.find("Properties")
         etag = properties.find("Etag").text
         last_modified = time.strptime(properties.find("Last-Modified").text, TIME_FORMAT)
         yield (container_name, etag, last_modified)
예제 #4
0
    def list_containers(self):
        req = RequestWithMethod("GET", "%s/?comp=list" % self.base_url)
        req.add_header("x-ms-version", "2011-08-18")
        self.credentials.sign_request(req)
        dom = etree.parse(urlopen(req))

        containers = dom.findall(".//Container")
        for container in containers:
            container_name = container.find("Name").text
            properties = container.find("Properties")
            etag = properties.find("Etag").text
            last_modified = time.strptime(
                properties.find("Last-Modified").text, TIME_FORMAT)
            yield (container_name, etag, last_modified)
예제 #5
0
파일: blob.py 프로젝트: glyuck/pyazure
 def list_blobs(self, container_name):
     req = RequestWithMethod("GET", "%s/%s?restype=container&comp=list" % (self.base_url, container_name))
     req.add_header("x-ms-version", "2011-08-18")
     self.credentials.sign_request(req)
     dom = etree.fromstring(urlopen(req).read())
     
     blobs = dom.findall(".//Blob")
     for blob in blobs:
         blob_name = blob.find("Name").text
         blob_properties = blob.find("Properties")
         etag = blob_properties.find("Etag").text
         size = blob_properties.find("Content-Length").text
         last_modified = time.strptime(blob_properties.find("Last-Modified").text, TIME_FORMAT)
         yield (blob_name, etag, last_modified, size)
예제 #6
0
파일: blob.py 프로젝트: 02strich/pyazure
 def put_blob(self, container_name, blob_name, data, content_type = None, page_block = False):
     req = RequestWithMethod("PUT", "%s/%s/%s" % (self.base_url, container_name, blob_name), data=data)
     req.add_header("x-ms-version", "2011-08-18")
     req.add_header("x-ms-blob-type", "PageBlob" if page_block else "BlockBlob")
     req.add_header("Content-Length", "%d" % len(data))
     req.add_header("Content-Type", content_type if content_type is not None else "") # urllib2 has dubious content-type meddling behaviour
     self.credentials.sign_request(req)
     try:
         response = urlopen(req)
         return response.code
     except URLError, e:
         return e.code
예제 #7
0
    def list_blobs(self, container_name, prefix=''):
        url = "%s/%s?restype=container&comp=list" % (self.base_url,
                                                     container_name)
        if prefix:
            url += '&prefix=' + quote(prefix)
        req = RequestWithMethod("GET", url)
        req.add_header("x-ms-version", "2011-08-18")
        self.credentials.sign_request(req)
        dom = etree.fromstring(urlopen(req).read())

        blobs = dom.findall(".//Blob")
        for blob in blobs:
            blob_name = blob.find("Name").text
            blob_properties = blob.find("Properties")
            etag = blob_properties.find("Etag").text
            size = blob_properties.find("Content-Length").text
            last_modified = time.strptime(
                blob_properties.find("Last-Modified").text, TIME_FORMAT)
            yield (blob_name, etag, last_modified, size)
예제 #8
0
 def create_container(self, container_name, is_public=False):
     req = RequestWithMethod(
         "PUT", "%s/%s?restype=container" % (self.base_url, container_name))
     req.add_header("x-ms-version", "2011-08-18")
     req.add_header("Content-Length", "0")
     if is_public: req.add_header("x-ms-blob-public-access", "blob")
     self.credentials.sign_request(req)
     try:
         response = urlopen(req)
         return response.code
     except URLError, e:
         return e.code
예제 #9
0
파일: blob.py 프로젝트: 02strich/pyazure
 def create_container(self, container_name, is_public = False):
     req = RequestWithMethod("PUT", "%s/%s?restype=container" % (self.base_url, container_name))
     req.add_header("x-ms-version", "2011-08-18")
     req.add_header("Content-Length", "0")
     if is_public: req.add_header("x-ms-blob-public-access", "blob")
     self.credentials.sign_request(req)
     try:
         response = urlopen(req)
         return response.code
     except URLError, e:
         return e.code
예제 #10
0
 def put_blob(self,
              container_name,
              blob_name,
              data,
              content_type=None,
              page_block=False):
     req = RequestWithMethod("PUT",
                             "%s/%s/%s" %
                             (self.base_url, container_name, blob_name),
                             data=data)
     req.add_header("x-ms-version", "2011-08-18")
     req.add_header("x-ms-blob-type",
                    "PageBlob" if page_block else "BlockBlob")
     req.add_header("Content-Length", "%d" % len(data))
     req.add_header(
         "Content-Type", content_type if content_type is not None else
         "")  # urllib2 has dubious content-type meddling behaviour
     self.credentials.sign_request(req)
     try:
         response = urlopen(req)
         return response.code
     except URLError, e:
         return e.code
예제 #11
0
 def delete_blob(self, container_name, blob_name):
     req = RequestWithMethod(
         "DELETE", "%s/%s/%s" % (self.base_url, container_name, blob_name))
     req.add_header("x-ms-version", "2011-08-18")
     self.credentials.sign_request(req)
     return urlopen(req).read()
예제 #12
0
파일: blob.py 프로젝트: 02strich/pyazure
 def delete_blob(self, container_name, blob_name):
     req = RequestWithMethod("DELETE", "%s/%s/%s" % (self.base_url, container_name, blob_name))
     req.add_header("x-ms-version", "2011-08-18")
     self.credentials.sign_request(req)
     return urlopen(req).read()