Commits

Andy Hayden committed 9122f84

ENH add python 3 support

Comments (0)

Files changed (5)

-from rstr_base import Rstr
-from rstr_base import default_instance as _default_instance
+from rstr.rstr_base import Rstr
+from rstr.rstr_base import default_instance as _default_instance
 
 rstr = _default_instance.rstr
 xeger = _default_instance.xeger

rstr/rstr_base.py

 import itertools
 from copy import copy
 from functools import partial
-from xeger import Xeger
+from rstr.xeger import Xeger
+import sys
 
 
 ALPHABETS = {'printable': string.printable,
-              'letters': string.letters,
-              'uppercase': string.uppercase,
-              'lowercase': string.lowercase,
+              'letters': string.ascii_letters,
+              'uppercase': string.ascii_uppercase,
+              'lowercase': string.ascii_lowercase,
               'digits': string.digits,
               'punctuation': string.punctuation,
-              'nondigits': string.letters + string.punctuation,
+              'nondigits': string.ascii_letters + string.punctuation,
               'nonletters': string.digits + string.punctuation,
               'whitespace': string.whitespace,
               'nonwhitespace': string.printable.strip(),
-              'normal': string.letters + string.digits + ' ',
-              'word': string.letters + string.digits + '_',
-              'nonword': ''.join(set(string.printable).difference(string.letters +
+              'normal': string.ascii_letters + string.digits + ' ',
+              'word': string.ascii_letters + string.digits + '_',
+              'nonword': ''.join(set(string.printable).difference(string.ascii_letters +
                                                           string.digits + '_')),
-              'postalsafe': string.letters + string.digits + ' .-#/',
-              'urlsafe': string.letters + string.digits + '-._~',
-              'domainsafe': string.letters + string.digits + '-'
+              'postalsafe': string.ascii_letters + string.digits + ' .-#/',
+              'urlsafe': string.ascii_letters + string.digits + '-._~',
+              'domainsafe': string.ascii_letters + string.digits + '-'
             }
 
 

rstr/tests/__init__.py

 import unittest
-import test_rstr
-import test_xeger
-import test_package_level_access
+import rstr.tests.test_rstr
+import rstr.tests.test_xeger
+import rstr.tests.test_package_level_access
 
 def suite():
     loader = unittest.TestLoader()

rstr/tests/test_rstr.py

 import re
 import unittest
+import sys
 
 from rstr.rstr_base import Rstr
 
+if sys.version_info[0] >= 3:
+    unichr = chr
+    xrange = range
+
 class TestRstr(unittest.TestCase):
     def setUp(self):
         self.rs = Rstr()
 import string
 from random import choice, randint
 from itertools import chain
+import sys
+
+
+if sys.version_info[0] >= 3:
+    unichr = chr
+    xrange = range
 
 #The * and + characters in a regular expression
 # match up to any number of repeats in theory,