def new_intid(): uid = randint(0, MAX_INT) base_id = encode(uid) try: URL.m.find({'_id' : uid }).one() uid = new_intid() except ValueError: pass # It doesn't exist; let's use it return uid
def make_url(self, url): intid = new_intid() short_url = encode(intid) model = URL(intid, url, short_url=short_url) model.m.save() return short_url
def test_encode(self): decode, encode, map_dict = self._make_codec() self.assertEqual(encode(0), u'A') self.assertEqual(encode(10), u'+') self.assertEqual(encode(7), u'\xe4') self.assertEqual(encode(4), u'2')