當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。