hesong.ipsc.busnetcli.utils module

Some helper functions

hesong.ipsc.busnetcli.utils.b2s_recode(bs, source_encoding=None, target_encoding=None)

bytes 字符串重编码为 str 字符串

参数:
  • bs (bytes) – 待转换字节字符串
  • source_encoding (str) – bytes 的编码格式。 默认 utf-8
  • target_encoding (str) – 转换结果字符串的编码格式。 仅 Python2 环境下有效。
返回:

转换结果字符串

返回类型:

str

hesong.ipsc.busnetcli.utils.s2b_recode(s, source_encoding=None, target_encoding=None)

str 字符串重编码为 bytes 字符串

参数:
  • s (str) – 待转换字节字符串
  • source_encoding (str) – bytes 的编码格式。 仅 Python2 环境下有效。
  • target_encoding (str) – 转换结果字符串的编码格式。
返回:

转换结果字符串

返回类型:

bytes

hesong.ipsc.busnetcli.utils.to_bytes(s, encoding='utf-8')

Convert to bytes string.

参数:
  • s – String to convert.
  • encoding (str) – Encoding codec.
返回:

bytes string, it’s bytes or str in Python 2.x, bytes in Python 3.x.

返回类型:

bytes

  • In Python 2, convert s to bytes if it’s unicode.
  • In Python 2, return original s if it’s not unicode.
  • In Python 2, it equals to to_str().
  • In Python 3, convert s to bytes if it’s unicode or str.
  • In Python 3, return original s if it’s neither unicode nor str.
hesong.ipsc.busnetcli.utils.to_str(s, encoding='utf-8')

Convert to str string.

参数:
  • s – String to convert.
  • encoding (str) – Decoding codec.
返回:

str string, it’s bytes in Python 2.x, unicode or str in Python 3.x.

返回类型:

str

  • In Python 2, convert s to str if it’s unicode.
  • In Python 2, return original s if it’s not unicode.
  • In Python 2, it equals to to_bytes().
  • In Python 3, convert s to str if it’s bytes.
  • In Python 3, return original s if it’s not bytes.
  • In Python 3, it equals to to_unicode().
hesong.ipsc.busnetcli.utils.to_unicode(s, encoding='utf-8')

Convert to unicode string.

参数:
  • s – String to convert.
  • encoding (str) – Encoding codec.
返回:

unicode string, it’s unicode in Python 2.x, str or unicode in Python 3.x.

返回类型:

unicode

  • In Python 2, convert s to unicode if it’s str or bytes.
  • In Python 2, return original s if it’s neither str or bytes.
  • In Python 3, convert s to str or unicode if it’s bytes.
  • In Python 3, return original s if it’s not bytes.
  • In Python 3, it equals to to_str().
class hesong.ipsc.busnetcli.utils.LoggerMixin

基类:object

Mixin Class provide a logger property

classmethod get_logger()

logger instance.

返回类型:logging.Logger

logger name format is ModuleName.ClassName

logger

logger instance.

返回类型:logging.Logger

logger name format is ModuleName.ClassName