Exemplo n.º 1
0
 def _open(self, name, mode="rb"):
     """
     Return a File object.
     """
     attachment = Attachment.objects.using(self.using).get(attachment__exact=name)
     fname = File(StringIO(attachment.blob), attachment.filename)
     
     # Make sure the checksum match before returning the file
     if not md5buffer(fname) == attachment.checksum:
         raise IntegrityError("Checksum mismatch")
     
     fname.size = attachment.size
     fname.mode = mode
     return fname
Exemplo n.º 2
0
 def _open(self, name, mode="rb"):
     """
     Read the file from the database, and return
     as a File instance.
     """
     attachment = Attachment.objects.using(self.using).get(attachment__exact=name)
     cursor = connections[self.using].cursor()
     lobject = cursor.db.connection.lobject(attachment.blob, "r")
     fname = File(StringIO(lobject.read()), attachment.filename)
     lobject.close()
     
     # Make sure the checksum match before returning the file
     if not md5buffer(fname) == attachment.checksum:
         raise IntegrityError("Checksum mismatch")
     
     fname.size = attachment.size
     fname.mode = mode
     
     return fname