Commits

matt chisholm committed f41523b Draft

repr always returns a string now

  • Participants
  • Parent commits 48a2be7
  • Branches default

Comments (0)

Files changed (2)

File PottyMouth.py

         return self
 
     def __repr__(self):
-        return '%s{%s}'%(self.name, self)
+        return '%s{%s}'%(self.name, super(Token, self).__repr__())
 
     def __add__(self, extra):
-        return Token(self.name, unicode.__add__(self, extra))
+        return Token(self.name, super(Token, self).__add__(extra))
 
     def __str__(self):
         return self.encode(encoding, 'xmlcharrefreplace')
 
 
     def parse(self, string):
+        if isinstance(string, str):
+            string = string.decode(encoding)
+        assert isinstance(string, unicode), "PottyMouth input must be unicode or str types"
         if self.smart_quotes:
             string = self.pre_replace(string)
         tokens = self.tokenize(string)
 #!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
 from difflib import Differ
 from PottyMouth import PottyMouth, Node
 
 ##pstats.strip_dirs()
 ##pstats.sort_stats('time', 'cumulative', 'calls')
 ##pstats.print_stats()
+
+def repr_test():
+    assert repr(w.parse(u"foo • bar")) == "[[[TEXT{u'foo'}, BULLET{u' \u2022 '}, TEXT{u'bar'}]]]"
+    assert repr(w.parse(u"foo • bar".encode('utf8'))) == "[[[TEXT{u'foo'}, BULLET{u' \u2022 '}, TEXT{u'bar'}]]]"
+
+repr_test()