summaryrefslogtreecommitdiffstats
path: root/src/lib/Client/Tools/POSIX.py
diff options
context:
space:
mode:
authorSol Jerome <sol.jerome@gmail.com>2011-06-06 18:27:24 -0500
committerSol Jerome <sol.jerome@gmail.com>2011-06-06 18:27:24 -0500
commit05c0d709111ca27ca53b1a1b08735c9c081af6ac (patch)
tree90156f52fb50ee2c1d2868187ac520cf3e66ad07 /src/lib/Client/Tools/POSIX.py
parent95797b788dc180b240e0c1c17f2559fbb4600b5b (diff)
parent8c497c815589c7c5878490df7661c6f5d3330829 (diff)
downloadbcfg2-05c0d709111ca27ca53b1a1b08735c9c081af6ac.tar.gz
bcfg2-05c0d709111ca27ca53b1a1b08735c9c081af6ac.tar.bz2
bcfg2-05c0d709111ca27ca53b1a1b08735c9c081af6ac.zip
Merge branch 'non-ascii-diffs' of https://github.com/weiss/bcfg2
Diffstat (limited to 'src/lib/Client/Tools/POSIX.py')
-rw-r--r--src/lib/Client/Tools/POSIX.py28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/lib/Client/Tools/POSIX.py b/src/lib/Client/Tools/POSIX.py
index 875db5ea7..862e0bc04 100644
--- a/src/lib/Client/Tools/POSIX.py
+++ b/src/lib/Client/Tools/POSIX.py
@@ -76,6 +76,21 @@ def normUid(entry):
return False
+def isString(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
+ try:
+ strng.decode(encoding)
+ return True
+ except:
+ return False
+
+
class POSIX(Bcfg2.Client.Tools.Tool):
"""POSIX File support code."""
name = 'POSIX'
@@ -458,12 +473,7 @@ class POSIX(Bcfg2.Client.Tools.Tool):
# md5sum so it would be faster for big binary files
contentStatus = content == tempdata
if not contentStatus:
- try:
- content.decode('ascii')
- isstring = True
- except:
- isstring = False
- if tbin or not isstring:
+ if tbin or not isString(content, self.setup['encoding']):
entry.set('current_bfile', binascii.b2a_base64(content))
nqtext = entry.get('qtext', '')
nqtext += '\nBinary file, no printable diff'
@@ -493,15 +503,15 @@ class POSIX(Bcfg2.Client.Tools.Tool):
difflib.unified_diff(content.split('\n'), \
tempdata.split('\n'))])
try:
- eudiff = udiff.encode('ascii')
+ dudiff = udiff.decode(self.setup['encoding'])
except:
- eudiff = "Binary file: no diff printed"
+ dudiff = "Binary file: no diff printed"
nqtext = entry.get('qtext', '')
if nqtext:
nqtext += '\n'
- nqtext += eudiff
+ nqtext += dudiff
else:
entry.set('current_bfile', binascii.b2a_base64(content))
nqtext = entry.get('qtext', '')