bag.io.common
This module contains some commonly used IO functions.
In particular, this module keeps track of BAG’s system-wide encoding/decoding settings.
Module Contents
Functions
|
Fix the given potential string object to ensure python 2/3 compatibility. |
|
Convert the given string to raw bytes. |
|
Sets the BAG input/output encoding. |
Returns the BAG input/output encoding. |
|
|
Sets the error policy on encoding/decoding errors. |
Returns the current BAG encoding/decoding error policy. |
Attributes
- bag.io.common.fix_string(obj)[source]
Fix the given potential string object to ensure python 2/3 compatibility.
If the given object is raw bytes, decode it into a string using current encoding and return it. Otherwise, just return the given object.
This method is useful for writing python 2/3 compatible code.
- Parameters:
obj – any python object.
- Returns:
the given object, or a decoded string if the given object is bytes.
- Return type:
val
- bag.io.common.to_bytes(my_str)[source]
Convert the given string to raw bytes.
- Parameters:
my_str (string) – the string to encode to bytes.
- Returns:
val – raw bytes of the string.
- Return type:
- bag.io.common.set_encoding(new_encoding)[source]
Sets the BAG input/output encoding.
- Parameters:
new_encoding (string) – the new encoding name.
- bag.io.common.get_encoding()[source]
Returns the BAG input/output encoding.
- Returns:
bag_encoding – the encoding name.
- Return type:
unicode