31
31
import time
32
32
import warnings
33
33
import webbrowser
34
+ import urllib
34
35
35
36
from base64 import encodebytes
36
37
from jinja2 import Environment , FileSystemLoader
@@ -1357,31 +1358,53 @@ def init_webapp(self):
1357
1358
@property
1358
1359
def display_url (self ):
1359
1360
if self .custom_display_url :
1360
- url = self .custom_display_url
1361
- if not url . endswith ( '/' ):
1362
- url += '/'
1361
+ parts = urllib . parse . urlparse ( self .custom_display_url )
1362
+ path = parts . path
1363
+ ip = parts . hostname
1363
1364
else :
1365
+ path = None
1364
1366
if self .ip in ('' , '0.0.0.0' ):
1365
1367
ip = "%s" % socket .gethostname ()
1366
1368
else :
1367
1369
ip = self .ip
1368
- url = self ._url (ip )
1370
+
1371
+ token = None
1369
1372
if self .token :
1370
1373
# Don't log full token if it came from config
1371
1374
token = self .token if self ._token_generated else '...'
1372
- url = (url_concat (url , {'token' : token })
1373
- + '\n or '
1374
- + url_concat (self ._url ('127.0.0.1' ), {'token' : token }))
1375
+
1376
+ url = (
1377
+ self .get_url (ip = ip , path = path , token = token )
1378
+ + '\n or '
1379
+ + self .get_url (ip = '127.0.0.1' , path = path , token = token )
1380
+ )
1375
1381
return url
1376
1382
1377
1383
@property
1378
1384
def connection_url (self ):
1379
1385
ip = self .ip if self .ip else 'localhost'
1380
- return self ._url ( ip )
1386
+ return self .get_url ( ip = ip )
1381
1387
1382
- def _url (self , ip ):
1383
- proto = 'https' if self .certfile else 'http'
1384
- return "%s://%s:%i%s" % (proto , ip , self .port , self .base_url )
1388
+ def get_url (self , ip = None , path = None , token = None ):
1389
+ """Build a url for the application.
1390
+ """
1391
+ if not ip :
1392
+ ip = self .ip
1393
+ if not path :
1394
+ path = url_path_join (self .base_url , self .default_url )
1395
+ # Build query string.
1396
+ if self .token :
1397
+ token = urllib .parse .urlencode ({'token' : token })
1398
+ # Build the URL Parts to dump.
1399
+ urlparts = urllib .parse .ParseResult (
1400
+ scheme = 'https' if self .certfile else 'http' ,
1401
+ netloc = "{ip}:{port}" .format (ip = ip , port = self .port ),
1402
+ path = path ,
1403
+ params = None ,
1404
+ query = token ,
1405
+ fragment = None
1406
+ )
1407
+ return urlparts .geturl ()
1385
1408
1386
1409
def init_terminals (self ):
1387
1410
if not self .terminals_enabled :
@@ -1429,7 +1452,7 @@ def _confirm_exit(self):
1429
1452
"""
1430
1453
info = self .log .info
1431
1454
info (_ ('interrupted' ))
1432
- print (self .notebook_info ())
1455
+ print (self .running_server_info ())
1433
1456
yes = _ ('y' )
1434
1457
no = _ ('n' )
1435
1458
sys .stdout .write (_ ("Shutdown this Jupyter server (%s/[%s])? " ) % (yes , no ))
@@ -1457,7 +1480,7 @@ def _signal_stop(self, sig, frame):
1457
1480
self .io_loop .add_callback_from_signal (self .io_loop .stop )
1458
1481
1459
1482
def _signal_info (self , sig , frame ):
1460
- print (self .notebook_info ())
1483
+ print (self .running_server_info ())
1461
1484
1462
1485
def init_components (self ):
1463
1486
"""Check the components submodule, and warn if it's unclean"""
@@ -1586,7 +1609,7 @@ def cleanup_kernels(self):
1586
1609
self .log .info (kernel_msg % n_kernels )
1587
1610
self .kernel_manager .shutdown_all ()
1588
1611
1589
- def notebook_info (self , kernel_count = True ):
1612
+ def running_server_info (self , kernel_count = True ):
1590
1613
"Return the current working directory and the server url information"
1591
1614
info = self .contents_manager .info_string () + "\n "
1592
1615
if kernel_count :
@@ -1715,7 +1738,7 @@ def start(self):
1715
1738
self .exit (1 )
1716
1739
1717
1740
info = self .log .info
1718
- for line in self .notebook_info (kernel_count = False ).split ("\n " ):
1741
+ for line in self .running_server_info (kernel_count = False ).split ("\n " ):
1719
1742
info (line )
1720
1743
info (_ ("Use Control-C to stop this server and shut down all kernels (twice to skip confirmation)." ))
1721
1744
if 'dev' in jupyter_server .__version__ :
@@ -1735,7 +1758,7 @@ def start(self):
1735
1758
# with auth info.
1736
1759
self .log .critical ('\n ' .join ([
1737
1760
'\n ' ,
1738
- 'To access the notebook , open this file in a browser:' ,
1761
+ 'To access the server , open this file in a browser:' ,
1739
1762
' %s' % urljoin ('file:' , pathname2url (self .browser_open_file )),
1740
1763
'Or copy and paste one of these URLs:' ,
1741
1764
' %s' % self .display_url ,
0 commit comments