original_docstring: 
          Check network connection sending event when network is up or down
  
          It also monitor wifi network status (disconnected/connected/invalid password)
          
docstring: Check network connection sending event when network is up or down
  It also monitor wifi network status (disconnected/connected/invalid password)
docstring_tokens: Check network connection sending event when network is up or down It also monitor wifi network status ( disconnected / connected / invalid password )
code: def _check_network_connection(self):
          """
          Check network connection sending event when network is up or down
  
          It also monitor wifi network status (disconnected/connected/invalid password)
          """
          # Performance optimization: do not check network connection each seconds all the time.
          # To reduce scan frequency frontend enables active scan (each seconds) when user loads network
          # config page and this for a configured duration. After this time, scan duration is set to
          # its optimized value NETWORK_SCAN_DURATION
          if self.network_status and int(time.time()) % self.__network_scan_duration != 0:
              return
  
          # init
          wifi_interfaces = self.iwconfig.get_interfaces()
          connected = False
  
          # check interfaces
          for interface_name in netifaces.interfaces():
              # drop local interface
              if interface_name == 'lo':
                  continue
  
              # check if at least one interface is connected
              addresses = netifaces.ifaddresses(interface_name)
              if (netifaces.AF_INET in addresses
                      and len(addresses[netifaces.AF_INET]) == 1
                      and addresses[netifaces.AF_INET][0]['addr'].strip()):
                  connected = True
  
              # update interface status
              if interface_name in wifi_interfaces:
                  # wireless interface
                  self._check_wifi_interface_status(copy.copy(interface_name))
              else:
                  # ethernet interface
                  self._check_wired_interface_status(copy.copy(interface_name))
  
          # handle network connection status
          if connected and self.__network_is_down:
              self.__network_is_down = False
              self.network_up_event.send()
          elif not connected and not self.__network_is_down:
              self.__network_is_down = True
              self.network_down_event.send()
code_tokens: def _check_network_connection ( self ) : if self . network_status and int ( time . time ( ) ) % self . __network_scan_duration != 0 : return wifi_interfaces = self . iwconfig . get_interfaces ( ) connected = False for interface_name in netifaces . interfaces ( ) : if interface_name == 'lo' : continue addresses = netifaces . ifaddresses ( interface_name ) if ( netifaces . AF_INET in addresses and len ( addresses [ netifaces . AF_INET ] ) == 1 and addresses [ netifaces . AF_INET ] [ 0 ] [ 'addr' ] . strip ( ) ) : connected = True if interface_name in wifi_interfaces : self . _check_wifi_interface_status ( copy . copy ( interface_name ) ) else : self . _check_wired_interface_status ( copy . copy ( interface_name ) ) if connected and self . __network_is_down : self . __network_is_down = False self . network_up_event . send ( ) elif not connected and not self . __network_is_down : self . __network_is_down = True self . network_down_event . send ( )
short_docstring: Check network connection sending event when network is up or down
  It also monitor wifi network status (disconnected/connected/invalid password)
short_docstring_tokens: Check network connection sending event when network is up or down It also monitor wifi network status ( disconnected / connected / invalid password )
comment: """
          Check network connection sending event when network is up or down
  
          It also monitor wifi network status (disconnected/connected/invalid password)
          """$SEP$# Performance optimization: do not check network connection each seconds all the time.$SEP$# To reduce scan frequency frontend enables active scan (each seconds) when user loads network$SEP$# config page and this for a configured duration. After this time, scan duration is set to$SEP$# its optimized value NETWORK_SCAN_DURATION$SEP$# init$SEP$# check interfaces$SEP$# drop local interface$SEP$# check if at least one interface is connected$SEP$# update interface status$SEP$# wireless interface$SEP$# ethernet interface$SEP$# handle network connection status