diff options
author | Ćukasz 'sil2100' Zemczak <lukasz.zemczak@ubuntu.com> | 2017-01-16 10:10:41 +0100 |
---|---|---|
committer | usd-importer <ubuntu-server@lists.ubuntu.com> | 2017-01-17 17:53:13 +0000 |
commit | dd73af563850762aad64e7ed2a9897377830af10 (patch) | |
tree | 33f34ccce29a5a11227741dbe6a8fce20deeeaba /azurelinuxagent/common/utils/textutil.py | |
parent | a05019d9343d0fde153d75a8e61fb6f99d1d3ff3 (diff) | |
parent | 558111e33720eb8f1eaacf571cf4fadae2430286 (diff) | |
download | vyos-walinuxagent-dd73af563850762aad64e7ed2a9897377830af10.tar.gz vyos-walinuxagent-dd73af563850762aad64e7ed2a9897377830af10.zip |
Import patches-applied version 2.2.2-0ubuntu1 to applied/ubuntu/zesty-proposed
Imported using git-ubuntu import.
Changelog parent: a05019d9343d0fde153d75a8e61fb6f99d1d3ff3
Unapplied parent: 558111e33720eb8f1eaacf571cf4fadae2430286
New changelog entries:
* New upstream release (LP: #1651128)
- d/patches/fix-auto-update.patch,
d/patches/lp1623570-adjust-walinuxagent-service-after-and-wants.patch:
- Dropped as changes have been applied upstream
- Refreshed debian/patches/disable_import_test.patch
Diffstat (limited to 'azurelinuxagent/common/utils/textutil.py')
-rw-r--r-- | azurelinuxagent/common/utils/textutil.py | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/azurelinuxagent/common/utils/textutil.py b/azurelinuxagent/common/utils/textutil.py index f03c7e6..59b8fe7 100644 --- a/azurelinuxagent/common/utils/textutil.py +++ b/azurelinuxagent/common/utils/textutil.py @@ -251,8 +251,14 @@ def set_ini_config(config, name, val): def remove_bom(c): - if str_to_ord(c[0]) > 128 and str_to_ord(c[1]) > 128 and \ - str_to_ord(c[2]) > 128: + ''' + bom is comprised of a sequence of three chars,0xef, 0xbb, 0xbf, in case of utf-8. + ''' + if not is_str_none_or_whitespace(c) and \ + len(c) > 2 and \ + str_to_ord(c[0]) > 128 and \ + str_to_ord(c[1]) > 128 and \ + str_to_ord(c[2]) > 128: c = c[3:] return c @@ -277,3 +283,34 @@ def b64encode(s): if PY_VERSION_MAJOR > 2: return base64.b64encode(bytes(s, 'utf-8')).decode('utf-8') return base64.b64encode(s) + + +def b64decode(s): + from azurelinuxagent.common.version import PY_VERSION_MAJOR + if PY_VERSION_MAJOR > 2: + return base64.b64decode(s).decode('utf-8') + return base64.b64decode(s) + + +def safe_shlex_split(s): + import shlex + from azurelinuxagent.common.version import PY_VERSION + if PY_VERSION[:2] == (2, 6): + return shlex.split(s.encode('utf-8')) + return shlex.split(s) + + +def parse_json(json_str): + """ + Parse json string and return a resulting dictionary + """ + # trim null and whitespaces + result = None + if not is_str_none_or_whitespace(json_str): + import json + result = json.loads(json_str.rstrip(' \t\r\n\0')) + + return result + +def is_str_none_or_whitespace(s): + return s is None or len(s) == 0 or s.isspace() |