示例#1
0
    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)
示例#2
0
    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)
示例#3
0
 def test_encode(self):
     self.assertEquals(
         crockford.b32encode('foo'),
         'CSQPY',
         'b32encode works'
     )
示例#4
0
def crockford_hash(s):
    h = hashlib.md5(s)
    return crockford.b32encode(h.digest())
示例#5
0
def crockford_hash(s):
    h = hashlib.md5(s)
    return crockford.b32encode(h.digest())
示例#6
0
 def test_encode(self):
     self.assertEquals(crockford.b32encode('foo'), 'CSQPY',
                       'b32encode works')