2626)
2727USE_CACHE = int (os .environ .get ('TLDR_CACHE_ENABLED' , '1' )) > 0
2828MAX_CACHE_AGE = int (os .environ .get ('TLDR_CACHE_MAX_AGE' , 24 ))
29- IGNORE_SSL = int (os .environ .get ('TLDR_IGNORE_SSL' ,'0' ))
30-
31- ignore_ctx = ssl .create_default_context ()
32- ignore_ctx .check_hostname = False
33- ignore_ctx .verify_mode = ssl .CERT_NONE
34-
35-
36-
29+ URLOPEN_CONTEXT = None
30+ if int (os .environ .get ('TLDR_ALLOW_INSECURE' , '0' )) == 1 :
31+ URLOPEN_CONTEXT = ssl .create_default_context ()
32+ URLOPEN_CONTEXT .check_hostname = False
33+ URLOPEN_CONTEXT .verify_mode = ssl .CERT_NONE
3734
3835OS_DIRECTORIES = {
3936 "linux" : "linux" ,
@@ -97,7 +94,7 @@ def get_page_for_platform(command, platform, remote=None):
9794 else :
9895 page_url = get_page_url (platform , command , remote )
9996 try :
100- data = urlopen (Request (page_url , headers = REQUEST_HEADERS ), context = ignore_ctx ).read ()
97+ data = urlopen (Request (page_url , headers = REQUEST_HEADERS ), context = URLOPEN_CONTEXT ).read ()
10198 data_downloaded = True
10299 except Exception :
103100 data = load_page_from_cache (command , platform )
@@ -110,7 +107,7 @@ def get_page_for_platform(command, platform, remote=None):
110107
111108def update_page_for_platform (command , platform , remote = None ):
112109 page_url = get_page_url (platform , command , remote )
113- data = urlopen (Request (page_url , headers = REQUEST_HEADERS ), context = ignore_ctx ).read ()
110+ data = urlopen (Request (page_url , headers = REQUEST_HEADERS ), context = URLOPEN_CONTEXT ).read ()
114111 store_page_to_cache (data , command , platform )
115112
116113
@@ -231,7 +228,7 @@ def update_cache():
231228 req = urlopen (Request (
232229 DOWNLOAD_CACHE_LOCATION ,
233230 headers = REQUEST_HEADERS
234- ))
231+ ), context = URLOPEN_CONTEXT )
235232 zipfile = ZipFile (BytesIO (req .read ()))
236233 pattern = re .compile (r'pages/(.+)/(.+)\.md' )
237234 cached = 0
@@ -281,8 +278,6 @@ def main():
281278
282279 colorama .init (strip = options .color )
283280
284- other_options = [str ('-' .join (other_options ))]
285-
286281 if options .update_cache :
287282 update_cache ()
288283 return
0 commit comments