Exemple #1
0
        def fromItem(cls, item):
            """
            Convert an SDB item to an instance of this class.

            :type item: Item
            """
            assert item is not None
            # Strings come back from SDB as unicode
            def strOrNone(s):
                return s if s is None else str(s)

            # ownerID and encrypted are the only mandatory attributes
            ownerID = strOrNone(item.get('ownerID'))
            encrypted = item.get('encrypted')
            if ownerID is None:
                assert encrypted is None
                return None
            else:
                version = strOrNone(item['version'])
                encrypted = strict_bool(encrypted)
                content, numContentChunks = cls.attributesToBinary(item)
                if encrypted:
                    sseKeyPath = cls.outer.sseKeyPath
                    if sseKeyPath is None:
                        raise AssertionError('Content is encrypted but no key was provided.')
                    if content is not None:
                        content = encryption.decrypt(content, sseKeyPath)
                self = cls(fileID=item.name, ownerID=ownerID, encrypted=encrypted, version=version,
                           content=content, numContentChunks=numContentChunks)
                return self
Exemple #2
0
        def fromItem(cls, item):
            """
            Convert an SDB item to an instance of this class.

            :type item: Item
            """
            assert item is not None
            # Strings come back from SDB as unicode
            def strOrNone(s):
                return s if s is None else str(s)

            # ownerID and encrypted are the only mandatory attributes
            ownerID = strOrNone(item.get('ownerID'))
            encrypted = item.get('encrypted')
            if ownerID is None:
                assert encrypted is None
                return None
            else:
                version = strOrNone(item['version'])
                encrypted = strict_bool(encrypted)
                content, numContentChunks = cls.attributesToBinary(item)
                if encrypted:
                    sseKeyPath = cls.outer.sseKeyPath
                    if sseKeyPath is None:
                        raise AssertionError('Content is encrypted but no key was provided.')
                    if content is not None:
                        content = encryption.decrypt(content, sseKeyPath)
                self = cls(fileID=item.name, ownerID=ownerID, encrypted=encrypted, version=version,
                           content=content, numContentChunks=numContentChunks)
                return self
Exemple #3
0
 def writeTo(self, writable):
     chunkStart = 0
     fileSize = int(blobProps['Content-Length'])
     while chunkStart < fileSize:
         chunkEnd = chunkStart + outer_self._maxAzureBlockBytes - 1
         buf = container.get_blob(blob_name=bytes(jobStoreFileID),
                                  x_ms_range="bytes=%d-%d" % (chunkStart, chunkEnd))
         if encrypted:
             buf = encryption.decrypt(buf, outer_self.keyPath)
         writable.write(buf)
         chunkStart = chunkEnd + 1
Exemple #4
0
 def writeTo(self, writable):
     chunkStart = 0
     fileSize = int(blobProps['Content-Length'])
     while chunkStart < fileSize:
         chunkEnd = chunkStart + outer_self._maxAzureBlockBytes - 1
         buf = container.get_blob(blob_name=jobStoreFileID,
                                  x_ms_range="bytes=%d-%d" % (chunkStart, chunkEnd))
         if encrypted:
             buf = encryption.decrypt(buf, outer_self.keyPath)
         writable.write(buf)
         chunkStart = chunkEnd + 1
Exemple #5
0
 def writeTo(self, writable):
     chunkStart = 0
     fileSize = blob.properties.content_length
     while chunkStart < fileSize:
         chunkEnd = chunkStart + outer_self._maxAzureBlockBytes - 1
         buf = container.get_blob_to_bytes(blob_name=str(jobStoreFileID),
                                           start_range=chunkStart,
                                           end_range=chunkEnd).content
         if encrypted:
             buf = encryption.decrypt(buf, outer_self.keyPath)
         writable.write(buf)
         chunkStart = chunkEnd + 1
Exemple #6
0
 def writer():
     try:
         chunkStartPos = 0
         fileSize = int(blobProps['Content-Length'])
         while chunkStartPos < fileSize:
             chunkEndPos = chunkStartPos + self._maxAzureBlockBytes - 1
             buf = container.get_blob(blob_name=jobStoreFileID,
                                      x_ms_range="bytes=%d-%d" % (chunkStartPos,
                                                                  chunkEndPos))
             if encrypted:
                 buf = encryption.decrypt(buf, self.keyPath)
             writable.write(buf)
             chunkStartPos = chunkEndPos + 1
     finally:
         # Ensure readers aren't left blocking if this thread crashes.
         # This close() will send EOF to the reading end and ultimately cause the
         # yield to return. It also makes the implict .close() done by the enclosing
         # "with" context redundant but that should be ok since .close() on file
         # objects are idempotent.
         writable.close()
Exemple #7
0
 def writer():
     try:
         chunkStartPos = 0
         fileSize = int(blobProps['Content-Length'])
         while chunkStartPos < fileSize:
             chunkEndPos = chunkStartPos + self._maxAzureBlockBytes - 1
             buf = container.get_blob(
                 blob_name=jobStoreFileID,
                 x_ms_range="bytes=%d-%d" %
                 (chunkStartPos, chunkEndPos))
             if encrypted:
                 buf = encryption.decrypt(buf, self.keyPath)
             writable.write(buf)
             chunkStartPos = chunkEndPos + 1
     finally:
         # Ensure readers aren't left blocking if this thread crashes.
         # This close() will send EOF to the reading end and ultimately cause the
         # yield to return. It also makes the implict .close() done by the enclosing
         # "with" context redundant but that should be ok since .close() on file
         # objects are idempotent.
         writable.close()