Repository: johnpaulett/python-hl7

Issue:
Buggy ASCII escaping
If you escape a string containing any ASCII characters, this will lead to a `TypeError`:

``` python
import hl7

msg = hl7.Message(separator='\r', separators='\r|^~\&')
msg.escape('asdf')
```

``` plain
Traceback (most recent call last):
  File "hl7/__init__.py", line 630, in escape
    return ''.join(rv)
TypeError: sequence item 0: expected str instance, bytes found
```


Discussion:

Patch:
diff --git a/hl7/containers.py b/hl7/containers.py
index 231e3b1..a57f570 100644
--- a/hl7/containers.py
+++ b/hl7/containers.py
@@ -319,7 +319,7 @@ class Message(Container):
             elif c in DEFAULT_MAP:
                 rv.append(esc + DEFAULT_MAP[c] + esc)
             elif ord(c) >= 0x20 and ord(c) <= 0x7E:
-                rv.append(c.encode('ascii'))
+                rv.append(c)
             else:
                 rv.append('%sX%2x%s' % (esc, ord(c), esc))
 


Test patch:
diff --git a/tests/test_parse.py b/tests/test_parse.py
index e7ad1d4..dfed995 100644
--- a/tests/test_parse.py
+++ b/tests/test_parse.py
@@ -172,13 +172,19 @@ class ParseTest(unittest.TestCase):
     def test_escape(self):
         msg = hl7.parse(rep_sample_hl7)
 
+        # Escape Separators
         self.assertEqual(msg.escape('\\'), '\\E\\')
         self.assertEqual(msg.escape('|'), '\\F\\')
         self.assertEqual(msg.escape('^'), '\\S\\')
         self.assertEqual(msg.escape('&'), '\\T\\')
         self.assertEqual(msg.escape('~'), '\\R\\')
 
+        # Escape ASCII characters
+        self.assertEqual(msg.escape('asdf'), 'asdf')
+
+        # Escape non-ASCII characters
         self.assertEqual(msg.escape('áéíóú'), '\\Xe1\\\\Xe9\\\\Xed\\\\Xf3\\\\Xfa\\')
+        self.assertEqual(msg.escape('äsdf'), '\\Xe4\\sdf')
 
     def test_file(self):
         # Extract message from file