Esempio n. 1
0
 def test_with_urandom(self, urandom, randrange):
     urandom.return_value = b'\x62' * 8
     randrange.return_value = ord('a')
     actual = utils.get_random_string()
     expected = '62' * 8  # hex for ord('b')
     self.assertIsInstance(actual, six.text_type)
     self.assertEqual(expected, actual)
Esempio n. 2
0
 def test_no_urandom(self, urandom, randrange):
     urandom.side_effect = Exception('cannot use this')
     randrange.return_value = ord('a')
     actual = utils.get_random_string()
     expected = '61' * 8  # hex for ord('a')
     self.assertIsInstance(actual, six.text_type)
     self.assertEqual(expected, actual)
Esempio n. 3
0
def _pick_note_file_name(notesdir, slug):
    "Pick a unique name in notesdir."
    for i in range(50):
        newid = utils.get_random_string()
        notefilename = os.path.join(notesdir, "%s-%s.yaml" % (slug, newid))
        if not os.path.exists(notefilename):
            return notefilename
    else:
        raise ValueError("Unable to generate unique random filename " "in %s after 50 tries" % notesdir)
Esempio n. 4
0
def _pick_note_file_name(notesdir, slug):
    "Pick a unique name in notesdir."
    for i in range(50):
        newid = utils.get_random_string()
        notefilename = os.path.join(notesdir, '%s-%s.yaml' % (slug, newid))
        if not os.path.exists(notefilename):
            return notefilename
    else:
        raise ValueError(
            'Unable to generate unique random filename '
            'in %s after 50 tries' % notesdir, )