def render_POST(self, request): uri = request.args.get('uri', []) if not uri or not tahoeRegex.match(uri[0]): return self.render_GET(request) ext = request.args.get('ext', []) b64uri = base64.urlsafe_b64encode(uri[0]) extension = '' if ext and ext[0]: extension = '.' + ext[0].lstrip('.') if uri[0] not in self.shortdb: while True: short = crockford.b32encode(os.urandom(9)).lower() if short not in self.shortdb: break self.shortdb[short] = uri[0] self.shortdb[uri[0]] = short self.shortdb.sync() else: short = self.shortdb[uri[0]] if request.args.get('api', []): return '/' + short + extension body = tags.p( tags.a('long url', href=b64uri + extension), '; ', tags.a('medium url', href='/' + uri[0] + extension), '; ', tags.a('short url', href=short + extension)) return renderElement(request, body)
def render_POST(self, request): uri = request.args.get('uri', []) if not uri or not tahoeRegex.match(uri[0]): return self.render_GET(request) ext = request.args.get('ext', []) b64uri = base64.urlsafe_b64encode(uri[0]) extension = '' if ext and ext[0]: extension = '.' + ext[0].lstrip('.') if uri[0] not in self.shortdb: while True: short = crockford.b32encode(os.urandom(9)).lower() if short not in self.shortdb: break self.shortdb[short] = uri[0] self.shortdb[uri[0]] = short self.shortdb.sync() else: short = self.shortdb[uri[0]] if request.args.get('api', []): return '/' + short + extension body = tags.p(tags.a('long url', href=b64uri + extension), '; ', tags.a('medium url', href='/' + uri[0] + extension), '; ', tags.a('short url', href=short + extension)) return renderElement(request, body)
def test_encode(self): self.assertEquals( crockford.b32encode('foo'), 'CSQPY', 'b32encode works' )
def crockford_hash(s): h = hashlib.md5(s) return crockford.b32encode(h.digest())
def test_encode(self): self.assertEquals(crockford.b32encode('foo'), 'CSQPY', 'b32encode works')