python类lookup()的实例源码

__init__.py 文件源码 项目:python- 作者: secondtonone1 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def _get_encoding(encoding_or_label):
    """
    Accept either an encoding object or label.

    :param encoding: An :class:`Encoding` object or a label string.
    :returns: An :class:`Encoding` object.
    :raises: :exc:`~exceptions.LookupError` for an unknown label.

    """
    if hasattr(encoding_or_label, 'codec_info'):
        return encoding_or_label

    encoding = lookup(encoding_or_label)
    if encoding is None:
        raise LookupError('Unknown encoding label: %r' % encoding_or_label)
    return encoding
__init__.py 文件源码 项目:my-first-blog 作者: AnkurBegining 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def _get_encoding(encoding_or_label):
    """
    Accept either an encoding object or label.

    :param encoding: An :class:`Encoding` object or a label string.
    :returns: An :class:`Encoding` object.
    :raises: :exc:`~exceptions.LookupError` for an unknown label.

    """
    if hasattr(encoding_or_label, 'codec_info'):
        return encoding_or_label

    encoding = lookup(encoding_or_label)
    if encoding is None:
        raise LookupError('Unknown encoding label: %r' % encoding_or_label)
    return encoding
codecs.py 文件源码 项目:otRebuilder 作者: Pal3love 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def search_function(name):
    name = encodings.normalize_encoding(name) # Rather undocumented...
    if name in _extended_encodings:
        if name not in _cache:
            base_encoding, mapping = _extended_encodings[name]
            assert(name[-4:] == "_ttx")
            # Python 2 didn't have any of the encodings that we are implementing
            # in this file.  Python 3 added aliases for the East Asian ones, mapping
            # them "temporarily" to the same base encoding as us, with a comment
            # suggesting that full implementation will appear some time later.
            # As such, try the Python version of the x_mac_... first, if that is found,
            # use *that* as our base encoding.  This would make our encoding upgrade
            # to the full encoding when and if Python finally implements that.
            # http://bugs.python.org/issue24041
            base_encodings = [name[:-4], base_encoding]
            for base_encoding in base_encodings:
                try:
                    codecs.lookup(base_encoding)
                except LookupError:
                    continue
                _cache[name] = ExtendCodec(name, base_encoding, mapping)
                break
        return _cache[name].info

    return None
dammit.py 文件源码 项目:Gank-Alfred-Workflow 作者: hujiaweibujidao 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def _populate_class_variables():
        lookup = {}
        reverse_lookup = {}
        characters_for_re = []
        for codepoint, name in list(codepoint2name.items()):
            character = unichr(codepoint)
            if codepoint != 34:
                # There's no point in turning the quotation mark into
                # ", unless it happens within an attribute value, which
                # is handled elsewhere.
                characters_for_re.append(character)
                lookup[character] = name
            # But we do want to turn " into the quotation mark.
            reverse_lookup[name] = character
        re_definition = "[%s]" % "".join(characters_for_re)
        return lookup, reverse_lookup, re.compile(re_definition)
dammit.py 文件源码 项目:Projects 作者: it2school 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def _populate_class_variables():
        lookup = {}
        reverse_lookup = {}
        characters_for_re = []
        for codepoint, name in list(codepoint2name.items()):
            character = chr(codepoint)
            if codepoint != 34:
                # There's no point in turning the quotation mark into
                # ", unless it happens within an attribute value, which
                # is handled elsewhere.
                characters_for_re.append(character)
                lookup[character] = name
            # But we do want to turn " into the quotation mark.
            reverse_lookup[name] = character
        re_definition = "[%s]" % "".join(characters_for_re)
        return lookup, reverse_lookup, re.compile(re_definition)
__init__.py 文件源码 项目:pip-update-requirements 作者: alanhamlett 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def _get_encoding(encoding_or_label):
    """
    Accept either an encoding object or label.

    :param encoding: An :class:`Encoding` object or a label string.
    :returns: An :class:`Encoding` object.
    :raises: :exc:`~exceptions.LookupError` for an unknown label.

    """
    if hasattr(encoding_or_label, 'codec_info'):
        return encoding_or_label

    encoding = lookup(encoding_or_label)
    if encoding is None:
        raise LookupError('Unknown encoding label: %r' % encoding_or_label)
    return encoding
