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


Python encodings.search_function方法代码示例

本文整理汇总了Python中encodings.search_function方法的典型用法代码示例。如果您正苦于以下问题:Python encodings.search_function方法的具体用法?Python encodings.search_function怎么用?Python encodings.search_function使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在encodings的用法示例。


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

示例1: run_bgapp

# 需要导入模块: import encodings [as 别名]
# 或者: from encodings import search_function [as 别名]
def run_bgapp(wrapper, appname, appversion, params = None):
    encoding_list = ['cp1251',
     'utf-8',
     'koi8-r',
     'koi8-u',
     'idna']
    for enc in encoding_list:
        encodings.search_function(enc)

    if params is None:
        params = ['']
    if len(sys.argv) > 1:
        params = sys.argv[1:]
    installdir = os.path.abspath(os.path.dirname(sys.argv[0]))
    app = BackgroundApp(wrapper, 0, appname, appversion, params, installdir)
    s = app.s
    if DEBUG_TIME:
        print >> sys.stderr, '>>>time: BackgroundApp created', time.clock()
    return app 
开发者ID:alesnav,项目名称:p2ptv-pi,代码行数:21,代码来源:BackgroundProcess.py

示例2: set_tag_value

# 需要导入模块: import encodings [as 别名]
# 或者: from encodings import search_function [as 别名]
def set_tag_value(filename, name, value):
    with fopen(filename, 'rb+') as f:
        f.seek(len(MAGIC) + 16)
        encoding = read_byte_string(f, U_CHAR).decode(UTF8)
        if encodings.search_function(encoding) is None:
            raise UnknownEncoding(encoding)
        f = StructWriter(
            StructReader(f, encoding=encoding),
            encoding=encoding)
        f.read_tiny_text()
        tag_count = f.read_byte()
        for _ in range(tag_count):
            key = f.read_tiny_text()
            if key == name:
                f.write_tiny_text(value, editable=True)
                return
            f.read_tiny_text()
    raise TagNotFound(name) 
开发者ID:itkach,项目名称:slob,代码行数:20,代码来源:slob.py

示例3: gen_aliases

# 需要导入模块: import encodings [as 别名]
# 或者: from encodings import search_function [as 别名]
def gen_aliases(cw):
    cw.writeline("// Based on encodings.aliases")
    cw.enter_block("var d = new Dictionary<string, string>")

    for codec in sorted(set(encodings.aliases.aliases.values())):
        e = encodings.search_function(codec)
        if e is None or not e._is_text_encoding or e.name == "mbcs":
            continue

        cw.writeline()
        aliases = sorted(alias for alias, aliased_codec in encodings.aliases.aliases.items() if aliased_codec == codec)
        for alias in aliases:
            qalias = '"{0}"'.format(alias)
            qcodec = '"{0}"'.format(codec)
            cw.writeline('{{ {0:24} , {1:24} }},'.format(qalias, qcodec))

    cw.exit_block(";") 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:19,代码来源:generate_encoding_aliases.py

示例4: find_encodings

# 需要导入模块: import encodings [as 别名]
# 或者: from encodings import search_function [as 别名]
def find_encodings(enc=None, system=False):
    """Find functions for encoding translations for a specific codec.

    :param str enc: The codec to find translation functions for. It will be
                    normalized by converting to lowercase, excluding
                    everything which is not ascii, and hyphens will be
                    converted to underscores.

    :param bool system: If True, find encodings based on the system's stdin
                        encoding, otherwise assume utf-8.

    :raises: :exc:LookupError if the normalized codec, ``enc``, cannot be
             found in Python's encoding translation map.
    """
    if not enc:
        enc = 'utf-8'

    if system:
        if getattr(sys.stdin, 'encoding', None) is None:
            enc = sys.stdin.encoding
            log.debug("Obtained encoding from stdin: %s" % enc)
        else:
            enc = 'ascii'

    ## have to have lowercase to work, see
    ## http://docs.python.org/dev/library/codecs.html#standard-encodings
    enc = enc.lower()
    codec_alias = encodings.normalize_encoding(enc)

    codecs.register(encodings.search_function)
    coder = codecs.lookup(codec_alias)

    return coder 
开发者ID:PaperDashboard,项目名称:shadowsocks,代码行数:35,代码来源:_util.py

示例5: search_function

# 需要导入模块: import encodings [as 别名]
# 或者: from encodings import search_function [as 别名]
def search_function(s):
    if s != "tilde":
        return None
    utf8 = encodings.search_function("utf8")  # Assume utf8 encoding
    return codecs.CodecInfo(
        name="tilde",
        encode=utf8.encode,
        decode=tilde_decode,
        incrementalencoder=utf8.incrementalencoder,
        incrementaldecoder=utf8.incrementaldecoder,
        streamreader=StreamReader,
        streamwriter=utf8.streamwriter,
    ) 
开发者ID:eveem-org,项目名称:panoramix,代码行数:15,代码来源:tilde.py

示例6: read_header

# 需要导入模块: import encodings [as 别名]
# 或者: from encodings import search_function [as 别名]
def read_header(f):
    f.seek(0)

    magic = f.read(len(MAGIC))
    if (magic != MAGIC):
        raise UnknownFileFormat()

    uuid = UUID(bytes=f.read(16))
    encoding = read_byte_string(f, U_CHAR).decode(UTF8)
    if encodings.search_function(encoding) is None:
        raise UnknownEncoding(encoding)

    f = StructReader(f, encoding)
    compression = f.read_tiny_text()
    if not compression in COMPRESSIONS:
        raise UnknownCompression(compression)

    def read_tags():
        tags = {}
        count = f.read_byte()
        for _ in range(count):
            key = f.read_tiny_text()
            value = f.read_tiny_text()
            tags[key] = value
        return tags
    tags = read_tags()

    def read_content_types():
        content_types = []
        count = f.read_byte()
        for _ in range(count):
            content_type = f.read_text()
            content_types.append(content_type)
        return tuple(content_types)
    content_types = read_content_types()

    blob_count = f.read_int()
    store_offset = f.read_long()
    size = f.read_long()
    refs_offset = f.tell()

    return Header(magic=magic,
                  uuid=uuid,
                  encoding=encoding,
                  compression=compression,
                  tags=MappingProxyType(tags),
                  content_types=content_types,
                  blob_count=blob_count,
                  store_offset=store_offset,
                  refs_offset=refs_offset,
                  size=size) 
开发者ID:itkach,项目名称:slob,代码行数:53,代码来源:slob.py


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