當前位置: 首頁>>代碼示例>>Python>>正文


Python builtins.bytes方法代碼示例

本文整理匯總了Python中future.builtins.bytes方法的典型用法代碼示例。如果您正苦於以下問題:Python builtins.bytes方法的具體用法?Python builtins.bytes怎麽用?Python builtins.bytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在future.builtins的用法示例。


在下文中一共展示了builtins.bytes方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: decode

# 需要導入模塊: from future import builtins [as 別名]
# 或者: from future.builtins import bytes [as 別名]
def decode(string):
    """Decode a raw base64 string, returning a bytes object.

    This function does not parse a full MIME header value encoded with
    base64 (like =?iso-8895-1?b?bmloISBuaWgh?=) -- please use the high
    level email.header class for that functionality.
    """
    if not string:
        return bytes()
    elif isinstance(string, str):
        return a2b_base64(string.encode('raw-unicode-escape'))
    else:
        return a2b_base64(string)


# For convenience and backwards compatibility w/ standard base64 module 
開發者ID:Soft8Soft,項目名稱:verge3d-blender-addon,代碼行數:18,代碼來源:base64mime.py

示例2: parse_headers

# 需要導入模塊: from future import builtins [as 別名]
# 或者: from future.builtins import bytes [as 別名]
def parse_headers(fp, _class=HTTPMessage):
    """Parses only RFC2822 headers from a file pointer.

    email Parser wants to see strings rather than bytes.
    But a TextIOWrapper around self.rfile would buffer too many bytes
    from the stream, bytes which we later need to read as bytes.
    So we read the correct bytes here, as bytes, for email Parser
    to parse.

    """
    headers = []
    while True:
        line = fp.readline(_MAXLINE + 1)
        if len(line) > _MAXLINE:
            raise LineTooLong("header line")
        headers.append(line)
        if len(headers) > _MAXHEADERS:
            raise HTTPException("got more than %d headers" % _MAXHEADERS)
        if line in (b'\r\n', b'\n', b''):
            break
    hstring = bytes(b'').join(headers).decode('iso-8859-1')
    return email_parser.Parser(_class=_class).parsestr(hstring) 
開發者ID:Soft8Soft,項目名稱:verge3d-blender-addon,代碼行數:24,代碼來源:client.py

示例3: _readall_chunked

# 需要導入模塊: from future import builtins [as 別名]
# 或者: from future.builtins import bytes [as 別名]
def _readall_chunked(self):
        assert self.chunked != _UNKNOWN
        chunk_left = self.chunk_left
        value = []
        while True:
            if chunk_left is None:
                try:
                    chunk_left = self._read_next_chunk_size()
                    if chunk_left == 0:
                        break
                except ValueError:
                    raise IncompleteRead(bytes(b'').join(value))
            value.append(self._safe_read(chunk_left))

            # we read the whole chunk, get another
            self._safe_read(2)      # toss the CRLF at the end of the chunk
            chunk_left = None

        self._read_and_discard_trailer()

        # we read everything; close the "file"
        self._close_conn()

        return bytes(b'').join(value) 
開發者ID:Soft8Soft,項目名稱:verge3d-blender-addon,代碼行數:26,代碼來源:client.py

示例4: _safe_read

# 需要導入模塊: from future import builtins [as 別名]
# 或者: from future.builtins import bytes [as 別名]
def _safe_read(self, amt):
        """Read the number of bytes requested, compensating for partial reads.

        Normally, we have a blocking socket, but a read() can be interrupted
        by a signal (resulting in a partial read).

        Note that we cannot distinguish between EOF and an interrupt when zero
        bytes have been read. IncompleteRead() will be raised in this
        situation.

        This function should be used when <amt> bytes "should" be present for
        reading. If the bytes are truly not available (due to EOF), then the
        IncompleteRead exception can be used to detect the problem.
        """
        s = []
        while amt > 0:
            chunk = self.fp.read(min(amt, MAXAMOUNT))
            if not chunk:
                raise IncompleteRead(bytes(b'').join(s), amt)
            s.append(chunk)
            amt -= len(chunk)
        return bytes(b"").join(s) 
開發者ID:Soft8Soft,項目名稱:verge3d-blender-addon,代碼行數:24,代碼來源:client.py

示例5: _send_output

