From 086c9c2d7d7b96d6cc476f1b94373b9ad77d2fa9 Mon Sep 17 00:00:00 2001
From: Mike Naberezny <mike@naberezny.com>
Date: Sat, 26 Oct 2013 15:15:51 -0700
Subject: [PATCH] Fix imports for Python 3

---
 py65/monitor.py            | 12 ++++++++----
 py65/tests/test_monitor.py |  6 +++++-
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/py65/monitor.py b/py65/monitor.py
index 51c87a6..7d91eb6 100644
--- a/py65/monitor.py
+++ b/py65/monitor.py
@@ -18,7 +18,7 @@ import os
 import re
 import shlex
 import sys
-import urllib2
+
 from asyncore import compact_traceback
 from py65.devices.mpu6502 import MPU as NMOS6502
 from py65.devices.mpu65c02 import MPU as CMOS65C02
@@ -30,6 +30,10 @@ from py65.utils import console
 from py65.utils.conversions import itoa
 from py65.memory import ObservableMemory
 
+try:
+    from urllib2 import urlopen
+except ImportError: # Python 3
+    from urllib.request import urlopen
 
 class Monitor(cmd.Cmd):
 
@@ -545,11 +549,11 @@ class Monitor(cmd.Cmd):
 
         if "://" in filename:
             try:
-                f = urllib2.urlopen(filename)
+                f = urlopen(filename)
                 bytes = f.read()
                 f.close()
-            except (urllib2.URLError, urllib2.HTTPError) as exc:
-                msg = "Cannot fetch remote file: %s" % exc.message
+            except Exception as exc:
+                msg = "Cannot fetch remote file: %s" % str(exc)
                 self._output(msg)
                 return
         else:
diff --git a/py65/tests/test_monitor.py b/py65/tests/test_monitor.py
index 54b42ad..5884631 100644
--- a/py65/tests/test_monitor.py
+++ b/py65/tests/test_monitor.py
@@ -4,7 +4,11 @@ import re
 import os
 import tempfile
 from py65.monitor import Monitor
-from StringIO import StringIO
+
+try:
+    from StringIO import StringIO
+except ImportError: # Python 3
+    from io import StringIO
 
 
 class MonitorTests(unittest.TestCase):