<NME> wifi.py
<BEF> from pyobjus import autoclass
from pyobjus.dylib_manager import load_framework, INCLUDE

from plyer.facades import Wifi

load_framework(INCLUDE.Foundation)
load_framework(INCLUDE.CoreWLAN)

CWInterface = autoclass('CWInterface')
CWNetwork = autoclass('CWNetwork')
CWWiFiClient = autoclass('CWWiFiClient')
NSArray = autoclass('NSArray')
NSDictionary = autoclass('NSDictionary')
NSString = autoclass('NSString')


class OSXWifi(Wifi):
    names = {}

    def _is_enabled(self):
        '''
        Returns `True` if the Wifi is enabled else  returns `False`.
        '''
        return CWWiFiClient.sharedWiFiClient().interface().powerOn()

    def _get_network_info(self, name):
        '''
        Returns all the network information.
        '''

        accessNetworkType = self.names[name].accessNetworkType
        aggregateRSSI = self.names[name].aggregateRSSI
        beaconInterval = self.names[name].beaconInterval
        bssid = self.names[name].bssid.UTF8String()
        countryCode = self.names[name].countryCode
        hasInternet = self.names[name].hasInternet
        hasInterworkingIE = self.names[name].hasInterworkingIE
        hessid = self.names[name].hessid
        ibss = self.names[name].ibss
        isAdditionalStepRequiredForAccess = \
            self.names[name].isAdditionalStepRequiredForAccess
        isCarPlayNetwork = self.names[name].isCarPlayNetwork
        isEmergencyServicesReachable = \
            self.names[name].isEmergencyServicesReachable
        isPasspoint = self.names[name].isPasspoint
        isPersonalHotspot = self.names[name].isPersonalHotspot
        isUnauthenticatedEmergencyServiceAccessible = \
            self.names[name].isUnauthenticatedEmergencyServiceAccessible
        noiseMeasurement = self.names[name].noiseMeasurement
        physicalLayerMode = self.names[name].physicalLayerMode
        rssiValue = self.names[name].rssiValue
        securityType = self.names[name].securityType
        ssid = self.names[name].ssid.UTF8String()
        supportsEasyConnect = self.names[name].supportsEasyConnect
        supportsWPS = self.names[name].supportsWPS
        venueGroup = self.names[name].venueGroup
        venueType = self.names[name].venueType

        return {'accessNetworkType': accessNetworkType,
                'aggregateRSSI': aggregateRSSI,
                'beaconInterval': beaconInterval,
                'bssid': bssid,
                'countryCode': countryCode,
                'hasInternet': hasInternet,
                'hasInterworkingIE': hasInterworkingIE,
                'hessid': hessid,
                'ibss': ibss,
                'isAdditionalStepRequiredForAccess':
                isAdditionalStepRequiredForAccess,
                'isCarPlayNetwork': isCarPlayNetwork,
                'isEmergencyServicesReachable': isEmergencyServicesReachable,
                'isPasspoint': isPasspoint,
                'isPersonalHotspot': isPersonalHotspot,
                'isUnauthenticatedEmergencyServiceAccessible':
                isUnauthenticatedEmergencyServiceAccessible,
                'noiseMeasurement': noiseMeasurement,
                'physicalLayerMode': physicalLayerMode,
                'rssiValue': rssiValue,
                'securityType': securityType,
                'ssid': ssid,
                'supportsEasyConnect': supportsEasyConnect,
                'supportsWPS': supportsWPS,
                'venueGroup': venueGroup,
                'venueType': venueType}

    def _start_scanning(self):
        '''
        Starts scanning for available Wi-Fi networks.
        '''
        if self._is_enabled():
            self.names = {}
            c = CWInterface.interface()
            scan = c.scanForNetworksWithName_error_(None, None)
            cnt = scan.allObjects().count()
            for i in range(cnt):
            cnt = scan.allObjects().count()
            for i in range(cnt):
                self.names[
                    scan.allObjects().objectAtIndex_(i).ssid.UTF8String()] \
                           = scan.allObjects().objectAtIndex_(i)
        else:
            raise Exception("Wifi not enabled.")

        Returns the name of available networks.
        '''
        return self.names.keys()

    def _connect(self, network, parameters):
        '''
        Expects 2 parameters:
            - name/ssid of the network.
            - password: dict type
        '''
        password = parameters['password']
        network_object = self.names[network]
        CWInterface.interface().associateToNetwork_password_error_(
            network_object,
            password,
            None)
        return

    def _disconnect(self):
        '''
        Disconnect from network.
        '''
        CWInterface.interface().disassociate()
        return

    def _disable(self):
        '''
        Wifi interface power state is set to "OFF".
        '''

        interface = CWWiFiClient.sharedWiFiClient().interface()
        interface.setPower_error_(False, None)

    def _enable(self):
        '''
        Wifi interface power state is set to "ON".
        '''

        interface = CWWiFiClient.sharedWiFiClient().interface()
        interface.setPower_error_(True, None)


def instance():
    return OSXWifi()

<MSG> Fix pep8 in Mac+iOS

<DFF> @@ -96,8 +96,8 @@ class OSXWifi(Wifi):
             cnt = scan.allObjects().count()
             for i in range(cnt):
                 self.names[
-                    scan.allObjects().objectAtIndex_(i).ssid.UTF8String()] \
-                           = scan.allObjects().objectAtIndex_(i)
+                    scan.allObjects().objectAtIndex_(i).ssid.UTF8String()
+                ] = scan.allObjects().objectAtIndex_(i)
         else:
             raise Exception("Wifi not enabled.")
 

{'commit': 'diff --git a/plyer/platforms/ios/email.py b/plyer/platforms/ios/email.py\nindex 7e55e4e..c6f99e0 100644\n--- a/plyer/platforms/ios/email.py\n+++ b/plyer/platforms/ios/email.py\n@@ -24,11 +24,11 @@ class iOSXEmail(Email):\n         if recipient:\n             uri += str(recipient)\n         if subject:\n-            uri += "?" if not "?" in uri else "&"\n+            uri += "?" if "?" not in uri else "&"\n             uri += "subject="\n             uri += quote(str(subject))\n         if text:\n-            uri += "?" if not "?" in uri else "&"\n+            uri += "?" if "?" not in uri else "&"\n             uri += "body="\n             uri += quote(str(text))\n \ndiff --git a/plyer/platforms/ios/tts.py b/plyer/platforms/ios/tts.py\nindex a711483..2427a53 100644\n--- a/plyer/platforms/ios/tts.py\n+++ b/plyer/platforms/ios/tts.py\n@@ -16,7 +16,9 @@ class iOSTextToSpeech(TTS):\n         self.voice = None\n \n     def _set_locale(self, locale="en-US"):\n-        self.voice = AVSpeechSynthesisVoice.voiceWithLanguage_(objc_str(locale))\n+        self.voice = AVSpeechSynthesisVoice.voiceWithLanguage_(\n+            objc_str(locale)\n+        )\n \n     def _speak(self, **kwargs):\n         message = kwargs.get(\'message\')\ndiff --git a/plyer/platforms/macosx/battery.py b/plyer/platforms/macosx/battery.py\nindex fe1c525..4534dfa 100644\n--- a/plyer/platforms/macosx/battery.py\n+++ b/plyer/platforms/macosx/battery.py\n@@ -12,8 +12,10 @@ class OSXBattery(Battery):\n \n         status = {"isCharging": None, "percentage": None}\n \n-        ioreg_process = Popen(["ioreg", "-rc", "AppleSmartBattery"],\n-                stdout=PIPE)\n+        ioreg_process = Popen(\n+            ["ioreg", "-rc", "AppleSmartBattery"],\n+            stdout=PIPE\n+        )\n         output = ioreg_process.communicate()[0]\n \n         environ[\'LANG\'] = old_lang\ndiff --git a/plyer/platforms/macosx/email.py b/plyer/platforms/macosx/email.py\nindex 8e29fa9..e2b7826 100644\n--- a/plyer/platforms/macosx/email.py\n+++ b/plyer/platforms/macosx/email.py\n@@ -19,11 +19,11 @@ class MacOSXEmail(Email):\n         if recipient:\n             uri += str(recipient)\n         if subject:\n-            uri += "?" if not "?" in uri else "&"\n+            uri += "?" if "?" not in uri else "&"\n             uri += "subject="\n             uri += quote(str(subject))\n         if text:\n-            uri += "?" if not "?" in uri else "&"\n+            uri += "?" if "?" not in uri else "&"\n             uri += "body="\n             uri += quote(str(text))\n \ndiff --git a/plyer/platforms/macosx/libs/osx_motion_sensor.py b/plyer/platforms/macosx/libs/osx_motion_sensor.py\nindex cd4fae4..d1bb6fd 100644\n--- a/plyer/platforms/macosx/libs/osx_motion_sensor.py\n+++ b/plyer/platforms/macosx/libs/osx_motion_sensor.py\n@@ -57,8 +57,10 @@ def read_sms():\n     matchingDictionary = IOKit.IOServiceMatching("SMCMotionSensor")\n \n     iterator = io_iterator_t()\n-    result = IOKit.IOServiceGetMatchingServices(masterPort, matchingDictionary,\n-                                            ctypes.byref(iterator))\n+    result = IOKit.IOServiceGetMatchingServices(\n+        masterPort, matchingDictionary,\n+        ctypes.byref(iterator)\n+    )\n \n     if (result != KERN_SUCCESS):\n         raise ("No coordinates received!")\n@@ -71,8 +73,10 @@ def read_sms():\n         return -2, None\n \n     dataPort = io_connect_t()\n-    result = IOKit.IOServiceOpen(smsDevice, IOKit.mach_task_self(), 0,\n-                            ctypes.byref(dataPort))\n+    result = IOKit.IOServiceOpen(\n+        smsDevice, IOKit.mach_task_self(),\n+        0, ctypes.byref(dataPort)\n+    )\n \n     if (result != KERN_SUCCESS):\n         return -3, None\n@@ -84,16 +88,20 @@ def read_sms():\n         structureInSize = IOItemCount(sizeof(data_structure))\n         structureOutSize = c_size_t(sizeof(data_structure))\n \n-        result = IOKit.IOConnectCallStructMethod(dataPort, KERN_FUNC,\n-                    ctypes.byref(inStructure), structureInSize,\n-                    ctypes.byref(outStructure), ctypes.byref(structureOutSize))\n+        result = IOKit.IOConnectCallStructMethod(\n+            dataPort, KERN_FUNC,\n+            ctypes.byref(inStructure), structureInSize,\n+            ctypes.byref(outStructure), ctypes.byref(structureOutSize)\n+        )\n     else:\n         structureInSize = IOItemCount(sizeof(data_structure))\n         structureOutSize = IOItemCount(sizeof(data_structure))\n \n-        result = IOConnectMethodStructureIStructureO(dataPort, KERN_FUNC,\n-                    structureInSize, ctypes.byref(structureOutSize),\n-                    ctypes.byref(inStructure), ctypes.byref(outStructure))\n+        result = IOConnectMethodStructureIStructureO(\n+            dataPort, KERN_FUNC,\n+            structureInSize, ctypes.byref(structureOutSize),\n+            ctypes.byref(inStructure), ctypes.byref(outStructure)\n+        )\n \n     IOKit.IOServiceClose(dataPort)\n \ndiff --git a/plyer/platforms/macosx/uniqueid.py b/plyer/platforms/macosx/uniqueid.py\nindex cdaca57..cbe61ac 100644\n--- a/plyer/platforms/macosx/uniqueid.py\n+++ b/plyer/platforms/macosx/uniqueid.py\n@@ -11,8 +11,10 @@ class OSXUniqueID(UniqueID):\n         environ[\'LANG\'] = \'C\'\n \n         ioreg_process = Popen(["ioreg", "-l"], stdout=PIPE)\n-        grep_process = Popen(["grep", "IOPlatformSerialNumber"],\n-            stdin=ioreg_process.stdout, stdout=PIPE)\n+        grep_process = Popen(\n+            ["grep", "IOPlatformSerialNumber"],\n+            stdin=ioreg_process.stdout, stdout=PIPE\n+        )\n         ioreg_process.stdout.close()\n         output = grep_process.communicate()[0]\n \ndiff --git a/plyer/platforms/macosx/wifi.py b/plyer/platforms/macosx/wifi.py\nindex c576129..39a5821 100644\n--- a/plyer/platforms/macosx/wifi.py\n+++ b/plyer/platforms/macosx/wifi.py\n@@ -96,8 +96,8 @@ class OSXWifi(Wifi):\n             cnt = scan.allObjects().count()\n             for i in range(cnt):\n                 self.names[\n-                    scan.allObjects().objectAtIndex_(i).ssid.UTF8String()] \\\n-                           = scan.allObjects().objectAtIndex_(i)\n+                    scan.allObjects().objectAtIndex_(i).ssid.UTF8String()\n+                ] = scan.allObjects().objectAtIndex_(i)\n         else:\n             raise Exception("Wifi not enabled.")\n \n', 'commit_subject': 'Fix pep8 in Mac+iOS', 'repo_name': 'kivy/plyer', 'committer': {'name': 'Peter Badida', 'email': '02235852529b35cba14f766340afbe46d9b346d1@users.noreply.github.com', 'time_sec': '1504305705', 'tz_offset': '120', 'date': {'seconds': '1504305705'}}, 'commit_tree': '81452ba796ce41b055bd9822d977da1f66cd2f03', 'commit_message': 'Fix pep8 in Mac+iOS\n', 'language_name': 'HTML', 'license': 'mit', 'hunks': '@@ -96,8 +96,8 @@ class OSXWifi(Wifi):\n             cnt = scan.allObjects().count()\n             for i in range(cnt):\n                 self.names[\n-                    scan.allObjects().objectAtIndex_(i).ssid.UTF8String()] \\\n-                           = scan.allObjects().objectAtIndex_(i)\n+                    scan.allObjects().objectAtIndex_(i).ssid.UTF8String()\n+                ] = scan.allObjects().objectAtIndex_(i)\n         else:\n             raise Exception("Wifi not enabled.")\n \n', 'addition_count': 2, 'deletion_count': 2, 'src_file': 'a/plyer/platforms/macosx/wifi.py', 'tgt_file': 'b/plyer/platforms/macosx/wifi.py', 'file_extension': '.py', 'before_file': 'from pyobjus import autoclass\nfrom pyobjus.dylib_manager import load_framework, INCLUDE\n\nfrom plyer.facades import Wifi\n\nload_framework(INCLUDE.Foundation)\nload_framework(INCLUDE.CoreWLAN)\n\nCWInterface = autoclass(\'CWInterface\')\nCWNetwork = autoclass(\'CWNetwork\')\nCWWiFiClient = autoclass(\'CWWiFiClient\')\nNSArray = autoclass(\'NSArray\')\nNSDictionary = autoclass(\'NSDictionary\')\nNSString = autoclass(\'NSString\')\n\n\nclass OSXWifi(Wifi):\n    names = {}\n\n    def _is_enabled(self):\n        \'\'\'\n        Returns `True` if the Wifi is enabled else  returns `False`.\n        \'\'\'\n        return CWWiFiClient.sharedWiFiClient().interface().powerOn()\n\n    def _get_network_info(self, name):\n        \'\'\'\n        Returns all the network information.\n        \'\'\'\n\n        accessNetworkType = self.names[name].accessNetworkType\n        aggregateRSSI = self.names[name].aggregateRSSI\n        beaconInterval = self.names[name].beaconInterval\n        bssid = self.names[name].bssid.UTF8String()\n        countryCode = self.names[name].countryCode\n        hasInternet = self.names[name].hasInternet\n        hasInterworkingIE = self.names[name].hasInterworkingIE\n        hessid = self.names[name].hessid\n        ibss = self.names[name].ibss\n        isAdditionalStepRequiredForAccess = \\\n            self.names[name].isAdditionalStepRequiredForAccess\n        isCarPlayNetwork = self.names[name].isCarPlayNetwork\n        isEmergencyServicesReachable = \\\n            self.names[name].isEmergencyServicesReachable\n        isPasspoint = self.names[name].isPasspoint\n        isPersonalHotspot = self.names[name].isPersonalHotspot\n        isUnauthenticatedEmergencyServiceAccessible = \\\n            self.names[name].isUnauthenticatedEmergencyServiceAccessible\n        noiseMeasurement = self.names[name].noiseMeasurement\n        physicalLayerMode = self.names[name].physicalLayerMode\n        rssiValue = self.names[name].rssiValue\n        securityType = self.names[name].securityType\n        ssid = self.names[name].ssid.UTF8String()\n        supportsEasyConnect = self.names[name].supportsEasyConnect\n        supportsWPS = self.names[name].supportsWPS\n        venueGroup = self.names[name].venueGroup\n        venueType = self.names[name].venueType\n\n        return {\'accessNetworkType\': accessNetworkType,\n                \'aggregateRSSI\': aggregateRSSI,\n                \'beaconInterval\': beaconInterval,\n                \'bssid\': bssid,\n                \'countryCode\': countryCode,\n                \'hasInternet\': hasInternet,\n                \'hasInterworkingIE\': hasInterworkingIE,\n                \'hessid\': hessid,\n                \'ibss\': ibss,\n                \'isAdditionalStepRequiredForAccess\':\n                isAdditionalStepRequiredForAccess,\n                \'isCarPlayNetwork\': isCarPlayNetwork,\n                \'isEmergencyServicesReachable\': isEmergencyServicesReachable,\n                \'isPasspoint\': isPasspoint,\n                \'isPersonalHotspot\': isPersonalHotspot,\n                \'isUnauthenticatedEmergencyServiceAccessible\':\n                isUnauthenticatedEmergencyServiceAccessible,\n                \'noiseMeasurement\': noiseMeasurement,\n                \'physicalLayerMode\': physicalLayerMode,\n                \'rssiValue\': rssiValue,\n                \'securityType\': securityType,\n                \'ssid\': ssid,\n                \'supportsEasyConnect\': supportsEasyConnect,\n                \'supportsWPS\': supportsWPS,\n                \'venueGroup\': venueGroup,\n                \'venueType\': venueType}\n\n    def _start_scanning(self):\n        \'\'\'\n        Starts scanning for available Wi-Fi networks.\n        \'\'\'\n        if self._is_enabled():\n            self.names = {}\n            c = CWInterface.interface()\n            scan = c.scanForNetworksWithName_error_(None, None)\n            cnt = scan.allObjects().count()\n            for i in range(cnt):\n            cnt = scan.allObjects().count()\n            for i in range(cnt):\n                self.names[\n                    scan.allObjects().objectAtIndex_(i).ssid.UTF8String()] \\\n                           = scan.allObjects().objectAtIndex_(i)\n        else:\n            raise Exception("Wifi not enabled.")\n\n        Returns the name of available networks.\n        \'\'\'\n        return self.names.keys()\n\n    def _connect(self, network, parameters):\n        \'\'\'\n        Expects 2 parameters:\n            - name/ssid of the network.\n            - password: dict type\n        \'\'\'\n        password = parameters[\'password\']\n        network_object = self.names[network]\n        CWInterface.interface().associateToNetwork_password_error_(\n            network_object,\n            password,\n            None)\n        return\n\n    def _disconnect(self):\n        \'\'\'\n        Disconnect from network.\n        \'\'\'\n        CWInterface.interface().disassociate()\n        return\n\n    def _disable(self):\n        \'\'\'\n        Wifi interface power state is set to "OFF".\n        \'\'\'\n\n        interface = CWWiFiClient.sharedWiFiClient().interface()\n        interface.setPower_error_(False, None)\n\n    def _enable(self):\n        \'\'\'\n        Wifi interface power state is set to "ON".\n        \'\'\'\n\n        interface = CWWiFiClient.sharedWiFiClient().interface()\n        interface.setPower_error_(True, None)\n\n\ndef instance():\n    return OSXWifi()\n', 'message': 'Fix pep8 in Mac+iOS\n', 'author_name': 'Peter Badida', 'lang': 'py'}