• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python _util.ensure_unicode_string函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pyudev._util.ensure_unicode_string函数的典型用法代码示例。如果您正苦于以下问题:Python ensure_unicode_string函数的具体用法?Python ensure_unicode_string怎么用?Python ensure_unicode_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了ensure_unicode_string函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: sys_number

    def sys_number(self):
        """
        The trailing number of the :attr:`sys_name` as unicode string, or
        ``None``, if the device has no trailing number in its name.

        .. note::

           The number is returned as unicode string to preserve the exact
           format of the number, especially any leading zeros:

           >>> from pyudev import Context, Device
           >>> context = Context()
           >>> device = Device.from_path(context, '/sys/devices/LNXSYSTM:00')
           >>> device.sys_number
           u'00'

           To work with numbers, explicitly convert them to ints:

           >>> int(device.sys_number)
           0

        .. versionadded:: 0.11
        """
        number = libudev.udev_device_get_sysnum(self)
        if number is not None:
            return ensure_unicode_string(number)
开发者ID:PSC-SR,项目名称:robotpy,代码行数:26,代码来源:device.py


示例2: receive_device

    def receive_device(self):
        """
        Receive a single device from the monitor.

        The caller must make sure, that there are events available in the
        event queue.  The call blocks, until a device is available.

        If a device was available, return ``(action, device)``.  ``device``
        is the :class:`Device` object describing the device.  ``action`` is
        a string describing the action.  udev informs about the following
        actions:

        ``'add'``
          A device has been added (e.g. a USB device was plugged in)
        ``'remove'``
          A device has been removed (e.g. a USB device was unplugged)
        ``'change'``
          Something about the device changed (e.g. a device property)
        ``'move'``
          The device was renamed, moved, or re-parented

        Raise :exc:`~exceptions.EnvironmentError`, if no device could be
        read.
        """
        try:
            device_p = libudev.udev_monitor_receive_device(self)
        except EnvironmentError:
            self._reraise_with_socket_path()
        if not device_p:
            raise EnvironmentError('Could not receive device')
        action = ensure_unicode_string(
            libudev.udev_device_get_action(device_p))
        return action, Device(self.context, device_p)
开发者ID:lanstat,项目名称:pyudev,代码行数:33,代码来源:monitor.py


示例3: device_path

    def device_path(self):
        """
        The device directory path defaulting to ``/dev`` as unicode string.

        This can be overridden in the udev configuration.
        """
        return ensure_unicode_string(libudev.udev_get_dev_path(self))
开发者ID:lanstat,项目名称:pyudev,代码行数:7,代码来源:core.py


示例4: sys_path

 def sys_path(self):
     """
     Absolute path of this device in ``sysfs`` including the ``sysfs``
     mount point as unicode string.
     """
     return ensure_unicode_string(
         self._libudev.udev_device_get_syspath(self))
开发者ID:cjmayo,项目名称:pyudev,代码行数:7,代码来源:_device.py


示例5: action

    def action(self):
        """
        The device event action as string, or ``None``, if this device was not
        received from a :class:`Monitor`.

        Usual actions are:

        ``'add'``
          A device has been added (e.g. a USB device was plugged in)
        ``'remove'``
          A device has been removed (e.g. a USB device was unplugged)
        ``'change'``
          Something about the device changed (e.g. a device property)
        ``'online'``
          The device is online now
        ``'offline'``
          The device is offline now

        .. warning::

           Though the actions listed above are the most common, this property
           *may* return other values, too, so be prepared to handle unknown
           actions!

        .. versionadded:: 0.16
        """
        action = libudev.udev_device_get_action(self)
        if action:
            return ensure_unicode_string(action)
开发者ID:PSC-SR,项目名称:robotpy,代码行数:29,代码来源:device.py