dammit.py 文件源码 项目:TACTIC-Handler 作者: listyque 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def _populate_class_variables():
        lookup = {}
        reverse_lookup = {}
        characters_for_re = []
        for codepoint, name in list(codepoint2name.items()):
            character = unichr(codepoint)
            if codepoint != 34:
                # There's no point in turning the quotation mark into
                # ", unless it happens within an attribute value, which
                # is handled elsewhere.
                characters_for_re.append(character)
                lookup[character] = name
            # But we do want to turn " into the quotation mark.
            reverse_lookup[name] = character
        re_definition = "[%s]" % "".join(characters_for_re)
        return lookup, reverse_lookup, re.compile(re_definition)
__init__.py 文件源码 项目:jira_worklog_scanner 作者: pgarneau 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _get_encoding(encoding_or_label):
    """
    Accept either an encoding object or label.

    :param encoding: An :class:`Encoding` object or a label string.
    :returns: An :class:`Encoding` object.
    :raises: :exc:`~exceptions.LookupError` for an unknown label.

    """
    if hasattr(encoding_or_label, 'codec_info'):
        return encoding_or_label

    encoding = lookup(encoding_or_label)
    if encoding is None:
        raise LookupError('Unknown encoding label: %r' % encoding_or_label)
    return encoding
stream.py 文件源码 项目:Qkou_kit 作者: pddg 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def get_news(id):
    sys.stdout = codecs.lookup('utf_8')[-1](sys.stdout)
    try:
        news = id_news(id)
    except Exception as e:
        log.exception(e)
    if news is not False:
        if news is not 0:
            try:
                update = news.up_date.decode('utf-8')
                detail = news.detail.decode('utf-8')
                if len(news.link) is not 0:
                    link_ = news.link.decode('utf-8')
                    return u"???:%s\n??:%s\n???:%s" % (update, detail, link_)
                else:
                    return u"???: %s\n??: %s" % (update, detail)
            except Exception as e:
                log.exception(e)
        else:
            return u"?????????????????????"

    else:
        return u"DB????????????????????"
stream.py 文件源码 项目:Qkou_kit 作者: pddg 项目源码 文件源码 阅读 44 收藏 0 点赞 0 评论 0
def get_info(id):
    sys.stdout = codecs.lookup('utf_8')[-1](sys.stdout)
    try:
        info = id_info(id)
    except Exception as e:
        log.exception(e)
    if info is not False:
        if info is not 0:
            try:
                subject = info.subject.decode('utf-8')
                teacher = info.teacher.decode('utf-8')
                week = info.week.decode('utf-8')
                period = info.period.decode('utf-8')
                detail = info.detail.decode('utf-8')
                return u"????%s\n????%s\n???%s, %s\n???%s" % (subject, teacher, week, period, detail)
            except Exception as e:
                log.exception(e)
        else:
            return u"?????????????????????????"

    else:
        return u"DB????????????????????"
dammit.py 文件源码 项目:UPBGE-CommunityAddon 作者: elmeunick9 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _populate_class_variables():
        lookup = {}
        reverse_lookup = {}
        characters_for_re = []
        for codepoint, name in list(codepoint2name.items()):
            character = chr(codepoint)
            if codepoint != 34:
                # There's no point in turning the quotation mark into
                # ", unless it happens within an attribute value, which
                # is handled elsewhere.
                characters_for_re.append(character)
                lookup[character] = name
            # But we do want to turn " into the quotation mark.
            reverse_lookup[name] = character
        re_definition = "[%s]" % "".join(characters_for_re)
        return lookup, reverse_lookup, re.compile(re_definition)