# 需要導入模塊: from future import builtins [as 別名]
# 或者: from future.builtins import bytes [as 別名]
def _send_output(self, message_body=None):
        """Send the currently buffered request and clear the buffer.

        Appends an extra \\r\\n to the buffer.
        A message_body may be specified, to be appended to the request.
        """
        self._buffer.extend((bytes(b""), bytes(b"")))
        msg = bytes(b"\r\n").join(self._buffer)
        del self._buffer[:]
        # If msg and message_body are sent in a single send() call,
        # it will avoid performance problems caused by the interaction
        # between delayed ack and the Nagle algorithm.
        if isinstance(message_body, bytes):
            msg += message_body
            message_body = None
        self.send(msg)
        if message_body is not None:
            # message_body was not a string (i.e. it is a file), and
            # we must run the risk of Nagle.
            self.send(message_body) 
開發者ID:Soft8Soft,項目名稱:verge3d-blender-addon,代碼行數:22,代碼來源:client.py

示例6: __new__

# 需要導入模塊: from future import builtins [as 別名]
# 或者: from future.builtins import bytes [as 別名]
def __new__(cls, year, month=None, day=None):
        """Constructor.

        Arguments:

        year, month, day (required, base 1)
        """
        if (isinstance(year, bytes) and len(year) == 4 and
            1 <= year[2] <= 12 and month is None):  # Month is sane
            # Pickle support
            self = object.__new__(cls)
            self.__setstate(year)
            return self
        _check_date_fields(year, month, day)
        self = object.__new__(cls)
        self._year = year
        self._month = month
        self._day = day
        return self

    # Additional constructors 
開發者ID:Soft8Soft,項目名稱:verge3d-blender-addon,代碼行數:23,代碼來源:datetime.py

示例7: header_length

# 需要導入模塊: from future import builtins [as 別名]
# 或者: from future.builtins import bytes [as 別名]
def header_length(bytearray):
    """Return the length of s when it is encoded with base64."""
    groups_of_3, leftover = divmod(len(bytearray), 3)
    # 4 bytes out for each 3 bytes (or nonzero fraction thereof) in.
    n = groups_of_3 * 4
    if leftover:
        n += 4
    return n 
開發者ID:Soft8Soft,項目名稱:verge3d-blender-addon,代碼行數:10,代碼來源:base64mime.py

示例8: header_length

# 需要導入模塊: from future import builtins [as 別名]
# 或者: from future.builtins import bytes [as 別名]
def header_length(bytearray):
    """Return a header quoted-printable encoding length.

    Note that this does not include any RFC 2047 chrome added by
    `header_encode()`.

    :param bytearray: An array of bytes (a.k.a. octets).
    :return: The length in bytes of the byte array when it is encoded with
        quoted-printable for headers.
    """
    return sum(len(_QUOPRI_HEADER_MAP[octet]) for octet in bytearray) 
開發者ID:Soft8Soft,項目名稱:verge3d-blender-addon,代碼行數:13,代碼來源:quoprimime.py

示例9: body_length

# 需要導入模塊: from future import builtins [as 別名]
# 或者: from future.builtins import bytes [as 別名]
def body_length(bytearray):
    """Return a body quoted-printable encoding length.

    :param bytearray: An array of bytes (a.k.a. octets).
    :return: The length in bytes of the byte array when it is encoded with
        quoted-printable for bodies.
    """
    return sum(len(_QUOPRI_BODY_MAP[octet]) for octet in bytearray) 
開發者ID:Soft8Soft,項目名稱:verge3d-blender-addon,代碼行數:10,代碼來源:quoprimime.py

示例10: encode_q

# 需要導入模塊: from future import builtins [as 別名]
# 或者: from future.builtins import bytes [as 別名]
def encode_q(bstring):
    return str(''.join(_q_byte_map[x] for x in bytes(bstring))) 
開發者ID:Soft8Soft,項目名稱:verge3d-blender-addon,代碼行數:4,代碼來源:_encoded_words.py

示例11: len_q

# 需要導入模塊: from future import builtins [as 別名]
# 或者: from future.builtins import bytes [as 別名]
def len_q(bstring):
    return sum(len(_q_byte_map[x]) for x in bytes(bstring))


#
# Base64
# 
開發者ID:Soft8Soft,項目名稱:verge3d-blender-addon,代碼行數:9,代碼來源:_encoded_words.py

示例12: len_b

# 需要導入模塊: from future import builtins [as 別名]
# 或者: from future.builtins import bytes [as 別名]
def len_b(bstring):
    groups_of_3, leftover = divmod(len(bstring), 3)
    # 4 bytes out for each 3 bytes (or nonzero fraction thereof) in.
    return groups_of_3 * 4 + (4 if leftover else 0) 
