Exemple #1
0
 def __setitem__(self, key, value):
     current_item_size = sum([
         item.size() if type(item) == DynamoType else bytesize(str(item))
         for item in (list(self.keys()) + list(self.values()))
     ])
     new_item_size = bytesize(key) + (value.size() if type(value) ==
                                      DynamoType else bytesize(str(value)))
     # Official limit is set to 400000 (400KB)
     # Manual testing confirms that the actual limit is between 409 and 410KB
     # We'll set the limit to something in between to be safe
     if (current_item_size + new_item_size) > 405000:
         raise ItemSizeTooLarge
     super(LimitedSizeDict, self).__setitem__(key, value)
Exemple #2
0
 def size(self):
     if self.is_number():
         value_size = len(str(self.value))
     elif self.is_set():
         sub_type = self.type[0]
         value_size = sum([DynamoType({sub_type: v}).size() for v in self.value])
     elif self.is_list():
         value_size = sum([v.size() for v in self.value])
     elif self.is_map():
         value_size = sum(
             [bytesize(k) + DynamoType(v).size() for k, v in self.value.items()]
         )
     elif type(self.value) == bool:
         value_size = 1
     else:
         value_size = bytesize(self.value)
     return value_size
Exemple #3
0
 def size(self):
     return sum(
         bytesize(key) + value.size() for key, value in self.attrs.items())