Example #1
0
 def write_file(self, f, filename):
     identifier = random_url_id(16)
     blob_info = self._db.put(f, bucket=self._bucket, identifier=identifier)
     assert identifier == blob_info.identifier
     file_meta = self._meta_model(identifier=identifier, filename=filename,
                                  length=blob_info.length)
     file_meta.save()
     return file_meta
Example #2
0
 def write_file(self, f, filename):
     identifier = random_url_id(16)
     blob_info = self._db.put(f, bucket=self._bucket, identifier=identifier)
     assert identifier == blob_info.identifier
     file_meta = self._meta_model(identifier=identifier, filename=filename,
                                  length=blob_info.length)
     file_meta.save()
     return file_meta
Example #3
0
    def _write_restore_blob(self, restore, db):

        if isinstance(restore, six.text_type):
            restore = io.BytesIO(restore.encode("utf-8"))
        elif isinstance(restore, bytes):
            restore = io.BytesIO(restore)

        info = db.put(restore, random_url_id(16))
        self.restore_blob_id = info.identifier
        self.content_length = info.length
def check_blobdb():
    """Save something to the blobdb and try reading it back."""
    db = get_blob_db()
    contents = b"It takes Pluto 248 Earth years to complete one orbit!"
    info = db.put(BytesIO(contents), random_url_id(16))
    with db.get(info.identifier) as fh:
        res = fh.read()
    db.delete(info.identifier)
    if res == contents:
        return ServiceStatus(True, "Successfully saved a file to the blobdb")
    return ServiceStatus(False, "Failed to save a file to the blobdb")
Example #5
0
 def write_file(self, f, filename, domain):
     identifier = random_url_id(16)
     meta = get_blob_db().put(f,
                              domain=domain,
                              parent_id=domain,
                              type_code=CODES.data_import,
                              key=identifier)
     assert identifier == meta.key, (identifier, meta.key)
     file_meta = self._meta_model(identifier=identifier,
                                  filename=filename,
                                  length=meta.content_length)
     file_meta.save()
     return file_meta
Example #6
0
 def write_file(self, f, filename, domain):
     identifier = random_url_id(16)
     meta = get_blob_db().put(
         f,
         domain=domain,
         parent_id=domain,
         type_code=CODES.data_import,
         key=identifier
     )
     assert identifier == meta.key, (identifier, meta.key)
     file_meta = self._meta_model(identifier=identifier, filename=filename,
                                  length=meta.content_length)
     file_meta.save()
     return file_meta
Example #7
0
 def create_obj(rex):
     ident = random_url_id(8)
     args = {rex.blob_helper.id_attr: ident}
     fields = {getattr(f, "attname", "")
         for f in rex.model_class._meta.get_fields()}
     if "content_length" in fields:
         args["content_length"] = len(data)
     elif "length" in fields:
         args["length"] = len(data)
     item = rex.model_class(**args)
     save_attr = rex.model_class.__name__ + "_save"
     if hasattr(self, save_attr):
         getattr(self, save_attr)(item, rex)
     else:
         item.save()
     return item, ident
Example #8
0
def get_short_identifier():
    """Get a short random identifier

    The identifier is chosen from a 64 bit key space, which is suitably
    large for no likely collisions in 1000 concurrent keys but kept
    small to minimize key length. 1000 is an arbitrary number chosen as
    an upper bound of the number of attachments associated with any
    given object. We may need to change this if we ever expect an object
    to have significantly more than 1000 attachments. The probability of
    a collision with a 64 bit ID is:

    k = 1000
    N = 2 ** 64
    (k ** 2) / (2 * N) = 2.7e-14

    which is somewhere near the probability of a meteor landing on
    your house. For most objects the number of blobs present at any
    moment in time will be far lower, and therefore the probability
    of a collision will be much lower as well.

    http://preshing.com/20110504/hash-collision-probabilities/
    """
    return random_url_id(8)
Example #9
0
def get_short_identifier():
    """Get a short random identifier

    The identifier is chosen from a 64 bit key space, which is suitably
    large for no likely collisions in 1000 concurrent keys but kept
    small to minimize key length. 1000 is an arbitrary number chosen as
    an upper bound of the number of attachments associated with any
    given object. We may need to change this if we ever expect an object
    to have significantly more than 1000 attachments. The probability of
    a collision with a 64 bit ID is:

    k = 1000
    N = 2 ** 64
    (k ** 2) / (2 * N) = 2.7e-14

    which is somewhere near the probability of a meteor landing on
    your house. For most objects the number of blobs present at any
    moment in time will be far lower, and therefore the probability
    of a collision will be much lower as well.

    http://preshing.com/20110504/hash-collision-probabilities/
    """
    return random_url_id(8)
Example #10
0
def get_id():
    return random_url_id(8)
Example #11
0
 def setUp(self):
     self.ids = [mod.random_url_id(8) for x in range(self.sample_size)]
Example #12
0
 def setUp(self):
     self.ids = [mod.random_url_id(8) for x in xrange(self.sample_size)]