<s> import six <EOL> from six . moves . urllib . parse import urlencode <EOL> from uuid import uuid4 <EOL> from struct import unpack <EOL> def url_concat ( url , args , fragments = None ) : <EOL> """<STR_LIT>""" <EOL> if not args and not fragments : <EOL> return url <EOL> while url [ - <NUM_LIT:1> ] == '<STR_LIT:#>' : <EOL> url = url [ : - <NUM_LIT:1> ] <EOL> fragment_tail = '<STR_LIT>' <EOL> if fragments : <EOL> fragment_tail = '<STR_LIT:#>' + urlencode ( fragments ) <EOL> args_tail = '<STR_LIT>' <EOL> if args : <EOL> if url [ - <NUM_LIT:1> ] not in ( '<STR_LIT:?>' , '<STR_LIT:&>' ) : <EOL> args_tail += '<STR_LIT:&>' if ( '<STR_LIT:?>' in url ) else '<STR_LIT:?>' <EOL> args_tail += urlencode ( args ) <EOL> return url + args_tail + fragment_tail <EOL> def generate_id ( ) : <EOL> a , b = unpack ( '<STR_LIT>' , uuid4 ( ) . bytes ) <EOL> num = a << <NUM_LIT:64> | b <EOL> alphabet = '<STR_LIT>' <EOL> base36 = '<STR_LIT>' <EOL> while num : <EOL> num , i = divmod ( num , <NUM_LIT> ) <EOL> base36 = alphabet [ i ] + base36 <EOL> return base36 </s>
