Try to guess the best 'device_type' based on patterns defined in SSH_MAPPER_BASE

        Returns
        -------
        best_match : str or None
            The device type that is currently the best to use to interact with the device
439132
def autodetect(self):
        
        for device_type, autodetect_dict in SSH_MAPPER_BASE.items():
            tmp_dict = autodetect_dict.copy()
            call_method = tmp_dict.pop("dispatch")
            autodetect_method = getattr(self, call_method)
            accuracy = autodetect_method(**tmp_dict)
            if accuracy:
                self.potential_matches[device_type] = accuracy
                if accuracy >= 99:  # Stop the loop as we are sure of our match
                    best_match = sorted(
                        self.potential_matches.items(), key=lambda t: t[1], reverse=True
                    )
                    self.connection.disconnect()
                    return best_match[0][0]

        if not self.potential_matches:
            self.connection.disconnect()
            return None

        best_match = sorted(
            self.potential_matches.items(), key=lambda t: t[1], reverse=True
        )
        self.connection.disconnect()
        return best_match[0][0]
1168859
protected function guess_device_type() {
        global $CFG;
        if (empty($CFG->enabledevicedetection)) {
            $this->devicetype = self::DEVICETYPE_DEFAULT;
            return $this->devicetype;
        }
        foreach ($this->devicetypecustoms as $value => $regex) {
            if (preg_match($regex, $this->useragent)) {
                $this->devicetype = $value;
                return $this->devicetype;
            }
        }
        if ($this->is_useragent_mobile()) {
            $this->devicetype = self::DEVICETYPE_MOBILE;
        } else if ($this->is_useragent_tablet()) {
            $this->devicetype = self::DEVICETYPE_TABLET;
        } else if (self::check_ie_version('0') && !self::check_ie_version('7.0')) {
            // IE 6 and before are considered legacy.
            $this->devicetype = self::DEVICETYPE_LEGACY;
        } else {
            $this->devicetype = self::DEVICETYPE_DEFAULT;
        }
        return $this->devicetype;
    }
1246239
def _get_devices(params):
    '''
    
    '''
    if 'id' not in params:
        raise CommandExecutionError("Parameter ID is required.")

    return type(params['id']) == int and [params['id']] \
           or [int(dev) for dev in params['id'].split(",")]
488067
def devices(self):
        
        service_root = self.webservices['findme']['url']
        return FindMyiPhoneServiceManager(
            service_root,
            self.session,
            self.params
        )
43734
def guess_mime_type(content, deftype):
    
    #Mappings recognized by cloudinit
    starts_with_mappings={
        '#include' : 'text/x-include-url',
        '#!' : 'text/x-shellscript',
        '#cloud-config' : 'text/cloud-config',
        '#upstart-job'  : 'text/upstart-job',
        '#part-handler' : 'text/part-handler',
        '#cloud-boothook' : 'text/cloud-boothook'
    }
    rtype = deftype
    for possible_type,mimetype in starts_with_mappings.items():
        if content.startswith(possible_type):
            rtype = mimetype
            break
    return(rtype)
1356790
def find_device(device=None):
    '''
    
    '''

    data = [{'uid': '/zport/dmd/Devices', 'params': {}, 'limit': None}]
    all_devices = _router_request('DeviceRouter', 'getDevices', data=data)
    for dev in all_devices['devices']:
        if dev['name'] == device:
            # We need to save the has for later operations
            dev['hash'] = all_devices['hash']
            log.info('Found device %s in Zenoss', device)
            return dev

    log.info('Unable to find device %s in Zenoss', device)
    return None
130890
def is_device(obj):
    
    return isinstance(obj, type) and issubclass(
        obj, DeviceBase) and obj.__module__ not in ('lewis.devices', 'lewis.core.devices')
29009
def find_serial_devices(serial_matcher="ED"):
    
    objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
    objSWbemServices = objWMIService.ConnectServer(".", "root\cimv2")
    items = objSWbemServices.ExecQuery("SELECT * FROM Win32_USBControllerDevice")
    ids = (item.Dependent.strip('"')[-8:] for item in items)
    return [e for e in ids if e.startswith(serial_matcher)]
10127
def findConnectedDevices(self):
        
        tmpTimeout = self._serial.timeout
        self._serial.timeout = 0.01

        for dev in range(128):
            device = self._getDeviceID(dev)

            if device is not None and int(device) not in self._deviceConfig:
                config = self._deviceConfig.setdefault(int(device), {})
                self._deviceCallback(device, config)
                self._log and self._log.info(
                    "Found device '%s' with configuration: %s", device, config)

        self._serial.timeout = tmpTimeout