示例6: device_links

    def device_links(self):
        """
        An iterator, which yields the absolute paths (including the device
        directory, see :attr:`Context.device_path`) of all symbolic links
        pointing to the :attr:`device_node` of this device.  The paths are
        unicode strings.

        UDev can create symlinks to the original device node (see
        :attr:`device_node`) inside the device directory.  This is often
        used to assign a constant, fixed device node to devices like
        removeable media, which technically do not have a constant device
        node, or to map a single device into multiple device hierarchies.
        The property provides access to all such symbolic links, which were
        created by UDev for this device.

        .. warning::

           Links are not necessarily resolved by
           :meth:`Device.from_device_file()`. Hence do *not* rely on
           ``Device.from_device_file(context, link).device_path ==
           device.device_path`` from any ``link`` in ``device.device_links``.
        """
        devlinks = libudev.udev_device_get_devlinks_list_entry(self)
        for name, _ in udev_list_iterate(devlinks):
            yield ensure_unicode_string(name)
开发者ID:PSC-SR,项目名称:robotpy,代码行数:25,代码来源:device.py


示例7: udev_version

def udev_version():
    """
    Get the version of the underlying udev library.

    udev doesn't use a standard major-minor versioning scheme, but instead
    labels releases with a single consecutive number.  Consequently, the
    version number returned by this function is a single integer, and not a
    tuple (like for instance the interpreter version in
    :data:`sys.version_info`).

    As libudev itself does not provide a function to query the version number,
    this function calls the ``udevadm`` utilitiy, so be prepared to catch
    :exc:`~exceptions.EnvironmentError` and
    :exc:`~subprocess.CalledProcessError` if you call this function.

    Return the version number as single integer.  Raise
    :exc:`~exceptions.ValueError`, if the version number retrieved from udev
    could not be converted to an integer.  Raise
    :exc:`~exceptions.EnvironmentError`, if ``udevadm`` was not found, or could
    not be executed.  Raise :exc:`subprocess.CalledProcessError`, if
    ``udevadm`` returned a non-zero exit code.  On Python 2.7 or newer, the
    ``output`` attribute of this exception is correctly set.

    .. versionadded:: 0.8
    """
    output = ensure_unicode_string(check_output(['udevadm', '--version']))
    return int(output.strip())
开发者ID:AlexisCaffa,项目名称:multibootusb,代码行数:27,代码来源:core.py


示例8: sys_path

    def sys_path(self):
        """
        The ``sysfs`` mount point defaulting to ``/sys'`` as unicode string.

        The mount point can be overwritten using the environment variable
        :envvar:`SYSFS_PATH`.  Use this for testing purposes.
        """
        return ensure_unicode_string(libudev.udev_get_sys_path(self))
开发者ID:lanstat,项目名称:pyudev,代码行数:8,代码来源:core.py


示例9: driver

    def driver(self):
        """
        The driver name as unicode string, or ``None``, if there is no
        driver for this device.

        .. versionadded:: 0.5
        """
        driver = self._libudev.udev_device_get_driver(self)
        return ensure_unicode_string(driver) if driver else None
开发者ID:cjmayo,项目名称:pyudev,代码行数:9,代码来源:_device.py


示例10: __iter__

    def __iter__(self):
        """
        Iterate over all tags.

        Yield each tag as unicode string.
        """
        tags = libudev.udev_device_get_tags_list_entry(self.device)
        for tag, _ in udev_list_iterate(tags):
            yield ensure_unicode_string(tag)
开发者ID:PSC-SR,项目名称:robotpy,代码行数:9,代码来源:device.py


示例11: sys_path

 def sys_path(self):
     """
     The ``sysfs`` mount point defaulting to ``/sys'`` as unicode string.
     """
     if hasattr(self._libudev, 'udev_get_sys_path'):
         return ensure_unicode_string(self._libudev.udev_get_sys_path(self))
     else:
         # Fixed path since udev 183
         return '/sys'
开发者ID:AlexisCaffa,项目名称:multibootusb,代码行数:9,代码来源:core.py


示例12: device_path

 def device_path(self):
     """
     The device directory path defaulting to ``/dev`` as unicode string.
     """
     if hasattr(self._libudev, 'udev_get_dev_path'):
         return ensure_unicode_string(self._libudev.udev_get_dev_path(self))
     else:
         # Fixed path since udev 183
         return '/dev'
开发者ID:AlexisCaffa,项目名称:multibootusb,代码行数:9,代码来源:core.py


