View393¶
Some helper functions to inspect str
objects in Python 3.3 and later.
Installation¶
$ pip install view393
Description¶
-
view393.
view
(unicode data, *, bool chars=False)¶ Returns a memoryview of the input string.
Parameters: Returns: A contiguous, readonly view on the string in native byte-order.
Return type:
-
view393.
utf8
(unicode data)¶ Returns a memoryview of the UTF-8 representation of the input string.
Calling this function multiple times will return different memoryview object, but the observed buffer is the same, possibly reducing overhead compared to
str.encode("UTF-8")
which generates unrelatedbytes
objects.Parameters: data (str) – String to observe. Returns: A contiguous, readonly view on the string encoded as UTF-8. Return type: memoryview
-
view393.
kind
(unicode data)¶ Returns the “kind” of the input string.
Parameters: data (str) – String to query. Returns: E.g. Kind.ASCII
if theall(ord(c) <= 0x7f for c in data)
.Return type: view393.Kind
-
class
view393.
Kind
¶ A enum to describe the “kind” of an
str()
.Enum members:
- ASCII: the string only contains US-ASCII data. (This includes the empty string.)the string only contains US-ASCII data. (This includes the empty string.)
- UCS1: the string contains some characters that are not representable in ASCII, but all characters are in Latin-1.
- UCS2: the string contains some characters that are not representable in Latin-1, but all characters are in the Basic Multilingual Plane.
- UCS4: the string contains some characters outside the Basic Multilingual Plane.
-
name
¶ The name of this enum value. E.g.
Kind.UCS4.size == "UCS4"
.
-
size
¶ The itemsize of a single character. E.g.
Kind.UCS4.size == 4
.