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