Skip to content

Commit

Permalink
Merge pull request #40 from /issues/39
Browse files Browse the repository at this point in the history
fixing clean message
  • Loading branch information
ltamaster authored Dec 5, 2019
2 parents 80c2edf + 40fea70 commit c745ff8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions contents/winrm-exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@
winrm.Session.run_cmd = winrm_session.run_cmd
winrm.Session.run_ps = winrm_session.run_ps
winrm.Session._clean_error_msg = winrm_session._clean_error_msg
winrm.Session._strip_namespace = winrm_session._strip_namespace

tsk = winrm_session.RunCommand(session, shell, exec_command)
t = threading.Thread(target=tsk.get_response)
Expand Down
12 changes: 11 additions & 1 deletion contents/winrm_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import base64
import sys
import types
import re

PY2 = sys.version_info[0] == 2
PY3 = sys.version_info[0] == 3
Expand Down Expand Up @@ -101,6 +102,14 @@ def _clean_error_msg(self, msg):

return msg

def _strip_namespace(self, xml):
"""strips any namespaces from an xml string"""
value = to_bytes(xml)
p = re.compile(b"xmlns=*[\"\"][^\"\"]*[\"\"]")
allmatches = p.finditer(value)
for match in allmatches:
value = value.replace(match.group(), b"")
return value

class Response(object):
"""Response from a remote command execution"""
Expand Down Expand Up @@ -158,4 +167,5 @@ def to_bytes(obj, encoding='utf-8', errors="ignore"):
# Try this first as it's the fastest
return obj.encode(encoding, errors)
except UnicodeEncodeError:
raise
raise

0 comments on commit c745ff8

Please sign in to comment.