dammit.py 文件源码 项目:llk 作者: Tycx2ry 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _populate_class_variables():
        lookup = {}
        reverse_lookup = {}
        characters_for_re = []
        for codepoint, name in list(codepoint2name.items()):
            character = unichr(codepoint)
            if codepoint != 34:
                # There's no point in turning the quotation mark into
                # ", unless it happens within an attribute value, which
                # is handled elsewhere.
                characters_for_re.append(character)
                lookup[character] = name
            # But we do want to turn " into the quotation mark.
            reverse_lookup[name] = character
        re_definition = "[%s]" % "".join(characters_for_re)
        return lookup, reverse_lookup, re.compile(re_definition)
visualstudio_py_repl.py 文件源码 项目:pythonVSCode 作者: DonJayamanne 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def execute_process_work_item(self):
        try:
            from subprocess import Popen, PIPE, STDOUT
            import codecs
            out_codec = codecs.lookup(sys.stdout.encoding)

            proc = Popen(
                '"%s" %s' % (self.current_code, self.current_args),
                stdout=PIPE,
                stderr=STDOUT,
                bufsize=0,
            )

            for line in proc.stdout:
                print(out_codec.decode(line, 'replace')[0].rstrip('\r\n'))
        except Exception:
            traceback.print_exc()
visualstudio_py_repl.py 文件源码 项目:pythonVSCode 作者: DonJayamanne 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def execute_process_work_item(self):
        try:
            from subprocess import Popen, PIPE, STDOUT
            import codecs
            out_codec = codecs.lookup(sys.stdout.encoding)

            proc = Popen(
                '"%s" %s' % (self.current_code, self.current_args),
                stdout=PIPE,
                stderr=STDOUT,
                bufsize=0,
            )

            for line in proc.stdout:
                print(out_codec.decode(line, 'replace')[0].rstrip('\r\n'))
        except Exception:
            traceback.print_exc()
__init__.py 文件源码 项目:Sci-Finder 作者: snverse 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def _get_encoding(encoding_or_label):
    """
    Accept either an encoding object or label.

    :param encoding: An :class:`Encoding` object or a label string.
    :returns: An :class:`Encoding` object.
    :raises: :exc:`~exceptions.LookupError` for an unknown label.

    """
    if hasattr(encoding_or_label, 'codec_info'):
        return encoding_or_label

    encoding = lookup(encoding_or_label)
    if encoding is None:
        raise LookupError('Unknown encoding label: %r' % encoding_or_label)
    return encoding
__init__.py 文件源码 项目:Sci-Finder 作者: snverse 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def _get_encoding(encoding_or_label):
    """
    Accept either an encoding object or label.

    :param encoding: An :class:`Encoding` object or a label string.
    :returns: An :class:`Encoding` object.
    :raises: :exc:`~exceptions.LookupError` for an unknown label.

    """
    if hasattr(encoding_or_label, 'codec_info'):
        return encoding_or_label

    encoding = lookup(encoding_or_label)
    if encoding is None:
        raise LookupError('Unknown encoding label: %r' % encoding_or_label)
    return encoding
dammit.py 文件源码 项目:harbour-sailfinder 作者: DylanVanAssche 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def _populate_class_variables():
        lookup = {}
        reverse_lookup = {}
        characters_for_re = []
        for codepoint, name in list(codepoint2name.items()):
            character = chr(codepoint)
            if codepoint != 34:
                # There's no point in turning the quotation mark into
                # ", unless it happens within an attribute value, which
                # is handled elsewhere.
                characters_for_re.append(character)
                lookup[character] = name
            # But we do want to turn " into the quotation mark.
            reverse_lookup[name] = character
        re_definition = "[%s]" % "".join(characters_for_re)
        return lookup, reverse_lookup, re.compile(re_definition)
dammit.py 文件源码 项目:harbour-sailfinder 作者: DylanVanAssche 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _populate_class_variables():
        lookup = {}
        reverse_lookup = {}
        characters_for_re = []
        for codepoint, name in list(codepoint2name.items()):
            character = chr(codepoint)
            if codepoint != 34:
                # There's no point in turning the quotation mark into
                # ", unless it happens within an attribute value, which
                # is handled elsewhere.
                characters_for_re.append(character)
                lookup[character] = name
            # But we do want to turn " into the quotation mark.
            reverse_lookup[name] = character
        re_definition = "[%s]" % "".join(characters_for_re)
        return lookup, reverse_lookup, re.compile(re_definition)
