Return a cffi console.
346452
def _console(console: Any) -> Any:
    """"""
    try:
        return console.console_c
    except AttributeError:
        warnings.warn(
            (
                "Falsy console parameters are deprecated, "
                "always use the root console instance returned by "
                "console_init_root."
            ),
            DeprecationWarning,
            stacklevel=3,
        )
        return ffi.NULL
191650
def console_output(msg, logging_msg=None):
    """"""
    assert isinstance(msg, bytes)
    assert isinstance(logging_msg, bytes) or logging_msg is None

    from polysh import remote_dispatcher

    remote_dispatcher.log(logging_msg or msg)
    if remote_dispatcher.options.interactive:
        from polysh.stdin import the_stdin_thread
        the_stdin_thread.no_raw_input()
        global last_status_length
        if last_status_length:
            safe_write('\r{}\r'.format(
                last_status_length * ' ').encode())
            last_status_length = 0
    safe_write(msg)
1067783
function(consoles) {

        var webPanel = express.Router();

        //Static files

        webPanel.use('/', express.static(path.join(__dirname, '..', 'static')));

        //API

        /**
         * readDir
         *
         * Return dir content
         *
         * @param {String}      dirPath     A path
         * @param {Function}    callback    Function to chain with result array
         */
        var readDir = function(dirPath, callback) {

            if (!dirPath || typeof dirPath !== 'string') {
                callback("dirPath must be a string");
            } else {
                fs.readdir(dirPath, function(err, list) {
                    var dir = [];

                    if (err) {
                        callback(err, null);
                    } else {
                        list.forEach(function(item) {
                            dir.push(readNode(path.join(dirPath, item)));
                        });

                        callback(null, dir);
                    }

                });
            }

        };

        /**
         * readNode
         *
         * Return some infos on the file or folder given
         *
         * @param  {String} itemPath    A path
         * @return {Object}
         * @return {String} type        'folder' or 'file'
         * @return {String} name
         * @return {String} path        @see params
         */
        var readNode = function(itemPath) {

            var info = fs.statSync(itemPath),
                item = {};

            item.type = info.isDirectory() ? 'folder' : 'file';
            item.name = path.basename(itemPath);
            item.path = itemPath;

            return item;
        };

        /**
         * getLogFolders
         *
         * @return {Array}  logs folder in use
         */
        var getLogFolders = function() {

            return map(consoles, function(elem) {
                return elem.logWriter ? elem.logWriter.rootPath : undefined;
            });
        };

        /**
         * getLogWriter
         *
         * @param {String}  logFolder   root folder of the logWriter to find
         *
         * @return {LogWriter|false}    If false, no logWriter with rootPath set to logFolder
         */
        var getLogWriter = function(logFolder) {

            var logWriter;

            return consoles.some(function(item) {
                if (item.logWriter && item.logWriter.rootPath === logFolder) {
                    logWriter = item.logWriter;
                    return true;
                }
            }) ? logWriter : false;

        };

         /**

        * This function scans through any webPanel request.
        * if the request contains the 'path' query parameter then it will pass it
        * through a check that ensures the following:
            - it contains logs
            - it contains 20xx
            - it is accessing a .json file
        * if it passess the checks it sends the request to the next webPanel function
        * otherwise it returns a json error message



        */

        webPanel.use(function(req, res, next){

            var path = req.query.path

            if(path!=null){

                if(path.indexOf("logs")!=-1 && path.indexOf("20")!=-1 && path.indexOf(".json")!=-1) {

                    next();

                } else {

                    var response = {};
                    response.error = true;
                    res.json(response);


                }

            } else {

                next();
            }




        });


        /**
         * /api
         *
         * Send logWriters
         */
        webPanel.get('/api', function(req, res) {

            var path = req.query.path;

            res.status(200).json(getLogFolders());
        });

        /**
         * /api/folderExplorer
         *
         * Send path content info
         */
        webPanel.get('/api/folderExplorer', function(req, res) {

            var path = req.query.path;

            readDir(path, function(err, dir) {
                if (err) {
                    res.status(400).end();
                } else {
                    res.status(200).json(dir);
                }
            });
        });

        /**
         * /api/dateExplorer
         *
         * Send files according to history dates
         * With pagination
         */
        webPanel.get('/api/dateExplorer', function(req, res) {

            var from = req.query.from || Date.now(),
                length = req.query.length || 10,
                logFolder = req.query.logFolder;

            var logWriter = getLogWriter(logFolder);

            if (!logWriter) {
                res.status(400).send('No logWriter attached to ' + logFolder);
            } else {

                var logWriterDates = Object.keys(logWriter.history.dates).sort();

                //Find the good dates
                var nb = 0,
                    result = [],
                    dates = logWriterDates.reverse().filter(function(date) {
                        if (date < from && nb <= length) {
                            nb++;
                            return date;
                        } else {
                            return null;
                        }
                    });

                dates.forEach(function(date) {
                    result.push({
                        date: date,
                        files: map(logWriter.history.dates[date], function(item) {
                            return {
                                name: path.basename(item),
                                path: item
                            };
                        })
                    });
                });

                res.status(200).json(result);
            }
        });

        /**
         * /api/log
         *
         * Send stream of file content
         */
        webPanel.get('/api/log', function(req, res) {

            var path = req.query.path;

            if (fs.existsSync(path)) {
                var stream = fs.createReadStream(path);

                res.writeHead(200, {
                    'Content-Length': fs.statSync(path).size,
                    'Content-Type': 'text/plain'
                });

                res.status(200);
                stream.pipe(res);
            } else {
                res.status(400).send("Can't read path");
            }
        });


        /**
         * /api/timezone
         *
         * Send the server timezone offset
         */
        webPanel.get('/api/timezoneOffset', function (req, res) {

            res.status(200).json({
                timezoneOffset : (new Date()).getTimezoneOffset()
            });

        });

        return webPanel;

    }
