Jason R. Coombs avatar Jason R. Coombs committed 0beb46b

modes tests now run under Python 3

Comments (0)

Files changed (3)

irc/_py2_compat.py

 import sys
 import operator
 
-__all__ = ['str', 'basestring', 'socketserver', 'method_name']
+__all__ = ['str', 'basestring', 'chr', 'socketserver', 'method_name']
 
 py3 = sys.version_info >= (3,0)
 
-try:
+if py3:
+	str = basestring = str
+	chr = chr
+else:
 	basestring = str
 	str = unicode
-except NameError:
-	str = basestring = str
+	chr = unichr
 
 try:
 	import socketserver
 from __future__ import unicode_literals
 
 from . import strings
+from . import _py2_compat
 
 # from jaraco.util.dictlib
 class KeyTransformingDict(dict):
     """
     @staticmethod
     def key_transform(key):
-        if isinstance(key, basestring):
+        if isinstance(key, _py2_compat.basestring):
             key = strings.IRCFoldedCase(key)
         return key
 
     This function never throws an error:
     >>> import random
+    >>> from . import _py2_compat
     >>> def random_text(min_len = 3, max_len = 80):
     ...     len = random.randint(min_len, max_len)
-    ...     chars_to_choose = [unichr(x) for x in range(0,1024)]
+    ...     chars_to_choose = [_py2_compat.chr(x) for x in range(0,1024)]
     ...     chars = (random.choice(chars_to_choose) for x in range(len))
     ...     return u''.join(chars)
     >>> def random_texts(min_len = 3, max_len = 80):
     ...         yield random_text(min_len, max_len)
     >>> import itertools
     >>> texts = itertools.islice(random_texts(), 1000)
-    >>> set(type(_parse_modes(text)) for text in texts)
-    set([<type 'list'>])
+    >>> set(type(_parse_modes(text)) for text in texts) == set([list])
+    True
     """
 
     # mode_string must be non-empty and begin with a sign
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.