Пример #1
0
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
Пример #2
0
 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
Пример #3
0
 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')