##// END OF EJS Templates
More Python 3 compatibility fixes.
Thomas Kluyver -
Show More
@@ -23,7 +23,7 b' import textwrap'
23 23 from string import Formatter
24 24
25 25 from IPython.external.path import path
26
26 from IPython.utils import py3compat
27 27 from IPython.utils.io import nlprint
28 28 from IPython.utils.data import flatten
29 29
@@ -284,7 +284,7 b' def make_quoted_expr(s):'
284 284 tail = ''
285 285 tailpadding = ''
286 286 raw = ''
287 ucode = 'u'
287 ucode = '' if py3compat.PY3 else 'u'
288 288 if "\\" in s:
289 289 raw = 'r'
290 290 if s.endswith('\\'):
@@ -494,7 +494,7 b" def marquee(txt='',width=78,mark='*'):"
494 494 """
495 495 if not txt:
496 496 return (mark*width)[:width]
497 nmark = (width-len(txt)-2)/len(mark)/2
497 nmark = (width-len(txt)-2)//len(mark)//2
498 498 if nmark < 0: nmark =0
499 499 marks = mark*nmark
500 500 return '%s %s %s' % (marks,txt,marks)
@@ -52,15 +52,17 b' import inspect'
52 52 import re
53 53 import sys
54 54 import types
55 from types import (
56 InstanceType, ClassType, FunctionType,
57 ListType, TupleType
58 )
55 from types import FunctionType
56 try:
57 from types import ClassType, InstanceType
58 ClassTypes = (ClassType, type)
59 except:
60 ClassTypes = (type,)
61
59 62 from .importstring import import_item
63 from IPython.utils import py3compat
60 64
61 ClassTypes = (ClassType, type)
62
63 SequenceTypes = (ListType, TupleType, set, frozenset)
65 SequenceTypes = (list, tuple, set, frozenset)
64 66
65 67 #-----------------------------------------------------------------------------
66 68 # Basic classes
@@ -108,7 +110,7 b' def repr_type(obj):'
108 110 error messages.
109 111 """
110 112 the_type = type(obj)
111 if the_type is InstanceType:
113 if (not py3compat.PY3) and the_type is InstanceType:
112 114 # Old-style class.
113 115 the_type = obj.__class__
114 116 msg = '%r %r' % (obj, the_type)
@@ -616,7 +618,7 b' class ClassBasedTraitType(TraitType):'
616 618
617 619 def error(self, obj, value):
618 620 kind = type(value)
619 if kind is InstanceType:
621 if (not py3compat.PY3) and kind is InstanceType:
620 622 msg = 'class %s' % value.__class__.__name__
621 623 else:
622 624 msg = '%s (i.e. %s)' % ( str( kind )[1:-1], repr( value ) )
@@ -880,29 +882,29 b' class CInt(Int):'
880 882 except:
881 883 self.error(obj, value)
882 884
885 if not py3compat.PY3:
886 class Long(TraitType):
887 """A long integer trait."""
883 888
884 class Long(TraitType):
885 """A long integer trait."""
889 default_value = 0L
890 info_text = 'a long'
886 891
887 default_value = 0L
888 info_text = 'a long'
889
890 def validate(self, obj, value):
891 if isinstance(value, long):
892 return value
893 if isinstance(value, int):
894 return long(value)
895 self.error(obj, value)
892 def validate(self, obj, value):
893 if isinstance(value, long):
894 return value
895 if isinstance(value, int):
896 return long(value)
897 self.error(obj, value)
896 898
897 899
898 class CLong(Long):
899 """A casting version of the long integer trait."""
900 class CLong(Long):
901 """A casting version of the long integer trait."""
900 902
901 def validate(self, obj, value):
902 try:
903 return long(value)
904 except:
905 self.error(obj, value)
903 def validate(self, obj, value):
904 try:
905 return long(value)
906 except:
907 self.error(obj, value)
906 908
907 909
908 910 class Float(TraitType):
@@ -955,7 +957,7 b' class CComplex(Complex):'
955 957 # for Python 3 conversion and for reliable unicode behaviour on Python 2. So
956 958 # we don't have a Str type.
957 959 class Bytes(TraitType):
958 """A trait for strings."""
960 """A trait for byte strings."""
959 961
960 962 default_value = ''
961 963 info_text = 'a string'
@@ -967,7 +969,7 b' class Bytes(TraitType):'
967 969
968 970
969 971 class CBytes(Bytes):
970 """A casting version of the string trait."""
972 """A casting version of the byte string trait."""
971 973
972 974 def validate(self, obj, value):
973 975 try:
@@ -380,7 +380,7 b' class Session(Configurable):'
380 380 h = self.auth.copy()
381 381 for m in msg_list:
382 382 h.update(m)
383 return h.hexdigest()
383 return str_to_bytes(h.hexdigest())
384 384
385 385 def serialize(self, msg, ident=None):
386 386 """Serialize the message components to bytes.
General Comments 0
You need to be logged in to leave comments. Login now