xsl_convert.py 文件源码 项目:rtf2xml 作者: paulhtremblay 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __transform_4suite(self, file, xsl_file, output, params):

        import codecs
        from Ft.Xml import InputSource
        from Ft.Xml.Xslt.Processor import Processor

        document = InputSource.DefaultFactory.fromUri(file)
        stylesheet = InputSource.DefaultFactory.fromUri(xsl_file)
            # there's also a fromString() method

        processor = Processor()
        processor.appendStylesheet(stylesheet)  
        result = processor.run(document, topLevelParams=params)
        (utf8_encode, utf8_decode, utf8_reader, utf8_writer) = codecs.lookup("utf-8")
        write_obj = utf8_writer(open(output, 'w'))
        write_obj.write(result)
        write_obj.close()
        return result, ''
output.py 文件源码 项目:rtf2xml 作者: paulhtremblay 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def __output_xml(self, in_file, out_file):
        """

        output the ill-formed xml file

        """

        (utf8_encode, utf8_decode, utf8_reader, utf8_writer) = codecs.lookup("utf-8")
        write_obj = utf8_writer(open(out_file, 'w'))
        write_obj = open(out_file, 'w')
        read_obj = utf8_writer(open(in_file, 'r'))
        read_obj = open(in_file, 'r')
        line = 1
        while line:
            line = read_obj.readline()
            if isinstance(line, type(u"")):
                line = line.encode("utf-8")
            write_obj.write(line)

        read_obj.close()
        write_obj.close()
dammit.py 文件源码 项目:B.E.N.J.I. 作者: the-ethan-hunt 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _populate_class_variables():
        lookup = {}
        reverse_lookup = {}
        characters_for_re = []
        for codepoint, name in list(codepoint2name.items()):
            character = chr(codepoint)
            if codepoint != 34:
                # There's no point in turning the quotation mark into
                # ", unless it happens within an attribute value, which
                # is handled elsewhere.
                characters_for_re.append(character)
                lookup[character] = name
            # But we do want to turn " into the quotation mark.
            reverse_lookup[name] = character
        re_definition = "[%s]" % "".join(characters_for_re)
        return lookup, reverse_lookup, re.compile(re_definition)
__init__.py 文件源码 项目:ascii-art-py 作者: blinglnav 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _get_encoding(encoding_or_label):
    """
    Accept either an encoding object or label.

    :param encoding: An :class:`Encoding` object or a label string.
    :returns: An :class:`Encoding` object.
    :raises: :exc:`~exceptions.LookupError` for an unknown label.

    """
    if hasattr(encoding_or_label, 'codec_info'):
        return encoding_or_label

    encoding = lookup(encoding_or_label)
    if encoding is None:
        raise LookupError('Unknown encoding label: %r' % encoding_or_label)
    return encoding
__init__.py 文件源码 项目:ivaochdoc 作者: ivaoch 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def _get_encoding(encoding_or_label):
    """
    Accept either an encoding object or label.

    :param encoding: An :class:`Encoding` object or a label string.
    :returns: An :class:`Encoding` object.
    :raises: :exc:`~exceptions.LookupError` for an unknown label.

    """
    if hasattr(encoding_or_label, 'codec_info'):
        return encoding_or_label

    encoding = lookup(encoding_or_label)
    if encoding is None:
        raise LookupError('Unknown encoding label: %r' % encoding_or_label)
    return encoding
__init__.py 文件源码 项目:aws-cfn-plex 作者: lordmuffin 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _get_encoding(encoding_or_label):
    """
    Accept either an encoding object or label.

    :param encoding: An :class:`Encoding` object or a label string.
    :returns: An :class:`Encoding` object.
    :raises: :exc:`~exceptions.LookupError` for an unknown label.

    """
    if hasattr(encoding_or_label, 'codec_info'):
        return encoding_or_label

    encoding = lookup(encoding_or_label)
    if encoding is None:
        raise LookupError('Unknown encoding label: %r' % encoding_or_label)
    return encoding
