- improve compatibility with io library (also accept bytearray for write)
- update test for Serial+io
diff --git a/documentation/pyserial_api.rst b/documentation/pyserial_api.rst
index 6b913a5..08f1b45 100644
--- a/documentation/pyserial_api.rst
+++ b/documentation/pyserial_api.rst
@@ -104,8 +104,8 @@
         Write the string *data* to the port.
 
         .. versionchanged:: 2.5
-            Accepts an instance of :class:`bytes` when available (Python 2.6
-            and newer) and :class:`str` otherwiese.
+            Accepts instances of :class:`bytes` and :class:`bytearray` when
+            available (Python 2.6 and newer) and :class:`str` otherwiese.
 
     .. method:: inWaiting()
 
diff --git a/pyserial/examples/test_rawio.py b/pyserial/examples/test_rawio.py
index 674934f..441b37f 100644
--- a/pyserial/examples/test_rawio.py
+++ b/pyserial/examples/test_rawio.py
@@ -12,8 +12,8 @@
 Intended to be run on different platforms, to ensure portability of
 the code.
 
-This modules contains test for RawSerial. This only works on Python 2.6+ with
-the io library.
+This modules contains test for the interaction between Serial and the io
+library. This only works on Python 2.6+ that introduced the io library.
 
 For all these tests a simple hardware is required.
 Loopback HW adapter:
@@ -25,25 +25,36 @@
 On a 9 pole DSUB these are the pins (2-3) (4-6) (7-8)
 """
 
-import unittest, threading, time
+import unittest
+import sys
+import io
 import serial
 
-# on which port should the tests be performed:
-PORT=0
+# trick to make that this test run under 2.6 and 3.x without modification.
+# problem is, io library on 2.6 does NOT accept type 'str' and 3.x doesn't
+# like u'nicode' strings with the prefix and it is not providing an unicode
+# function ('str' is now what 'unicode' used to be)
+if sys.version_info >= (3, 0):
+    def unicode(x): return x
 
-class Test_RawSerial(unittest.TestCase):
+
+# on which port should the tests be performed:
+PORT = 0
+
+class Test_SerialAndIO(unittest.TestCase):
 
     def setUp(self):
-        self.s = serial.RawSerial(PORT)
+        self.s = serial.Serial(PORT, timeout=1)
+        self.io = io.TextIOWrapper(io.BufferedRWPair(self.s, self.s))
 
     def tearDown(self):
         self.s.close()
 
-    def test_hello(self):
-        self.s.write(bytes("hello"))
-        hello = self.s.read(5)
-        #~ print hello
-        self.failUnlessEqual(hello, bytes("hello"))
+    def test_hello_raw(self):
+        self.io.write(unicode("hello\n"))
+        self.io.flush()
+        hello = self.io.readline()
+        self.failUnlessEqual(hello, unicode("hello\n"))
 
 
 if __name__ == '__main__':
diff --git a/pyserial/serial/serialcli.py b/pyserial/serial/serialcli.py
index 5cb76aa..d8eaf1e 100644
--- a/pyserial/serial/serialcli.py
+++ b/pyserial/serial/serialcli.py
@@ -167,8 +167,8 @@
     def write(self, data):
         """Output the given string over the serial port."""
         if not self._port_handle: raise portNotOpenError
-        if not isinstance(data, bytes):
-            raise TypeError('expected %s, got %s' % (bytes, type(data)))
+        if not isinstance(data, (bytes, bytearray)):
+            raise TypeError('expected %s or bytearray, got %s' % (bytes, type(data)))
         try:
             # must call overloaded method with byte array argument
             # as this is the only one not applying encodings
diff --git a/pyserial/serial/serialjava.py b/pyserial/serial/serialjava.py
index 4a0edb3..2541534 100644
--- a/pyserial/serial/serialjava.py
+++ b/pyserial/serial/serialjava.py
@@ -166,8 +166,8 @@
     def write(self, data):
         """Output the given string over the serial port."""
         if not self.sPort: raise portNotOpenError
-        if not isinstance(data, bytes):
-            raise TypeError('expected %s, got %s' % (bytes, type(data)))
+        if not isinstance(data, (bytes, bytearray)):
+            raise TypeError('expected %s or bytearray, got %s' % (bytes, type(data)))
         self._outstream.write(data)
         return len(data)
 
diff --git a/pyserial/serial/serialposix.py b/pyserial/serial/serialposix.py
index c3cc284..bbf7fb9 100644
--- a/pyserial/serial/serialposix.py
+++ b/pyserial/serial/serialposix.py
@@ -462,8 +462,8 @@
     def write(self, data):
         """Output the given string over the serial port."""
         if self.fd is None: raise portNotOpenError
-        if not isinstance(data, bytes):
-            raise TypeError('expected %s, got %s' % (bytes, type(data)))
+        if not isinstance(data, (bytes, bytearray)):
+            raise TypeError('expected %s or bytearray, got %s' % (bytes, type(data)))
         t = len(data)
         d = data
         while t > 0:
diff --git a/pyserial/serial/serialwin32.py b/pyserial/serial/serialwin32.py
index 59572d2..df58e77 100644
--- a/pyserial/serial/serialwin32.py
+++ b/pyserial/serial/serialwin32.py
@@ -240,8 +240,8 @@
     def write(self, data):
         """Output the given string over the serial port."""
         if not self.hComPort: raise portNotOpenError
-        if not isinstance(data, bytes):
-            raise TypeError('expected %s, got %s' % (bytes, type(data)))
+        if not isinstance(data, (bytes, bytearray)):
+            raise TypeError('expected %s or bytearray, got %s' % (bytes, type(data)))
         if data:
             #~ win32event.ResetEvent(self._overlappedWrite.hEvent)
             n = win32.DWORD()