1245814
def _check_type(self):
        '''
        '''

        if self.type not in self.available_types:
            msg = 'Unsupported cluster type was given: %s' % self.type
            raise DeviceGroupNotSupported(msg)
        elif self.type == 'sync-only' and self.name != 'device_trust_group':
            msg = "Management of sync-only device groups only supported for " \
                "built-in device group named 'device_trust_group'"
            raise DeviceGroupNotSupported(msg)
88318
def get_device(self, rid):
        
        headers = {
                'User-Agent': self.user_agent(),
                'Content-Type': self.content_type()
        }
        headers.update(self.headers())

        url = self.portals_url()+'/devices/'+rid
        # print("URL: {0}".format(url))

        r = requests.get(   url,
                            headers=headers,
                            auth=self.auth())
    
        if HTTP_STATUS.OK == r.status_code:
            # fix the 'meta' to be dictionary instead of string
            device_obj = r.json()
            # device_obj['info']['description']['meta'] = \
                    # json.loads(device_obj['info']['description']['meta'])
            return device_obj
        else:
            print("get_device: Something went wrong: <{0}>: {1}".format(
                        r.status_code, r.reason))
            r.raise_for_status()
529272
def type(self):
        
        if self._device_mode == 1 or self._type == CertificateType.developer:
            return CertificateType.developer
        elif self._type == CertificateType.bootstrap:
            return CertificateType.bootstrap
        else:
            return CertificateType.lwm2m
1307254
def device_filter(self):
        
        if isinstance(self._device_filter, str):
            return self._decode_query(self._device_filter)
        return self._device_filter
755297
def device(value):
    

    browser = None
    for regex, name in BROWSERS:
        if regex.search(value):
            browser = name
            break

    device = None
    for regex, name in DEVICES:
        if regex.search(value):
            device = name
            break

    if browser and device:
        return _('%(browser)s on %(device)s') % {
            'browser': browser,
            'device': device
        }

    if browser:
        return browser

    if device:
        return device

    return None
239214
def device_priority(cls, device_with_type_tuple):
        
        device, device_type = device_with_type_tuple
        return (device_type is pyopencl.device_type.GPU,
                device.get_info(pyopencl.device_info.GLOBAL_MEM_SIZE),
                )
644454
def get_device_opts(opts, salt_obj=None):
    '''
    
    '''
    network_device = {}
    # by default, look in the proxy config details
    device_dict = opts.get('proxy', {}) if is_proxy(opts) else opts.get('napalm', {})
    if opts.get('proxy') or opts.get('napalm'):
        opts['multiprocessing'] = device_dict.get('multiprocessing', False)
        # Most NAPALM drivers are SSH-based, so multiprocessing should default to False.
        # But the user can be allows one to have a different value for the multiprocessing, which will
        #   override the opts.
    if not device_dict:
        # still not able to setup
        log.error('Incorrect minion config. Please specify at least the napalm driver name!')
    # either under the proxy hier, either under the napalm in the config file
    network_device['HOSTNAME'] = device_dict.get('host') or \
                                 device_dict.get('hostname') or \
                                 device_dict.get('fqdn') or \
                                 device_dict.get('ip')
    network_device['USERNAME'] = device_dict.get('username') or \
                                 device_dict.get('user')
    network_device['DRIVER_NAME'] = device_dict.get('driver') or \
                                    device_dict.get('os')
    network_device['PASSWORD'] = device_dict.get('passwd') or \
                                 device_dict.get('password') or \
                                 device_dict.get('pass') or \
                                 ''
    network_device['TIMEOUT'] = device_dict.get('timeout', 60)
    network_device['OPTIONAL_ARGS'] = device_dict.get('optional_args', {})
    network_device['ALWAYS_ALIVE'] = device_dict.get('always_alive', True)
    network_device['PROVIDER'] = device_dict.get('provider')
    network_device['UP'] = False
    # get driver object form NAPALM
    if 'config_lock' not in network_device['OPTIONAL_ARGS']:
        network_device['OPTIONAL_ARGS']['config_lock'] = False
    if network_device['ALWAYS_ALIVE'] and 'keepalive' not in network_device['OPTIONAL_ARGS']:
        network_device['OPTIONAL_ARGS']['keepalive'] = 5  # 5 seconds keepalive
    return network_device
1189286
def get_network_adapter_type(adapter_type):
    '''
    
    '''
    if adapter_type == 'vmxnet':
        return vim.vm.device.VirtualVmxnet()
    elif adapter_type == 'vmxnet2':
        return vim.vm.device.VirtualVmxnet2()
    elif adapter_type == 'vmxnet3':
        return vim.vm.device.VirtualVmxnet3()
    elif adapter_type == 'e1000':
        return vim.vm.device.VirtualE1000()
    elif adapter_type == 'e1000e':
        return vim.vm.device.VirtualE1000e()

    raise ValueError('An unknown network adapter object type name.')