##// END OF EJS Templates
Minor work on kernelmanager....
Brian Granger -
Show More
@@ -27,7 +27,7 b' from unittest import TestCase'
27 27 from IPython.utils.traitlets import (
28 28 HasTraits, MetaHasTraits, TraitType, Any,
29 29 Int, Long, Float, Complex, Str, Unicode, TraitError,
30 Undefined, Type, This, Instance
30 Undefined, Type, This, Instance, TCPAddress
31 31 )
32 32
33 33
@@ -684,3 +684,16 b' class TestUnicode(TraitTestBase):'
684 684 '-10.1', '', u'', 'string', u'string', ]
685 685 _bad_values = [10, -10, 10L, -10L, 10.1, -10.1, 1j,
686 686 [10], ['ten'], [u'ten'], {'ten': 10},(10,), None]
687
688
689 class TCPAddressTrait(HasTraits):
690
691 value = TCPAddress()
692
693 class TestTCPAddress(TraitTestBase):
694
695 obj = TCPAddressTrait()
696
697 _default_value = ('127.0.0.1',0)
698 _good_values = [('localhost',0),('192.168.0.1',1000),('www.google.com',80)]
699 _bad_values = [(0,0),('localhost',10.0),('localhost',-1)]
@@ -230,8 +230,7 b' class TraitType(object):'
230 230
231 231 def get_default_value(self):
232 232 """Create a new instance of the default value."""
233 dv = self.default_value
234 return dv
233 return self.default_value
235 234
236 235 def instance_init(self, obj):
237 236 """This is called by :meth:`HasTraits.__new__` to finish init'ing.
@@ -798,7 +797,6 b' class Any(TraitType):'
798 797 class Int(TraitType):
799 798 """A integer trait."""
800 799
801 evaluate = int
802 800 default_value = 0
803 801 info_text = 'an integer'
804 802
@@ -820,7 +818,6 b' class CInt(Int):'
820 818 class Long(TraitType):
821 819 """A long integer trait."""
822 820
823 evaluate = long
824 821 default_value = 0L
825 822 info_text = 'a long'
826 823
@@ -845,7 +842,6 b' class CLong(Long):'
845 842 class Float(TraitType):
846 843 """A float trait."""
847 844
848 evaluate = float
849 845 default_value = 0.0
850 846 info_text = 'a float'
851 847
@@ -869,7 +865,6 b' class CFloat(Float):'
869 865 class Complex(TraitType):
870 866 """A trait for complex numbers."""
871 867
872 evaluate = complex
873 868 default_value = 0.0 + 0.0j
874 869 info_text = 'a complex number'
875 870
@@ -894,7 +889,6 b' class CComplex(Complex):'
894 889 class Str(TraitType):
895 890 """A trait for strings."""
896 891
897 evaluate = lambda x: x
898 892 default_value = ''
899 893 info_text = 'a string'
900 894
@@ -920,7 +914,6 b' class CStr(Str):'
920 914 class Unicode(TraitType):
921 915 """A trait for unicode strings."""
922 916
923 evaluate = unicode
924 917 default_value = u''
925 918 info_text = 'a unicode string'
926 919
@@ -944,7 +937,7 b' class CUnicode(Unicode):'
944 937
945 938 class Bool(TraitType):
946 939 """A boolean (True, False) trait."""
947 evaluate = bool
940
948 941 default_value = False
949 942 info_text = 'a boolean'
950 943
@@ -1023,3 +1016,23 b' class List(Instance):'
1023 1016
1024 1017 super(List,self).__init__(klass=list, args=args,
1025 1018 allow_none=allow_none, **metadata)
1019
1020
1021 class TCPAddress(TraitType):
1022 """A trait for an (ip, port) tuple.
1023
1024 This allows for both IPv4 IP addresses as well as hostnames.
1025 """
1026
1027 default_value = ('127.0.0.1', 0)
1028 info_text = 'an (ip, port) tuple'
1029
1030 def validate(self, obj, value):
1031 if isinstance(value, tuple):
1032 if len(value) == 2:
1033 if isinstance(value[0], basestring) and isinstance(value[1], int):
1034 port = value[1]
1035 if port >= 0 and port <= 65535:
1036 return value
1037 self.error(obj, value)
1038
@@ -1,4 +1,4 b''
1 """Classes to manage the interaction with a running kernel.
1 """Base classes to manage the interaction with a running kernel.
2 2
3 3 Todo
4 4 ====
@@ -29,7 +29,7 b' from zmq import POLLIN, POLLOUT, POLLERR'
29 29 from zmq.eventloop import ioloop
30 30
31 31 # Local imports.
32 from IPython.utils.traitlets import HasTraits, Any, Instance, Type
32 from IPython.utils.traitlets import HasTraits, Any, Instance, Type, TCPAddress
33 33 from kernel import launch_kernel
34 34 from session import Session
35 35
@@ -61,9 +61,9 b' class ZmqSocketChannel(Thread):'
61 61
62 62 Parameters
63 63 ----------
64 context : zmq.Context
64 context : :class:`zmq.Context`
65 65 The ZMQ context to use.
66 session : session.Session
66 session : :class:`session.Session`
67 67 The session to use.
68 68 address : tuple
69 69 Standard (ip, port) tuple that the kernel is listening on.
@@ -289,6 +289,10 b' class SubSocketChannel(ZmqSocketChannel):'
289 289 def flush(self, timeout=1.0):
290 290 """Immediately processes all pending messages on the SUB channel.
291 291
292 Callers should use this method to ensure that :method:`call_handlers`
293 has been called for all messages that have been received on the
294 0MQ SUB socket of this channel.
295
292 296 This method is thread safe.
293 297
294 298 Parameters
@@ -324,7 +328,7 b' class SubSocketChannel(ZmqSocketChannel):'
324 328 msg = self.socket.recv_json(zmq.NOBLOCK)
325 329 except zmq.ZMQError:
326 330 # Check the errno?
327 # Will this tigger POLLERR?
331 # Will this trigger POLLERR?
328 332 break
329 333 else:
330 334 self.call_handlers(msg)
@@ -435,9 +439,9 b' class KernelManager(HasTraits):'
435 439 rep_channel_class = Type(RepSocketChannel)
436 440
437 441 # Protected traits.
438 _xreq_address = Any
439 _sub_address = Any
440 _rep_address = Any
442 _xreq_address = TCPAddress
443 _sub_address = TCPAddress
444 _rep_address = TCPAddress
441 445 _xreq_channel = Any
442 446 _sub_channel = Any
443 447 _rep_channel = Any
@@ -585,4 +589,3 b' class KernelManager(HasTraits):'
585 589 def rep_address(self):
586 590 return self._rep_address
587 591
588
1 NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now