summaryrefslogtreecommitdiff
path: root/azurelinuxagent/common/utils/textutil.py
diff options
context:
space:
mode:
authorƁukasz 'sil2100' Zemczak <lukasz.zemczak@ubuntu.com>2017-01-16 10:10:41 +0100
committerusd-importer <ubuntu-server@lists.ubuntu.com>2017-01-17 17:53:13 +0000
commitd064ab0bffd429382ea4fafeb144784d403848bd (patch)
tree28b0940943acfa742f484c2c0016e8f22c17124c /azurelinuxagent/common/utils/textutil.py
parent63d399807de30a64456e672063e7c20babf7aadc (diff)
downloadvyos-walinuxagent-d064ab0bffd429382ea4fafeb144784d403848bd.tar.gz
vyos-walinuxagent-d064ab0bffd429382ea4fafeb144784d403848bd.zip
Import patches-unapplied version 2.2.2-0ubuntu1 to ubuntu/zesty-proposed
Imported using git-ubuntu import. Changelog parent: 63d399807de30a64456e672063e7c20babf7aadc 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.py41
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()