開發者ID:Soft8Soft,項目名稱:verge3d-blender-addon,代碼行數:6,代碼來源:_encoded_words.py

示例13: decode

# 需要導入模塊: from future import builtins [as 別名]
# 或者: from future.builtins import bytes [as 別名]
def decode(ew):
    """Decode encoded word and return (string, charset, lang, defects) tuple.

    An RFC 2047/2243 encoded word has the form:

        =?charset*lang?cte?encoded_string?=

    where '*lang' may be omitted but the other parts may not be.

    This function expects exactly such a string (that is, it does not check the
    syntax and may raise errors if the string is not well formed), and returns
    the encoded_string decoded first from its Content Transfer Encoding and
    then from the resulting bytes into unicode using the specified charset.  If
    the cte-decoded string does not successfully decode using the specified
    character set, a defect is added to the defects list and the unknown octets
    are replaced by the unicode 'unknown' character \uFDFF.

    The specified charset and language are returned.  The default for language,
    which is rarely if ever encountered, is the empty string.

    """
    _, charset, cte, cte_string, _ = str(ew).split('?')
    charset, _, lang = charset.partition('*')
    cte = cte.lower()
    # Recover the original bytes and do CTE decoding.
    bstring = cte_string.encode('ascii', 'surrogateescape')
    bstring, defects = _cte_decoders[cte](bstring)
    # Turn the CTE decoded bytes into unicode.
    try:
        string = bstring.decode(charset)
    except UnicodeError:
        defects.append(errors.UndecodableBytesDefect("Encoded word "
            "contains bytes not decodable using {} charset".format(charset)))
        string = bstring.decode(charset, 'surrogateescape')
    except LookupError:
        string = bstring.decode('ascii', 'surrogateescape')
        if charset.lower() != 'unknown-8bit':
            defects.append(errors.CharsetError("Unknown charset {} "
                "in encoded word; decoded as unknown bytes".format(charset)))
    return string, charset, lang, defects 
開發者ID:Soft8Soft,項目名稱:verge3d-blender-addon,代碼行數:42,代碼來源:_encoded_words.py

示例14: _sanitize

# 需要導入模塊: from future import builtins [as 別名]
# 或者: from future.builtins import bytes [as 別名]
def _sanitize(string):
    # Turn any escaped bytes into unicode 'unknown' char.
    original_bytes = string.encode('ascii', 'surrogateescape')
    return original_bytes.decode('ascii', 'replace')


# Helpers 
開發者ID:Soft8Soft,項目名稱:verge3d-blender-addon,代碼行數:9,代碼來源:utils.py

示例15: __init__

# 需要導入模塊: from future import builtins [as 別名]
# 或者: from future.builtins import bytes [as 別名]
def __init__(self, sock, debuglevel=0, strict=_strict_sentinel, method=None, url=None):
        # If the response includes a content-length header, we need to
        # make sure that the client doesn't read more than the
        # specified number of bytes.  If it does, it will block until
        # the server times out and closes the connection.  This will
        # happen if a self.fp.read() is done (without a size) whether
        # self.fp is buffered or not.  So, no self.fp.read() by
        # clients unless they know what they are doing.
        self.fp = sock.makefile("rb")
        self.debuglevel = debuglevel
        if strict is not _strict_sentinel:
            warnings.warn("the 'strict' argument isn't supported anymore; "
                "http.client now always assumes HTTP/1.x compliant servers.",
                DeprecationWarning, 2)
        self._method = method

        # The HTTPResponse object is returned via urllib.  The clients
        # of http and urllib expect different attributes for the
        # headers.  headers is used here and supports urllib.  msg is
        # provided as a backwards compatibility layer for http
        # clients.

        self.headers = self.msg = None

        # from the Status-Line of the response
        self.version = _UNKNOWN # HTTP-Version
        self.status = _UNKNOWN  # Status-Code
        self.reason = _UNKNOWN  # Reason-Phrase

        self.chunked = _UNKNOWN         # is "chunked" being used?
        self.chunk_left = _UNKNOWN      # bytes left to read in current chunk
        self.length = _UNKNOWN          # number of bytes left in response
        self.will_close = _UNKNOWN      # conn will close at end of response 
開發者ID:Soft8Soft,項目名稱:verge3d-blender-addon,代碼行數:35,代碼來源:client.py


注:本文中的future.builtins.bytes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。