Esempio n. 1
0
 def secret(self):
     if 'secret' in self._data:
         return self._data['secret']
     else:
         secret = random_word(20)
         self.store('secret', secret)
         return secret
Esempio n. 2
0
 def secret(self):
     if 'secret' in self._data:
         return self._data['secret']
     else:
         secret = random_word(20)
         self.store('secret', secret)
         return secret
Esempio n. 3
0
    def _gen_new_code(cls):
        for i in range(200):
            try:
                code = random_word(5, ascii_lowercase + digits)
                self = yield super().create(code)
                return (self, code)

            except DuplicateKeyError:
                msg.try_new_id_after_dup_obj_in_db(cls.path + '.create')
        else:
            msg.exhausted_tries(cls.path + '.create')
Esempio n. 4
0
    def _gen_new_code(cls):
        for i in range(200):
            try:
                code = random_word(
                    5, ascii_lowercase + digits)
                self = yield super().create(code)
                return (self, code)

            except DuplicateKeyError:
                msg.try_new_id_after_dup_obj_in_db(
                    cls.path + '.create')
        else:
            msg.exhausted_tries(cls.path + '.create')
Esempio n. 5
0
 def create(cls, room_id, code_type, seat_id=None):
     code_path = cls.path + '.create'
     creat_err_msg = lambda: msg.obj_creation_error(
         code_path, cls, room_id=room_id,
         code_type=code_type, seat_id=seat_id)
         
     if not isinstance(code_type, CodeType):
         raise TypeError
     
     if seat_id and not isinstance(seat_id, str):
         raise TypeError
     
     if (code_type is CodeType.room) == bool(seat_id):
         raise ValueError
     
     try:
         #Throws NoObjectReturnedFromDB
         room = yield Room(room_id)
             
         for i in range(200):
             try:
                 code = random_word(5,
                     ascii_lowercase+digits)
                 self = yield super().create(code)
                 break
                 
             except DuplicateKeyError:
                 msg.try_new_id_after_dup_obj_in_db(
                     cls.path+'.create')
         else:
             msg.exhausted_tries(cls.path+'.create')
         
         self.setattr('_room', room)
         #Trhows OperationFailure
         yield self.store_dict(
             {'room_id': room_id,
              'code_type': code_type.value,
              'seat_id': seat_id})
         return self
     
     except NoObjectReturnedFromDB:
         creat_err_msg()
         raise OperationFailure
     
     except OperationFailure:
         creat_err_msg()
         cls.coll.remove(code)
         raise