__init__.py 文件源码 项目:django 作者: alexsukhrin 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _get_encoding(encoding_or_label):
    """
    Accept either an encoding object or label.

    :param encoding: An :class:`Encoding` object or a label string.
    :returns: An :class:`Encoding` object.
    :raises: :exc:`~exceptions.LookupError` for an unknown label.

    """
    if hasattr(encoding_or_label, 'codec_info'):
        return encoding_or_label

    encoding = lookup(encoding_or_label)
    if encoding is None:
        raise LookupError('Unknown encoding label: %r' % encoding_or_label)
    return encoding
__init__.py 文件源码 项目:RPoint 作者: george17-meet 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def _get_encoding(encoding_or_label):
    """
    Accept either an encoding object or label.

    :param encoding: An :class:`Encoding` object or a label string.
    :returns: An :class:`Encoding` object.
    :raises: :exc:`~exceptions.LookupError` for an unknown label.

    """
    if hasattr(encoding_or_label, 'codec_info'):
        return encoding_or_label

    encoding = lookup(encoding_or_label)
    if encoding is None:
        raise LookupError('Unknown encoding label: %r' % encoding_or_label)
    return encoding
dammit.py 文件源码 项目:Taigabot 作者: FrozenPigs 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def _populate_class_variables():
        lookup = {}
        reverse_lookup = {}
        characters_for_re = []
        for codepoint, name in list(codepoint2name.items()):
            character = unichr(codepoint)
            if codepoint != 34:
                # There's no point in turning the quotation mark into
                # ", unless it happens within an attribute value, which
                # is handled elsewhere.
                characters_for_re.append(character)
                lookup[character] = name
            # But we do want to turn " into the quotation mark.
            reverse_lookup[name] = character
        re_definition = "[%s]" % "".join(characters_for_re)
        return lookup, reverse_lookup, re.compile(re_definition)
__init__.py 文件源码 项目:AshsSDK 作者: thehappydinoa 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def _get_encoding(encoding_or_label):
    """
    Accept either an encoding object or label.

    :param encoding: An :class:`Encoding` object or a label string.
    :returns: An :class:`Encoding` object.
    :raises: :exc:`~exceptions.LookupError` for an unknown label.

    """
    if hasattr(encoding_or_label, 'codec_info'):
        return encoding_or_label

    encoding = lookup(encoding_or_label)
    if encoding is None:
        raise LookupError('Unknown encoding label: %r' % encoding_or_label)
    return encoding
__init__.py 文件源码 项目:habilitacion 作者: GabrielBD 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def _get_encoding(encoding_or_label):
    """
    Accept either an encoding object or label.

    :param encoding: An :class:`Encoding` object or a label string.
    :returns: An :class:`Encoding` object.
    :raises: :exc:`~exceptions.LookupError` for an unknown label.

    """
    if hasattr(encoding_or_label, 'codec_info'):
        return encoding_or_label

    encoding = lookup(encoding_or_label)
    if encoding is None:
        raise LookupError('Unknown encoding label: %r' % encoding_or_label)
    return encoding
streams.py 文件源码 项目:Intranet-Penetration 作者: yuxiaokui 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def __init__(self, file, encoding=None):
        """
        @param file A file-like object holding your input. Only the read()
           method must be implemented.

        @param encoding If you set the optional encoding argument, then the
           data will be decoded on the fly.

        """

        if encoding is not None:
            # wrap input in a decoding reader
            reader = codecs.lookup(encoding)[2]
            file = reader(file)

        data = file.read()

        ANTLRStringStream.__init__(self, data)


# I guess the ANTLR prefix exists only to avoid a name clash with some Java
# mumbojumbo. A plain "StringStream" looks better to me, which should be
# the preferred name in Python.


问题


面经


文章

微信
公众号

扫码关注公众号