diff options
author | Ćukasz 'sil2100' Zemczak <lukasz.zemczak@ubuntu.com> | 2017-09-04 10:27:07 +0200 |
---|---|---|
committer | usd-importer <ubuntu-server@lists.ubuntu.com> | 2017-09-04 09:38:24 +0000 |
commit | 185ceb32fea5d5c2a43d7b6ee2a40228489055f4 (patch) | |
tree | 2e1c9cc42510c4a922cf63fa265ec0e1945ec14b /azurelinuxagent/common/utils/textutil.py | |
parent | 43bdf9debe5377216aed0086bff2aad864f6ba82 (diff) | |
download | vyos-walinuxagent-185ceb32fea5d5c2a43d7b6ee2a40228489055f4.tar.gz vyos-walinuxagent-185ceb32fea5d5c2a43d7b6ee2a40228489055f4.zip |
Import patches-unapplied version 2.2.16-0ubuntu1 to ubuntu/artful-proposed
Imported using git-ubuntu import.
Changelog parent: 43bdf9debe5377216aed0086bff2aad864f6ba82
New changelog entries:
* New upstream release (LP: #1714299).
Diffstat (limited to 'azurelinuxagent/common/utils/textutil.py')
-rw-r--r-- | azurelinuxagent/common/utils/textutil.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/azurelinuxagent/common/utils/textutil.py b/azurelinuxagent/common/utils/textutil.py index 2d99f6f..7e244fc 100644 --- a/azurelinuxagent/common/utils/textutil.py +++ b/azurelinuxagent/common/utils/textutil.py @@ -19,6 +19,7 @@ import base64 import crypt import random +import re import string import struct import sys @@ -259,6 +260,17 @@ def set_ini_config(config, name, val): config.insert(length - 1, text) +def replace_non_ascii(incoming, replace_char=''): + outgoing = '' + if incoming is not None: + for c in incoming: + if str_to_ord(c) > 128: + outgoing += replace_char + else: + outgoing += c + return outgoing + + def remove_bom(c): ''' bom is comprised of a sequence of three chars,0xef, 0xbb, 0xbf, in case of utf-8. @@ -311,6 +323,16 @@ def safe_shlex_split(s): return shlex.split(s.encode('utf-8')) return shlex.split(s) +def swap_hexstring(s, width=2): + r = len(s) % width + if r != 0: + s = ('0' * (width - (len(s) % width))) + s + + return ''.join(reversed( + re.findall( + r'[a-f0-9]{{{0}}}'.format(width), + s, + re.IGNORECASE))) def parse_json(json_str): """ |