当前位置: 首页>>代码示例>>Python>>正文


Python encoding.locale_decode函数代码示例

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


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

示例1: check_dirs_and_files

    def check_dirs_and_files(self):
        if not os.path.isdir(self.config["local"]["media_dir"]):
            logger.warning("Local media dir %s does not exist." % self.config["local"]["media_dir"])

        try:
            path.get_or_create_dir(self.config["local"]["data_dir"])
        except EnvironmentError as error:
            logger.warning("Could not create local data dir: %s", encoding.locale_decode(error))

        # TODO: replace with data dir?
        try:
            path.get_or_create_dir(self.config["local"]["playlists_dir"])
        except EnvironmentError as error:
            logger.warning("Could not create local playlists dir: %s", encoding.locale_decode(error))
开发者ID:karlpilkington,项目名称:mopidy,代码行数:14,代码来源:actor.py

示例2: _process

def _process(pipeline, timeout_ms):
    clock = pipeline.get_clock()
    bus = pipeline.get_bus()
    timeout = timeout_ms * gst.MSECOND
    tags, mime, have_audio, missing_description = {}, None, False, None

    types = (
        gst.MESSAGE_ELEMENT
        | gst.MESSAGE_APPLICATION
        | gst.MESSAGE_ERROR
        | gst.MESSAGE_EOS
        | gst.MESSAGE_ASYNC_DONE
        | gst.MESSAGE_TAG
    )

    start = clock.get_time()
    while timeout > 0:
        message = bus.timed_pop_filtered(timeout, types)

        if message is None:
            break
        elif message.type == gst.MESSAGE_ELEMENT:
            if gst.pbutils.is_missing_plugin_message(message):
                missing_description = encoding.locale_decode(_missing_plugin_desc(message))
        elif message.type == gst.MESSAGE_APPLICATION:
            if message.structure.get_name() == "have-type":
                mime = message.structure["caps"].get_name()
                if mime.startswith("text/") or mime == "application/xml":
                    return tags, mime, have_audio
            elif message.structure.get_name() == "have-audio":
                have_audio = True
        elif message.type == gst.MESSAGE_ERROR:
            error = encoding.locale_decode(message.parse_error()[0])
            if missing_description:
                error = "%s (%s)" % (missing_description, error)
            raise exceptions.ScannerError(error)
        elif message.type == gst.MESSAGE_EOS:
            return tags, mime, have_audio
        elif message.type == gst.MESSAGE_ASYNC_DONE:
            if message.src == pipeline:
                return tags, mime, have_audio
        elif message.type == gst.MESSAGE_TAG:
            taglist = message.parse_tag()
            # Note that this will only keep the last tag.
            tags.update(utils.convert_taglist(taglist))

        timeout -= clock.get_time() - start

    raise exceptions.ScannerError("Timeout after %dms" % timeout_ms)
开发者ID:tylerball,项目名称:mopidy,代码行数:49,代码来源:scan.py

示例3: test_can_decode_utf8_strings_with_french_content

    def test_can_decode_utf8_strings_with_french_content(self, mock):
        mock.return_value = 'UTF-8'

        result = locale_decode(
            b'[Errno 98] Adresse d\xc3\xa9j\xc3\xa0 utilis\xc3\xa9e')

        self.assertEqual('[Errno 98] Adresse d\xe9j\xe0 utilis\xe9e', result)
开发者ID:FabrizioCongia,项目名称:mopidy,代码行数:7,代码来源:test_encoding.py

示例4: __init__

    def __init__(self, config, core):
        super(MpdFrontend, self).__init__()

        hostname = network.format_hostname(config['mpd']['hostname'])
        self.hostname = hostname
        self.port = config['mpd']['port']
        self.zeroconf_name = config['mpd']['zeroconf']
        self.zeroconf_service = None

        try:
            network.Server(
                self.hostname, self.port,
                protocol=session.MpdSession,
                protocol_kwargs={
                    'config': config,
                    'core': core,
                },
                max_connections=config['mpd']['max_connections'],
                timeout=config['mpd']['connection_timeout'])
        except IOError as error:
            logger.error(
                'MPD server startup failed: %s',
                encoding.locale_decode(error))
            sys.exit(1)

        logger.info('MPD server running at [%s]:%s', self.hostname, self.port)
