summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Utils.py
diff options
context:
space:
mode:
authorSol Jerome <sol.jerome@gmail.com>2015-07-22 15:36:23 -0500
committerSol Jerome <sol.jerome@gmail.com>2015-07-22 15:36:23 -0500
commit49ab865657f03795139e95490b1978fcceca2f41 (patch)
treec41beeca523fca354a586ad63c283a9c2133b709 /src/lib/Bcfg2/Utils.py
parentc7e67299381df961ff8274e9b53827c2bddbb47b (diff)
parentb54c32c861b517b889b1cd6c0bbe082b8d93e5d2 (diff)
downloadbcfg2-49ab865657f03795139e95490b1978fcceca2f41.tar.gz
bcfg2-49ab865657f03795139e95490b1978fcceca2f41.tar.bz2
bcfg2-49ab865657f03795139e95490b1978fcceca2f41.zip
Merge branch 'merge-files-ignore-binary' of https://github.com/AlexanderS/bcfg2
Diffstat (limited to 'src/lib/Bcfg2/Utils.py')
-rw-r--r--src/lib/Bcfg2/Utils.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/lib/Bcfg2/Utils.py b/src/lib/Bcfg2/Utils.py
index 10057b63e..64d0d8b93 100644
--- a/src/lib/Bcfg2/Utils.py
+++ b/src/lib/Bcfg2/Utils.py
@@ -330,3 +330,19 @@ class classproperty(object): # pylint: disable=C0103
def __get__(self, instance, owner):
return self.getter(owner)
+
+
+def is_string(strng, encoding):
+ """ Returns true if the string contains no ASCII control
+ characters and can be decoded from the specified encoding. """
+ for char in strng:
+ if ord(char) < 9 or ord(char) > 13 and ord(char) < 32:
+ return False
+ if not hasattr(strng, "decode"):
+ # py3k
+ return True
+ try:
+ strng.decode(encoding)
+ return True
+ except: # pylint: disable=W0702
+ return False