Exemplo n.º 1
0
 def _extract_sid_wid_from_url(self, sheet_url=None):
   url = urlparse.urlparse(sheet_url)
   query_string = urlparse.parse_qs(url.query)
   fragment = urlparse.parse_qs(url.fragment)
   sid = query_string['key'][0]
   gid = fragment['gid'][0]
   wid = basin.encode("0123456789abcdefghijklmnopqrstuvwxyz", int(gid) ^ 31578)  
   return sid, wid
Exemplo n.º 2
0
def detail(request, id):
    alphabet = '0123456789abcdefghijklmnopqrstuvwxyz'
    nid = basin.decode(alphabet, id)

    paste = get_object_or_404(Paste, pk=nid)
    paste.short = basin.encode(alphabet, paste.id)
    
    return render(request, 'paste_detail.html', {'paste' : paste})
Exemplo n.º 3
0
def md5_to_bucket_shard(md5):
    """ calculate the shard label of the bucket name from md5 """
    # "Consider utilizing multiple buckets that start with different
    # alphanumeric characters. This will ensure a degree of partitioning
    # from the start. The higher your volume of concurrent PUT and
    # GET requests, the more impact this will likely have."
    #  -- http://aws.amazon.com/articles/1904
    # "Bucket names must be a series of one or more labels. Adjacent
    # labels are separated by a single period (.). [...] Each label must
    # start and end with a lowercase letter or a number. "
    #  -- http://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html
    # see also:  http://en.wikipedia.org/wiki/Base_36
    ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyz"
    # http://stats.stackexchange.com/a/70884/14900
    # take the first two digits of the hash and turn that into an inteter
    # this should be evenly distributed
    int_value = int(md5[0], 16)+10*int(md5[1], 16)
    # divide by the length of the alphabet and take the remainder
    bucket = int_value % len(ALPHABET)
    return basin.encode(ALPHABET, bucket)
Exemplo n.º 4
0
def _encode(bytes):
    return basin.encode('23456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ', basin.bytestring_to_integer(bytes))