Commits

Jonathan Eunice  committed e9b7a5b

tweaking for eventual py3 support;

  • Participants
  • Parent commits 3633165

Comments (0)

Files changed (3)

 """
 
 import re
+import six
 
 class NullType(object):
     """
     
 Default = NullType()
 
+def is_string(v):
+    return isinstance(v, six.string_types)    
+
 def stringify(v):
     """
     Return a string. If it's already a string, just return that.
     Otherwise, stringify it. Not safe for Python 3.
     """
-    return v if isinstance(v, basestring) else str(v)
+    return v if is_string(v) else str(v)
 
 class Quoter(object):
     """
         Quote a value in X/HTML style, with optional attributes.
         """
         pstr, mstr = self._whitespace(padding, margin)
-        callatts = self._parse_selector(atts)[1] if isinstance(atts, basestring) else atts or {}
+        callatts = self._parse_selector(atts)[1] if is_string(atts) else atts or {}
         atts = {}
         atts.update(self.atts)
         atts.update(callatts)            
     except KeyError:
         raise ValueError("'{}' is not a known quote style".format(style))
     return quoter(value, **kwargs)
+    # if the kwarg 'chars' is given, should that take precedence over style,
+    # and/or be orthogonal choice vs style?
+    
+# should Quoter be memoized?
     long_description=open('README.rst').read(),
     url='https://bitbucket.org/jeunice/quoter',
     py_modules=['quoter'],
-    install_requires=[],
+    install_requires=['six'],
     classifiers=linelist("""
         Development Status :: 3 - Alpha
         Operating System :: OS Independent

File test/test.py

     doublea = Quoter(chars='<<>>')
     assert doublea('AAA') == '<<AAA>>'
 
-    
 def test_shortcuts():    
     assert ' '.join([qs('one'), qd('two'), qb('and'), qt('three')]) == \
         "'one' \"two\" `and` \"\"\"three\"\"\""