diff martini/config.py @ 17:a42a02bb46ed

py3
author Jeff Hammel <k0scist@gmail.com>
date Mon, 20 Feb 2017 15:11:21 -0800
parents 8ae3a7fd466a
children 81e0743dbe53
line wrap: on
line diff
--- a/martini/config.py	Mon Feb 20 14:56:46 2017 -0800
+++ b/martini/config.py	Mon Feb 20 15:11:21 2017 -0800
@@ -4,7 +4,6 @@
 import sys
 
 
-
 try:
     from collections import OrderedDict
 except ImportError:
@@ -29,16 +28,24 @@
     from io import StringIO
 
 
+try:
+    # python 2
+    string = (str, unicode)
+except:
+    # python 3
+    string = (str,)
+
+
 def file_pointer(resource):
     """returns a file-like object given a string"""
     # XXX could go in utils.py
 
-    if not isinstance(resource, basestring):
+    if not isinstance(resource, string):
         # assume resource is already a file-like object
         return resource
 
     if os.path.exists(resource):
-        return file(resource)
+        return open(resource)
     if sum([resource.startswith(http)
             for http in ('http://', 'https://')]):
         return urlopen(resource)