add an iterbytes helper function
diff --git a/serial/rfc2217.py b/serial/rfc2217.py
index 8776f09..9c5d68b 100644
--- a/serial/rfc2217.py
+++ b/serial/rfc2217.py
@@ -706,9 +706,7 @@
                         self.logger.debug("socket error in reader thread: %s" % (e,))
                     break
                 if not data: break # lost connection
-                #~ for byte in data:    # fails for python3 as it returns ints instead of b''
-                for x in range(len(data)):
-                    byte = data[x:x+1]
+                for byte in iterbytes(data):
                     if mode == M_NORMAL:
                         # interpret as command or as data
                         if byte == IAC:
@@ -1031,9 +1029,7 @@
 
         (socket error handling code left as exercise for the reader)
         """
-        #~ for byte in data:    # XXX fails for python3 as it returns ints instead of bytes
-        for x in range(len(data)):
-            byte = data[x:x+1]
+        for byte in iterbytes(data):
             if self.mode == M_NORMAL:
                 # interpret as command or as data
                 if byte == IAC:
diff --git a/serial/serialutil.py b/serial/serialutil.py
index a71bd37..e20196d 100644
--- a/serial/serialutil.py
+++ b/serial/serialutil.py
@@ -22,6 +22,16 @@
         pass
 
 
+# "for byte in data" fails for python3 as it returns ints instead of bytes
+def iterbytes(b):
+    """Iterate over bytes, returning bytes instead of ints (python3)"""
+    x = 0
+    a = True
+    while a:
+        a = b[x:x+1]
+        x += 1
+        yield a
+        
 # all Python versions prior 3.x convert ``str([17])`` to '[17]' instead of '\x11'
 # so a simple ``bytes(sequence)`` doesn't work for all versions
 def to_bytes(seq):
diff --git a/serial/urlhandler/protocol_loop.py b/serial/urlhandler/protocol_loop.py
index 02f30df..02167e5 100644
--- a/serial/urlhandler/protocol_loop.py
+++ b/serial/urlhandler/protocol_loop.py
@@ -174,9 +174,7 @@
         if self._writeTimeout is not None and time_used_to_send > self._writeTimeout:
             time.sleep(self._writeTimeout) # must wait so that unit test succeeds
             raise writeTimeoutError
-        #~ for byte in data:    # fails for python3 as it returns ints instead of b''
-        for x in range(len(data)):
-            byte = data[x:x+1]
+        for byte in iterbytes(data):
             self.queue.put(byte, timeout=self._writeTimeout)
         return len(data)