Created
July 24, 2012 22:09
-
-
Save mattcarp/3173004 to your computer and use it in GitHub Desktop.
Generates a random length string of non-control Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import random | |
import unicodedata | |
def unicode_fuzz(lower_limit=0, upper_limit=60): | |
unicode_glyphs = ''.join( | |
unichr(char) | |
for char in xrange(65533) | |
# use the unicode categories that don't include control codes | |
if unicodedata.category(unichr(char))[0] in ('LMNPSZ') | |
) | |
rand_length = random.randint(lower_limit, upper_limit) | |
# generate it | |
utf_string = ''.join([random.choice(unicode_glyphs).encode('utf-8') | |
for i in xrange(rand_length)]) | |
return utf_string | |
# call it with some upper and lower string lengths, or use the defaults | |
# print unicode_fuzz(0, 250) |
This doesn't work! I tried fixing it but it didn't output anything. Here is my fixed version:
from random import randint, choice
from unicodedata import category
import pyparsing
from cffi.backend_ctypes import xrange
def gen_unicode(lower_limit, upper_limit):
unicode_glyphs = ''.join(
pyparsing.unichr(char) for char in xrange(65533) if category(pyparsing.unichr(char))[0] in 'LMNPSZ')
rand_length = randint(lower_limit, upper_limit)
utf_string = ''.join([choice(unicode_glyphs).encode('utf-8') for _ in xrange(rand_length)])
return utf_string
print(gen_unicode(0, 30))
This doesn't work! I tried fixing it but it didn't output anything. Here is my fixed version:
from random import randint, choice from unicodedata import category import pyparsing from cffi.backend_ctypes import xrange def gen_unicode(lower_limit, upper_limit): unicode_glyphs = ''.join( pyparsing.unichr(char) for char in xrange(65533) if category(pyparsing.unichr(char))[0] in 'LMNPSZ') rand_length = randint(lower_limit, upper_limit) utf_string = ''.join([choice(unicode_glyphs).encode('utf-8') for _ in xrange(rand_length)]) return utf_string print(gen_unicode(0, 30))
Error: TypeError: sequence item 0: expected str instance, bytes found
Congratulations, guys. I don't even remember that I wrote it. Welcome to
orphaned code.
Hope you are well.
…On Thu, Apr 7, 2022 at 11:05 PM VB PROGER ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
This doesn't work! I tried fixing it but it didn't output anything. Here
is my fixed version:
from random import randint, choicefrom unicodedata import category
import pyparsingfrom cffi.backend_ctypes import xrange
def gen_unicode(lower_limit, upper_limit):
unicode_glyphs = ''.join(
pyparsing.unichr(char) for char in xrange(65533) if category(pyparsing.unichr(char))[0] in 'LMNPSZ')
rand_length = randint(lower_limit, upper_limit)
utf_string = ''.join([choice(unicode_glyphs).encode('utf-8') for _ in xrange(rand_length)])
return utf_string
print(gen_unicode(0, 30))
Error: TypeError: sequence item 0: expected str instance, bytes found
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/3173004#gistcomment-4125292>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAF27B2Y7PEJLIKRR5QJEMDVD5EXBANCNFSM43D4PRGQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
what is
xrange
?