code: def toEncoding(self, s, encoding=None):
          
          if isinstance(s, unicode):
              if encoding:
                  s = s.encode(encoding)
          elif isinstance(s, str):
              if encoding:
                  s = s.encode(encoding)
              else:
                  s = unicode(s)
          else:
              if encoding:
                  s  = self.toEncoding(str(s), encoding)
              else:
                  s = unicode(s)
          return s
docs: Encodes an object to a string in some encoding, or to Unicode.
          .