#NEWLINE# def generate_token( length = 30 , chars = UNICODE_ASCII_CHARACTER_SET ) : #NEWLINE# #INDENT# 'Generates a non-guessable OAuth token\n\n    OAuth (1 and 2) does not specify the format of tokens except that they\n    should be strings of random characters. Tokens should not be guessable\n    and entropy when generating the random characters is important. Which is\n    why SystemRandom is used instead of the default random.choice method.\n    ' #NEWLINE# rand = random . SystemRandom ( ) #NEWLINE# return '' . join ( ( rand . choice ( chars ) for x in range ( length ) ) )