code: def _generate_random_string(self, container, length=20):
          
          while True:
              s = ''.join([random.SystemRandom().choice(string.digits + string.ascii_letters)
                           for n in range(length)])
              if (s not in container):
                  break
          return s
docs: Generate a random cookie or token string not in container.
  
          The cookie or token should be secure in the sense that it should not
          be likely to be able guess a value. Because it is not derived from
          anything else, there is no vulnerability of the token from computation,
          or possible leakage of information from the token.