@@ -61,9 +61,9 @@ def compare_digest(a,b): return a == b
61
61
from jupyter_client .jsonutil import extract_dates , squash_dates , date_default
62
62
from ipython_genutils .py3compat import (str_to_bytes , str_to_unicode , unicode_type ,
63
63
iteritems )
64
- from traitlets import (CBytes , Unicode , Bool , Any , Instance , Set ,
65
- DottedObjectName , CUnicode , Dict , Integer ,
66
- TraitError ,
64
+ from traitlets import (
65
+ CBytes , Unicode , Bool , Any , Instance , Set , DottedObjectName , CUnicode ,
66
+ Dict , Integer , TraitError , observe
67
67
)
68
68
from jupyter_client import protocol_version
69
69
from jupyter_client .adapter import adapt
@@ -180,8 +180,10 @@ class SessionFactory(LoggingConfigurable):
180
180
"""
181
181
182
182
logname = Unicode ('' )
183
- def _logname_changed (self , name , old , new ):
184
- self .log = logging .getLogger (new )
183
+
184
+ @observe ('logname' )
185
+ def _logname_changed (self , change ):
186
+ self .log = logging .getLogger (change ['new' ])
185
187
186
188
# not configurable:
187
189
context = Instance ('zmq.Context' )
@@ -311,7 +313,10 @@ class Session(Configurable):
311
313
help = """The name of the packer for serializing messages.
312
314
Should be one of 'json', 'pickle', or an import name
313
315
for a custom callable serializer.""" )
314
- def _packer_changed (self , name , old , new ):
316
+
317
+ @observe ('packer' )
318
+ def _packer_changed (self , change ):
319
+ new = change ['new' ]
315
320
if new .lower () == 'json' :
316
321
self .pack = json_packer
317
322
self .unpack = json_unpacker
@@ -326,7 +331,10 @@ def _packer_changed(self, name, old, new):
326
331
unpacker = DottedObjectName ('json' , config = True ,
327
332
help = """The name of the unpacker for unserializing messages.
328
333
Only used with custom functions for `packer`.""" )
329
- def _unpacker_changed (self , name , old , new ):
334
+
335
+ @observe ('unpacker' )
336
+ def _unpacker_changed (self , change ):
337
+ new = change ['new' ]
330
338
if new .lower () == 'json' :
331
339
self .pack = json_packer
332
340
self .unpack = json_unpacker
@@ -345,7 +353,8 @@ def _session_default(self):
345
353
self .bsession = u .encode ('ascii' )
346
354
return u
347
355
348
- def _session_changed (self , name , old , new ):
356
+ @observe ('session' )
357
+ def _session_changed (self , change ):
349
358
self .bsession = self .session .encode ('ascii' )
350
359
351
360
# bsession is the session as bytes
@@ -368,13 +377,17 @@ def _session_changed(self, name, old, new):
368
377
def _key_default (self ):
369
378
return new_id_bytes ()
370
379
371
- def _key_changed (self ):
380
+ @observe ('key' )
381
+ def _key_changed (self , change ):
372
382
self ._new_auth ()
373
383
374
384
signature_scheme = Unicode ('hmac-sha256' , config = True ,
375
385
help = """The digest scheme used to construct the message signatures.
376
386
Must have the form 'hmac-HASH'.""" )
377
- def _signature_scheme_changed (self , name , old , new ):
387
+
388
+ @observe ('signature_scheme' )
389
+ def _signature_scheme_changed (self , change ):
390
+ new = change ['new' ]
378
391
if not new .startswith ('hmac-' ):
379
392
raise TraitError ("signature_scheme must start with 'hmac-', got %r" % new )
380
393
hash_name = new .split ('-' , 1 )[1 ]
@@ -406,8 +419,10 @@ def _new_auth(self):
406
419
407
420
keyfile = Unicode ('' , config = True ,
408
421
help = """path to file containing execution key.""" )
409
- def _keyfile_changed (self , name , old , new ):
410
- with open (new , 'rb' ) as f :
422
+
423
+ @observe ('keyfile' )
424
+ def _keyfile_changed (self , change ):
425
+ with open (change ['new' ], 'rb' ) as f :
411
426
self .key = f .read ().strip ()
412
427
413
428
# for protecting against sends from forks
@@ -416,13 +431,19 @@ def _keyfile_changed(self, name, old, new):
416
431
# serialization traits:
417
432
418
433
pack = Any (default_packer ) # the actual packer function
419
- def _pack_changed (self , name , old , new ):
434
+
435
+ @observe ('pack' )
436
+ def _pack_changed (self , change ):
437
+ new = change ['new' ]
420
438
if not callable (new ):
421
439
raise TypeError ("packer must be callable, not %s" % type (new ))
422
440
423
441
unpack = Any (default_unpacker ) # the actual packer function
424
- def _unpack_changed (self , name , old , new ):
442
+
443
+ @observe ('unpack' )
444
+ def _unpack_changed (self , change ):
425
445
# unpacker is not checked - it is assumed to be
446
+ new = change ['new' ]
426
447
if not callable (new ):
427
448
raise TypeError ("unpacker must be callable, not %s" % type (new ))
428
449
0 commit comments