458752
def LegacyKextload(self, cf_bundle_url, dependency_kext):
    """"""
    _ = dependency_kext
    error_code = OS_SUCCESS
    cf_path = self.dll.CFURLCopyFileSystemPath(cf_bundle_url, POSIX_PATH_STYLE)
    path = self.CFStringToPystring(cf_path)
    self.dll.CFRelease(cf_path)
    try:
      subprocess.check_call(['/sbin/kextload', path])
    except subprocess.CalledProcessError as cpe:
      logging.debug('failed to load %s:%s', path, str(cpe))
      error_code = -1
    return error_code
36690
def WrapCFTypeInPython(self, obj):
    
    obj_type = self.dll.CFGetTypeID(obj)
    if obj_type == self.dll.CFBooleanGetTypeID():
      return CFBoolean(obj)
    elif obj_type == self.dll.CFNumberGetTypeID():
      return CFNumber(obj)
    elif obj_type == self.dll.CFStringGetTypeID():
      return CFString(obj)
    elif obj_type == self.dll.CFDictionaryGetTypeID():
      return CFDictionary(obj)
    elif obj_type == self.dll.CFArrayGetTypeID():
      return CFArray(obj)
    else:
      raise TypeError('Unknown type for object: {0}'.format(obj))
841644
def image_from_console(console: tcod.console.Console) -> tcod.image.Image:
    
    return tcod.image.Image._from_cdata(
        ffi.gc(
            lib.TCOD_image_from_console(_console(console)),
            lib.TCOD_image_delete,
        )
    )
682985
def get_devices():
    """"""
    buf = create_string_buffer(512)
    buflen = c_uint32(sizeof(buf))
    DAQmxGetSysDevNames(buf, buflen)
    pybuf = buf.value
    devices = pybuf.decode(u'utf-8').split(u",")
    return devices
1309416
def _ioctl(self, func, arg):
        """"""
        if self._fd is None:
            raise WatchdogError("Watchdog device is closed")
        if os.name != 'nt':
            import fcntl
            fcntl.ioctl(self._fd, func, arg, True)
418766
def default_fg(self) -> Tuple[int, int, int]:
        """"""
        color = self._console_data.fore
        return color.r, color.g, color.b
662179
def c(self):
        """"""
        if self._client is None:
            self._parse_settings()
            self._client = Rumetr(**self.settings)
        return self._client
702767
def _get_auth_from_console(self, realm):
        """"""
        self.user, self.password = self.AUTH_MEMOIZE_INPUT.get(realm, (self.user, None))
        if not self.auth_valid():
            if not self.user:
                login = getpass.getuser()
                self.user = self._raw_input('Username for "{}" [{}]: '.format(realm, login)) or login
            self.password = getpass.getpass('Password for "{}": '.format(realm))
            Credentials.AUTH_MEMOIZE_INPUT[realm] = self.user, self.password

        return 'console'
813856
def cfunc(name, result, *args):
    """"""
    atypes = []
    aflags = []
    for arg in args:
        atypes.append(arg[1])
        aflags.append((arg[2], arg[0]) + arg[3:])
    return CFUNCTYPE(result, *atypes)((name, _fl), tuple(aflags))
1366973
def LegacyKextunload(self, cf_bundle_identifier):
    """"""
    error_code = OS_SUCCESS
    bundle_identifier = self.CFStringToPystring(cf_bundle_identifier)
    try:
      subprocess.check_call(['/sbin/kextunload', '-b', bundle_identifier])
    except subprocess.CalledProcessError as cpe:
      logging.debug('failed to unload %s:%s', bundle_identifier, str(cpe))
      error_code = -1
    return error_code
1094500
def inspect
      cf = CF::String.new(CF.CFCopyDescription(self))
      cf.to_s.tap {cf.release}
    end
443064
def _loadf(ins):
    
    output = _float_oper(ins.quad[2])
    output.extend(_fpush())
    return output
446642
def _newConsole(cls, console):
        """"""
        self = cls.__new__(cls)
        _BaseConsole.__init__(self)
        self.console_c = console
        self.console = self
        self.width = _lib.TCOD_console_get_width(console)
        self.height = _lib.TCOD_console_get_height(console)
        return self
115591
def get_if(iff, cmd):
    """"""

    sck = socket.socket()
    ifreq = ioctl(sck, cmd, struct.pack("16s16x", iff.encode("utf8")))
    sck.close()
    return ifreq