示例13: subsystem

    def subsystem(self):
        """
        Name of the subsystem this device is part of as unicode string.

        :returns: name of subsystem if found, else None
        :rtype: unicode string or NoneType
        """
        subsys = self._libudev.udev_device_get_subsystem(self)
        return None if subsys is None else ensure_unicode_string(subsys)
开发者ID:cjmayo,项目名称:pyudev,代码行数:9,代码来源:_device.py


示例14: device_path

    def device_path(self):
        """
        Kernel device path as unicode string.  This path uniquely identifies
        a single device.

        Unlike :attr:`sys_path`, this path does not contain the ``sysfs``
        mount point.  However, the path is absolute and starts with a slash
        ``'/'``.
        """
        return ensure_unicode_string(libudev.udev_device_get_devpath(self))
开发者ID:PSC-SR,项目名称:robotpy,代码行数:10,代码来源:device.py


示例15: run_path

    def run_path(self):
        """
        The run runtime directory path defaulting to ``/run`` as unicode
        string.

        .. udevversion:: 167

        .. versionadded:: 0.10
        """
        return ensure_unicode_string(libudev.udev_get_run_path(self))
开发者ID:lanstat,项目名称:pyudev,代码行数:10,代码来源:core.py


示例16: asstring

    def asstring(self, attribute):
        """
        Get the given ``attribute`` for the device as unicode string.

        :param attribute: the key for an attribute value
        :type attribute: unicode or byte string
        :returns: the value corresponding to ``attribute``, as unicode
        :rtype: unicode
        :raises KeyError: if no value found for ``attribute``
        :raises UnicodeDecodeError: if value is not convertible
        """
        return ensure_unicode_string(self._get(attribute))
开发者ID:cjmayo,项目名称:pyudev,代码行数:12,代码来源:_device.py


示例17: _get_attributes

 def _get_attributes(self):
     if hasattr(self._libudev, 'udev_device_get_sysattr_list_entry'):
         attrs = self._libudev.udev_device_get_sysattr_list_entry(
             self.device)
         for attribute, _ in udev_list_iterate(self._libudev, attrs):
             yield ensure_unicode_string(attribute)
     else:
         sys_path = self.device.sys_path
         for filename in os.listdir(sys_path):
             filepath = os.path.join(sys_path, filename)
             if _is_attribute_file(filepath):
                 yield filename
开发者ID:AlexisCaffa,项目名称:multibootusb,代码行数:12,代码来源:device.py


示例18: run_path

    def run_path(self):
        """
        The run runtime directory path defaulting to ``/run`` as unicode
        string.

        .. udevversion:: 167

        .. versionadded:: 0.10
        """
        if hasattr(self._libudev, 'udev_get_run_path'):
            return ensure_unicode_string(self._libudev.udev_get_run_path(self))
        else:
            return '/run/udev'
开发者ID:AlexisCaffa,项目名称:multibootusb,代码行数:13,代码来源:core.py


示例19: device_node

    def device_node(self):
        """
        Absolute path to the device node of this device as unicode string or
        ``None``, if this device doesn't have a device node.  The path
        includes the device directory (see :attr:`Context.device_path`).

        This path always points to the actual device node associated with
        this device, and never to any symbolic links to this device node.
        See :attr:`device_links` to get a list of symbolic links to this
        device node.
        """
        node = libudev.udev_device_get_devnode(self)
        if node:
            return ensure_unicode_string(node)
开发者ID:lanstat,项目名称:pyudev,代码行数:14,代码来源:device.py


示例20: __getitem__

    def __getitem__(self, property):
        """
        Get the given ``property`` from this device.

        ``property`` is a unicode or byte string containing the name of the
        property.

        Return the property value as unicode string, or raise a
        :exc:`~exceptions.KeyError`, if the given property is not defined
        for this device.
        """
        value = libudev.udev_device_get_property_value(
            self, ensure_byte_string(property))
        if value is None:
            raise KeyError(property)
        return ensure_unicode_string(value)
开发者ID:PSC-SR,项目名称:robotpy,代码行数:16,代码来源:device.py



注:本文中的pyudev._util.ensure_unicode_string函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python test_examples.two_triangles函数代码示例发布时间:2022-05-27
下一篇:
Python _util.ensure_byte_string函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap