Mercurial > hg > MakeItSo
changeset 268:64979cfff465 default tip
some py3 fixes
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Tue, 29 May 2018 15:28:41 -0700 |
parents | 7e3a32f2794a |
children | |
files | makeitso/makeitso.py |
diffstat | 1 files changed, 18 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/makeitso/makeitso.py Fri Apr 27 14:07:46 2018 -0700 +++ b/makeitso/makeitso.py Tue May 29 15:28:41 2018 -0700 @@ -16,7 +16,21 @@ import urllib # TODO: may have to use urllib2.urlopen to get reasonable timeouts -from ConfigParser import RawConfigParser +try: + # python 2 + from ConfigParser import RawConfigParser +except ImportError: + # python 3 + from configparser import RawConfigParser + +try: + # python 2 + string = (unicode, str) +except NameError: + # python 3 + string = (str,) + + from optparse import OptionParser # URL of -this file- @@ -214,7 +228,7 @@ # write output output = output or sys.stdout - if isinstance(output, basestring): + if isinstance(output, string): path = output if os.path.isdir(output): path = os.path.join(path, basename(self.name)) @@ -329,7 +343,7 @@ self.templates = [] entry_points = get_entry_points() for template in templates: - if isinstance(template, basestring): + if isinstance(template, string): # TODO: check if the template is a [e.g] PasteScript.template entry point if os.path.isdir(template): self.templates.append(DirectoryTemplate(template, interactive=self.interactive, variables=variables)) @@ -357,7 +371,7 @@ return missing def check_output(self, output): - if output and isinstance(output, basestring) and os.path.exists(output) and len(self.templates) > 1: + if output and isinstance(output, string) and os.path.exists(output) and len(self.templates) > 1: assert os.path.isdir(output), "Must specify a directory for multiple templates" for template in self.templates: if hasattr(template, 'check_output'):