开发者ID:Shugyousha,项目名称:mopidy,代码行数:26,代码来源:actor.py

示例5: _collect

    def _collect(self):
        """Polls for messages to collect data."""
        start = time.time()
        timeout_s = self._timeout_ms / float(1000)
        tags = {}

        while time.time() - start < timeout_s:
            if not self._bus.have_pending():
                continue
            message = self._bus.pop()

            if message.type == gst.MESSAGE_ERROR:
                raise exceptions.ScannerError(
                    encoding.locale_decode(message.parse_error()[0]))
            elif message.type == gst.MESSAGE_EOS:
                return tags
            elif message.type == gst.MESSAGE_ASYNC_DONE:
                if message.src == self._pipe:
                    return tags
            elif message.type == gst.MESSAGE_TAG:
                # Taglists are not really dicts, hence the lack of .items() and
                # explicit .keys. We only keep the last tag for each key, as we
                # assume this is the best, some formats will produce multiple
                # taglists. Lastly we force everything to lists for conformity.
                taglist = message.parse_tag()
                for key in taglist.keys():
                    value = taglist[key]
                    if not isinstance(value, list):
                        value = [value]
                    tags[key] = value

        raise exceptions.ScannerError('Timeout after %dms' % self._timeout_ms)
开发者ID:AndroidMarv,项目名称:mopidy,代码行数:32,代码来源:scan.py

示例6: check_dirs_and_files

    def check_dirs_and_files(self):
        if not os.path.isdir(self.config['local']['media_dir']):
            logger.warning('Local media dir %s does not exist.' %
                           self.config['local']['media_dir'])

        try:
            path.get_or_create_dir(self.config['local']['playlists_dir'])
        except EnvironmentError as error:
            logger.warning(
                'Could not create local playlists dir: %s',
                encoding.locale_decode(error))

        try:
            path.get_or_create_file(self.config['local']['tag_cache_file'])
        except EnvironmentError as error:
            logger.warning(
                'Could not create empty tag cache file: %s',
                encoding.locale_decode(error))
开发者ID:Halfnhav,项目名称:mopidy,代码行数:18,代码来源:actor.py

示例7: _send_broadcast

def _send_broadcast(client, msg):
    # We could check for client.ws_connection, but we don't really
    # care why the broadcast failed, we just want the rest of them
    # to succeed, so catch everything.
    try:
        client.write_message(msg)
    except Exception as e:
        error_msg = encoding.locale_decode(e)
        logger.debug('Broadcast of WebSocket message to %s failed: %s',
                     client.request.remote_ip, error_msg)
开发者ID:TheNameIsNigel,项目名称:mopidy,代码行数:10,代码来源:handlers.py

示例8: __init__

    def __init__(self, frontend, serial_port, serial_bps):
        super(SerialMonoboxController, self).__init__()
        try:
            self.s = serial.Serial(serial_port, serial_bps, timeout=0.5)
        except Exception as error:
            raise exceptions.FrontendError('SMC serial connection failed: %s' %
                    encoding.locale_decode(error))

        self.frontend = frontend
        self.buffer = ''
开发者ID:oxullo,项目名称:mopidy-monobox,代码行数:10,代码来源:smc.py

示例9: send

 def send(self, data):
     """Send data to client, return any unsent data."""
     try:
         sent = self.sock.send(data)
         return data[sent:]
     except socket.error as e:
         if e.errno in (errno.EWOULDBLOCK, errno.EINTR):
             return data
         self.stop(
             'Unexpected client error: %s' % encoding.locale_decode(e))
         return b''
开发者ID:ArcherSys,项目名称:Peridot,代码行数:11,代码来源:network.py

示例10: check_dirs_and_files

def check_dirs_and_files(config):
    if not os.path.isdir(config['local']['media_dir']):
        logger.warning(
            'Local media dir %s does not exist.' %
            config['local']['media_dir'])

    try:
        path.get_or_create_dir(config['local']['data_dir'])
    except EnvironmentError as error:
        logger.warning(
            'Could not create local data dir: %s',
            encoding.locale_decode(error))

    # TODO: replace with data dir?
    try:
        path.get_or_create_dir(config['local']['playlists_dir'])
    except EnvironmentError as error:
        logger.warning(
            'Could not create local playlists dir: %s',
            encoding.locale_decode(error))
