@@ -386,6 +386,21 @@ def resource_name(resource_path):
386386 return ''
387387
388388
389+ def check_network_connection ():
390+ """
391+ Returns True if an HTTP connection to the live internet is possible.
392+ """
393+ http_connection = httplib .HTTPConnection ('dejacode.org' , timeout = 10 )
394+ try :
395+ http_connection .connect ()
396+ except socket .error :
397+ return False
398+ else :
399+ return True
400+
401+ has_network_connectivity = check_network_connection ()
402+
403+
389404class AboutFile (object ):
390405 """
391406 Represent an ABOUT file and functions to parse and validate a file.
@@ -778,27 +793,13 @@ def check_url(self, url, network_check=False):
778793 return False
779794
780795 if network_check :
781- # FIXME: we should only check network connection ONCE per run
782- # and cache the results, not do this here
783- if self .check_network_connection ():
796+ if has_network_connectivity :
784797 # FIXME: HEAD request DO NOT WORK for ftp://
785798 return self .check_url_reachable (netloc , path )
786799 else :
787800 print ('No network connection detected.' )
788801 return url_has_valid_format
789802
790- @staticmethod
791- def check_network_connection ():
792- """
793- Returns True if an HTTP connection to the live internet is possible.
794- """
795- try :
796- http_connection = httplib .HTTPConnection ('dejacode.org' )
797- http_connection .connect ()
798- return True
799- except socket .error :
800- return False
801-
802803 @staticmethod
803804 def check_url_reachable (host , path ):
804805 # FIXME: we are only checking netloc and path ... NOT the whole url
0 commit comments