Cnv class

class crsysapi.Cnv

Character conversion routines.

static frombase64(s)

Decode a base64-encoded string into a byte array.

Parameters:

s (str) -- Base64-encoded data

Returns:

Binary data in byte array.

Return type:

bytes

Note

Whitespace characters are ignored, but other non-base64 characters will cause an error.

static fromhex(s)

Decode a hexadecimal-encoded string into a byte array.

Parameters:

s (str) -- Hex-encoded string

Returns:

Binary data in byte array.

Return type:

bytes

Note

Whitespace and ASCII punctuation characters in the input are ignored, but other non-hex characters, e.g. [G-Zg-z], will cause an error.

Examples

>>> Cnv.fromhex("61:62:63")
'abc'
static shortpathname(pathName)

Retrieve the Windows short path form of the specified path.

Parameters:

pathName (str) -- Path name.

Returns:

Windows short path name of file or empty string if file does not exist.

Return type:

str

Note

Windows only. The file path must exist. The short path name is guaranteed to be ASCII and can be used as a filename argument in any function in this Toolkit.

Example

>>> Cnv.shortpathname("work/你好.txt")
'work/FC0F~1.TXT'
static tobase64(data)

Encode binary data as a base64 string.

Parameters:

data (bytes) -- binary data to be encoded.

Returns:

Base64-encoded string.

Return type:

str

Example

>>> Cnv.tobase64(Cnv.fromhex('fedcba9876543210'))
'/ty6mHZUMhA='
static tohex(data)

Encode binary data as a hexadecimal string.

Parameters:

data (bytes) -- binary data to be encoded.

Returns:

Hex-encoded string. Letters [A-F] are in uppercase. Use s.lower() for lowercase.

Return type:

str

Examples

>>> Cnv.tohex(b"abcé")
'616263E9'
>>> Cnv.tohex(bytearray([0xde, 0xad, 0xbe, 0xef])).lower()
'deadbeef'