开发者ID:AndroidMarv,项目名称:mopidy,代码行数:20,代码来源:storage.py

示例11: test_can_decode_an_ioerror_with_french_content

    def test_can_decode_an_ioerror_with_french_content(self, mock):
        mock.return_value = 'UTF-8'

        error = IOError(98, b'Adresse d\xc3\xa9j\xc3\xa0 utilis\xc3\xa9e')
        result = locale_decode(error)
        expected = '[Errno 98] Adresse d\xe9j\xe0 utilis\xe9e'

        self.assertEqual(
            expected, result,
            '%r decoded to %r does not match expected %r' % (
                error, result, expected))
开发者ID:FabrizioCongia,项目名称:mopidy,代码行数:11,代码来源:test_encoding.py

示例12: try_ipv6_socket

def try_ipv6_socket():
    """Determine if system really supports IPv6"""
    if not socket.has_ipv6:
        return False
    try:
        socket.socket(socket.AF_INET6).close()
        return True
    except IOError as error:
        logger.debug(
            "Platform supports IPv6, but socket creation failed, " "disabling: %s", encoding.locale_decode(error)
        )
    return False
开发者ID:karlpilkington,项目名称:mopidy,代码行数:12,代码来源:network.py

示例13: __init__

    def __init__(self, config, audio):
        super(M3UBackend, self).__init__()

        self._config = config

        try:
            path.get_or_create_dir(config['m3u']['playlists_dir'])
        except EnvironmentError as error:
            logger.warning(
                'Could not create M3U playlists dir: %s',
                encoding.locale_decode(error))

        self.playlists = M3UPlaylistsProvider(backend=self)
        self.library = M3ULibraryProvider(backend=self)
开发者ID:ArcherSys,项目名称:Peridot,代码行数:14,代码来源:actor.py

示例14: _find_worker

def _find_worker(relative, follow, done, work, results, errors):
    """Worker thread for collecting stat() results.

    :param str relative: directory to make results relative to
    :param bool follow: if symlinks should be followed
    :param threading.Event done: event indicating that all work has been done
    :param queue.Queue work: queue of paths to process
    :param dict results: shared dictionary for storing all the stat() results
    :param dict errors: shared dictionary for storing any per path errors
    """
    while not done.is_set():
        try:
            entry, parents = work.get(block=False)
        except queue.Empty:
            continue

        if relative:
            path = os.path.relpath(entry, relative)
        else:
            path = entry

        try:
            if follow:
                st = os.stat(entry)
            else:
                st = os.lstat(entry)

            if (st.st_dev, st.st_ino) in parents:
                errors[path] = exceptions.FindError('Sym/hardlink loop found.')
                continue

            parents = parents + [(st.st_dev, st.st_ino)]
            if stat.S_ISDIR(st.st_mode):
                for e in os.listdir(entry):
                    work.put((os.path.join(entry, e), parents))
            elif stat.S_ISREG(st.st_mode):
                results[path] = st
            elif stat.S_ISLNK(st.st_mode):
                errors[path] = exceptions.FindError('Not following symlinks.')
            else:
                errors[path] = exceptions.FindError('Not a file or directory.')

        except OSError as e:
            errors[path] = exceptions.FindError(
                encoding.locale_decode(e.strerror), e.errno)
        finally:
            work.task_done()
开发者ID:ArcherSys,项目名称:Peridot,代码行数:47,代码来源:path.py

示例15: create_file_structures_and_config

def create_file_structures_and_config(args, extensions):
    path.get_or_create_dir(b'$XDG_DATA_DIR/mopidy')
    path.get_or_create_dir(b'$XDG_CONFIG_DIR/mopidy')

    # Initialize whatever the last config file is with defaults
    config_file = args.config_files[-1]
    if os.path.exists(path.expand_path(config_file)):
        return

    try:
        default = config_lib.format_initial(extensions)
        path.get_or_create_file(config_file, mkdir=False, content=default)
        logger.info('Initialized %s with default config', config_file)
    except IOError as error:
        logger.warning(
            'Unable to initialize %s with default config: %s',
            config_file, encoding.locale_decode(error))
开发者ID:ArcherSys,项目名称:Peridot,代码行数:17,代码来源:__main__.py


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