微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Python encodings 模块-ascii() 实例源码

Python encodings 模块,ascii() 实例源码

我们从Python开源项目中,提取了以下20代码示例,用于说明如何使用encodings.ascii()

项目:pythonVSCode    作者:DonJayamanne    | 项目源码 | 文件源码
def read_string(conn):
    """ reads length of text to read,and then the text encoded in UTF-8,and returns the string"""
    strlen = read_int(conn)
    if not strlen:
        return ''
    res = to_bytes('')
    while len(res) < strlen:
        res = res + conn.recv(strlen - len(res))

    res = utf_8.decode(res)[0]
    if sys.version_info[0] == 2 and sys.platform != 'cli':
        # Py 2.x,we want an ASCII string if possible
        try:
            res = ascii.Codec.encode(res)[0]
        except UnicodeEncodeError:
            pass

    return res
项目:pythonVSCode    作者:DonJayamanne    | 项目源码 | 文件源码
def read_string(conn):
    """ reads length of text to read,we want an ASCII string if possible
        try:
            res = ascii.Codec.encode(res)[0]
        except UnicodeEncodeError:
            pass

    return res
项目:Intranet-Penetration    作者:yuxiaokui    | 项目源码 | 文件源码
def __init__(self, stream, fieldnames, encoding='utf-8', **kwds):
    """Initialzer.

    Args:
      stream: Stream to write to.
      fieldnames: Fieldnames to pass to the DictWriter.
      encoding: Desired encoding.
      kwds: Additional arguments to pass to the DictWriter.
    """

    writer = codecs.getwriter(encoding)



    if (writer is encodings.utf_8.StreamWriter or
        writer is encodings.ascii.StreamWriter or
        writer is encodings.latin_1.StreamWriter or
        writer is encodings.cp1252.StreamWriter):
      self.no_recoding = True
      self.encoder = codecs.getencoder(encoding)
      self.writer = csv.DictWriter(stream, **kwds)
    else:
      self.no_recoding = False
      self.encoder = codecs.getencoder('utf-8')
      self.queue = cStringIO.StringIO()
      self.writer = csv.DictWriter(self.queue, **kwds)
      self.stream = writer(stream)
项目:HomeAutomation    作者:gs2671    | 项目源码 | 文件源码
def read_string(conn):
    """ reads length of text to read,we want an ASCII string if possible
        try:
            res = ascii.Codec.encode(res)[0]
        except UnicodeEncodeError:
            pass

    return res
项目:xidian-sfweb    作者:Gear420    | 项目源码 | 文件源码
def read_string(conn):
    """ reads length of text to read,we want an ASCII string if possible
        try:
            res = ascii.Codec.encode(res)[0]
        except UnicodeEncodeError:
            pass

    return res
项目:skojjt    作者:martin-green    | 项目源码 | 文件源码
def read_string(conn):
    """ reads length of text to read,we want an ASCII string if possible
        try:
            res = ascii.Codec.encode(res)[0]
        except UnicodeEncodeError:
            pass

    return res
项目:DjangoWebProject    作者:wrkettlitz    | 项目源码 | 文件源码
def read_string(conn):
    """ reads length of text to read,we want an ASCII string if possible
        try:
            res = ascii.Codec.encode(res)[0]
        except UnicodeEncodeError:
            pass

    return res
项目:ApiRestPythonTest    作者:rvfvazquez    | 项目源码 | 文件源码
def read_string(conn):
    """ reads length of text to read,we want an ASCII string if possible
        try:
            res = ascii.Codec.encode(res)[0]
        except UnicodeEncodeError:
            pass

    return res
项目:pythonVSCode    作者:DonJayamanne    | 项目源码 | 文件源码
def to_bytes(cmd_str):
        return ascii.Codec.encode(cmd_str)[0]
项目:pythonVSCode    作者:DonJayamanne    | 项目源码 | 文件源码
def to_bytes(cmd_str):
        return ascii.Codec.encode(cmd_str)[0]
项目:filefinder2    作者:asmodehn    | 项目源码 | 文件源码
def source_to_unicode(txt, errors='replace', skip_encoding_cookie=True):
    """Converts a bytes string with python source code to unicode.
    Unicode strings are passed through unchanged. Byte strings are checked
    for the python source file encoding cookie to determine encoding.
    txt can be either a bytes buffer or a string containing the source
    code.
    """
    if isinstance(txt, six.text_type):
        return txt
    if isinstance(txt, six.binary_type):
        buffer = io.BytesIO(txt)
    else:
        buffer = txt
    try:
        encoding, _ = detect_encoding(buffer.readline)
    except SyntaxError:
        encoding = "ascii"
    buffer.seek(0)

    newline_decoder = io.IncrementalNewlineDecoder(None, True)

    text = io.TextIOWrapper(buffer, encoding, errors=errors, line_buffering=True)
    text.mode = 'r'
    if skip_encoding_cookie:
        return u"".join(strip_encoding_cookie(text))
    else:
        return text.read()
项目:HomeAutomation    作者:gs2671    | 项目源码 | 文件源码
def to_bytes(cmd_str):
        return ascii.Codec.encode(cmd_str)[0]
项目:xidian-sfweb    作者:Gear420    | 项目源码 | 文件源码
def to_bytes(cmd_str):
        return ascii.Codec.encode(cmd_str)[0]
项目:skojjt    作者:martin-green    | 项目源码 | 文件源码
def to_bytes(cmd_str):
        return ascii.Codec.encode(cmd_str)[0]
项目:DjangoWebProject    作者:wrkettlitz    | 项目源码 | 文件源码
def to_bytes(cmd_str):
        return ascii.Codec.encode(cmd_str)[0]
项目:ApiRestPythonTest    作者:rvfvazquez    | 项目源码 | 文件源码
def to_bytes(cmd_str):
        return ascii.Codec.encode(cmd_str)[0]
项目:MKFQ    作者:maojingios    | 项目源码 | 文件源码
def __init__(self, **kwds)
      self.stream = writer(stream)
项目:xxNet    作者:drzorm    | 项目源码 | 文件源码
def __init__(self, **kwds)
      self.stream = writer(stream)
项目:Deploy_XXNET_Server    作者:jzp820927    | 项目源码 | 文件源码
def __init__(self, **kwds)
      self.stream = writer(stream)
项目:Docker-XX-Net    作者:kuanghy    | 项目源码 | 文件源码
def __init__(self, **kwds)
      self.stream = writer(stream)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