cheroot._compat
module¶
Compatibility code for using Cheroot with various versions of Python.
-
cheroot._compat.
assert_native
(n)¶ Check whether the input is of native
str
type.- Raises:
TypeError: in case of failed check
-
cheroot._compat.
bton
(b, encoding='ISO-8859-1')¶ Return the byte string as native string in the given encoding.
-
cheroot._compat.
extract_bytes
(mv)¶ Retrieve bytes out of the given input buffer.
- Parameters
mv (memoryview or bytes) – input
buffer()
- Returns
unwrapped bytes
- Return type
bytes
- Raises
ValueError – if the input is not one of
memoryview
/buffer()
orbytes
-
class
cheroot._compat.
memoryview
(object)¶ Bases:
object
Create a new memoryview object which references the given object.
-
c_contiguous
¶ A bool indicating whether the memory is C contiguous.
-
cast
(format, *, shape)¶ Cast a memoryview to a new format or shape.
-
contiguous
¶ A bool indicating whether the memory is contiguous.
-
f_contiguous
¶ A bool indicating whether the memory is Fortran contiguous.
-
format
¶ A string containing the format (in struct module style) for each element in the view.
-
hex
()¶ Return the data in the buffer as a str of hexadecimal numbers.
- sep
An optional single character or byte to separate hex bytes.
- bytes_per_sep
How many bytes between separators. Positive values count from the right, negative values count from the left.
Example: >>> value = memoryview(b’xb9x01xef’) >>> value.hex() ‘b901ef’ >>> value.hex(‘:’) ‘b9:01:ef’ >>> value.hex(‘:’, 2) ‘b9:01ef’ >>> value.hex(‘:’, -2) ‘b901:ef’
-
itemsize
¶ The size in bytes of each element of the memoryview.
-
nbytes
¶ The amount of space in bytes that the array would use in a contiguous representation.
-
ndim
¶ An integer indicating how many dimensions of a multi-dimensional array the memory represents.
-
obj
¶ The underlying object of the memoryview.
-
readonly
¶ A bool indicating whether the memory is read only.
-
release
()¶ Release the underlying buffer exposed by the memoryview object.
-
shape
¶ A tuple of ndim integers giving the shape of the memory as an N-dimensional array.
-
strides
¶ A tuple of ndim integers giving the size in bytes to access each element for each dimension of the array.
-
suboffsets
¶ A tuple of integers used internally for PIL-style arrays.
-
tobytes
(order=None)¶ Return the data in the buffer as a byte string. Order can be {‘C’, ‘F’, ‘A’}. When order is ‘C’ or ‘F’, the data of the original array is converted to C or Fortran order. For contiguous views, ‘A’ returns an exact copy of the physical memory. In particular, in-memory Fortran order is preserved. For non-contiguous views, the data is converted to C first. order=None is the same as order=’C’.
-
tolist
()¶ Return the data in the buffer as a list of elements.
-
toreadonly
()¶ Return a readonly version of the memoryview.
-
-
cheroot._compat.
ntob
(n, encoding='ISO-8859-1')¶ Return the native string as bytes in the given encoding.
-
cheroot._compat.
ntou
(n, encoding='ISO-8859-1')¶ Return the native string as Unicode with the given encoding.