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)

相关文章

Python setuptools.dep_util 模块,newer_pairwise_group() ...
Python chainer.utils.type_check 模块,eval() 实例源码 我...
Python chainer.utils.type_check 模块,prod() 实例源码 我...
Python chainer.utils.type_check 模块,expect() 实例源码 ...
Python multiprocessing.managers 模块,BaseProxy() 实例源...
Python multiprocessing.managers 模块,RemoteError() 实例...