@@ -114,7 +114,7 @@ def force_clear_cookie(self, name, path="/", domain=None):
114
114
name = escape .native_str (name )
115
115
expires = datetime .datetime .utcnow () - datetime .timedelta (days = 365 )
116
116
117
- morsel = Morsel ()
117
+ morsel : Morsel = Morsel ()
118
118
morsel .set (name , "" , '""' )
119
119
morsel ["expires" ] = httputil .format_timestamp (expires )
120
120
morsel ["path" ] = path
@@ -257,7 +257,7 @@ def mathjax_config(self):
257
257
return self .settings .get ("mathjax_config" , "TeX-AMS-MML_HTMLorMML-full,Safe" )
258
258
259
259
@property
260
- def base_url (self ):
260
+ def base_url (self ) -> str :
261
261
return self .settings .get ("base_url" , "/" )
262
262
263
263
@property
@@ -492,7 +492,9 @@ def check_host(self):
492
492
return True
493
493
494
494
# Remove port (e.g. ':8888') from host
495
- host = re .match (r"^(.*?)(:\d+)?$" , self .request .host ).group (1 )
495
+ match = re .match (r"^(.*?)(:\d+)?$" , self .request .host )
496
+ assert match is not None
497
+ host = match .group (1 )
496
498
497
499
# Browsers format IPv6 addresses like [::1]; we need to remove the []
498
500
if host .startswith ("[" ) and host .endswith ("]" ):
@@ -583,7 +585,7 @@ def write_error(self, status_code, **kwargs):
583
585
exc_info = kwargs .get ("exc_info" )
584
586
message = ""
585
587
status_message = responses .get (status_code , "Unknown HTTP Error" )
586
- exception = "(unknown)"
588
+
587
589
if exc_info :
588
590
exception = exc_info [1 ]
589
591
# get the custom message, if defined
@@ -596,6 +598,8 @@ def write_error(self, status_code, **kwargs):
596
598
reason = getattr (exception , "reason" , "" )
597
599
if reason :
598
600
status_message = reason
601
+ else :
602
+ exception = "(unknown)"
599
603
600
604
# build template namespace
601
605
ns = dict (
@@ -618,6 +622,8 @@ def write_error(self, status_code, **kwargs):
618
622
class APIHandler (JupyterHandler ):
619
623
"""Base class for API handlers"""
620
624
625
+ _user_cache : dict
626
+
621
627
def prepare (self ):
622
628
if not self .check_origin ():
623
629
raise web .HTTPError (404 )
@@ -627,7 +633,7 @@ def write_error(self, status_code, **kwargs):
627
633
"""APIHandler errors are JSON, not human pages"""
628
634
self .set_header ("Content-Type" , "application/json" )
629
635
message = responses .get (status_code , "Unknown HTTP Error" )
630
- reply = {
636
+ reply : dict = {
631
637
"message" : message ,
632
638
}
633
639
exc_info = kwargs .get ("exc_info" )
@@ -749,13 +755,14 @@ def head(self, path):
749
755
750
756
@web .authenticated
751
757
def get (self , path ):
752
- if os .path .splitext (path )[1 ] == ".ipynb" or self .get_argument ("download" , False ):
758
+ if os .path .splitext (path )[1 ] == ".ipynb" or self .get_argument ("download" , None ):
753
759
name = path .rsplit ("/" , 1 )[- 1 ]
754
760
self .set_attachment_header (name )
755
761
756
762
return web .StaticFileHandler .get (self , path )
757
763
758
764
def get_content_type (self ):
765
+ assert self .absolute_path is not None
759
766
path = self .absolute_path .strip ("/" )
760
767
if "/" in path :
761
768
_ , name = path .rsplit ("/" , 1 )
@@ -834,7 +841,8 @@ class FileFindHandler(JupyterHandler, web.StaticFileHandler):
834
841
"""subclass of StaticFileHandler for serving files from a search path"""
835
842
836
843
# cache search results, don't search for files more than once
837
- _static_paths = {}
844
+ _static_paths : dict = {}
845
+ root : tuple
838
846
839
847
def set_headers (self ):
840
848
super ().set_headers ()
@@ -898,6 +906,7 @@ class TrailingSlashHandler(web.RequestHandler):
898
906
"""
899
907
900
908
def get (self ):
909
+ assert self .request .uri is not None
901
910
path , * rest = self .request .uri .partition ("?" )
902
911
# trim trailing *and* leading /
903
912
# to avoid misinterpreting repeated '//'
0 commit comments