import sys
import hashlib

def e(s):
    if type(s) == str:
        return str
    return s.encode('utf-8')

def d(s):
    if type(s) == unicode:
        return s
    return unicode(s, 'utf-8')

def mkid(s):
    return hashlib.sha1(e(s)).hexdigest()[:2*4]

class Logger(object):
    def __init__(self):
        self._mode = 'INFO'

    def progress(self, message):
        if not sys.stderr.isatty():
            return

        if self._mode == 'PROGRESS':
            print >>sys.stderr, '\r',
        print >>sys.stderr, message,
        self._mode = 'PROGRESS'

    def info(self, message):
        if self._mode == 'PROGRESS':
            print >>sys.stderr

        print >>sys.stderr, message
        self._mode = 'INFO'

import sys
import hashlib

def e(s):
    if type(s) == str:
        return str
    return s.encode('utf-8')

def d(s):
    if type(s) == unicode:
        return s
    return unicode(s, 'utf-8')

def mkid(s):
    return hashlib.sha1(e(s)).hexdigest()[:2*4]

class Logger(object):
    def __init__(self):
        self._mode = 'INFO'

    def progress(self, message):
        message = e(message)
        if not sys.stderr.isatty():
            return

        if self._mode == 'PROGRESS':
            print >>sys.stderr, '\r',
        print >>sys.stderr, message,
        self._mode = 'PROGRESS'

    def info(self, message):
        message = e(message)
        if self._mode == 'PROGRESS':
            print >>sys.stderr

        print >>sys.stderr, message
        self._mode = 'INFO'

Handle logging unicode messages in python2.
Handle logging unicode messages in python2.


Former-commit-id: 257d94eb71d5597ff52a18ec1530d73496901ef4
  import sys
  import hashlib
  
  def e(s):
      if type(s) == str:
          return str
      return s.encode('utf-8')
  
  def d(s):
      if type(s) == unicode:
          return s
      return unicode(s, 'utf-8')
  
  def mkid(s):
      return hashlib.sha1(e(s)).hexdigest()[:2*4]
  
  class Logger(object):
      def __init__(self):
          self._mode = 'INFO'
  
      def progress(self, message):
+         message = e(message)
          if not sys.stderr.isatty():
              return
  
          if self._mode == 'PROGRESS':
              print >>sys.stderr, '\r',
          print >>sys.stderr, message,
          self._mode = 'PROGRESS'
  
      def info(self, message):
+         message = e(message)
          if self._mode == 'PROGRESS':
              print >>sys.stderr
  
          print >>sys.stderr, message
          self._mode = 'INFO'
  
Handle logging unicode messages in python2.
## Code Before:
import sys
import hashlib

def e(s):
    if type(s) == str:
        return str
    return s.encode('utf-8')

def d(s):
    if type(s) == unicode:
        return s
    return unicode(s, 'utf-8')

def mkid(s):
    return hashlib.sha1(e(s)).hexdigest()[:2*4]

class Logger(object):
    def __init__(self):
        self._mode = 'INFO'

    def progress(self, message):
        if not sys.stderr.isatty():
            return

        if self._mode == 'PROGRESS':
            print >>sys.stderr, '\r',
        print >>sys.stderr, message,
        self._mode = 'PROGRESS'

    def info(self, message):
        if self._mode == 'PROGRESS':
            print >>sys.stderr

        print >>sys.stderr, message
        self._mode = 'INFO'

## Instruction:
Handle logging unicode messages in python2.
## Code After:
import sys
import hashlib

def e(s):
    if type(s) == str:
        return str
    return s.encode('utf-8')

def d(s):
    if type(s) == unicode:
        return s
    return unicode(s, 'utf-8')

def mkid(s):
    return hashlib.sha1(e(s)).hexdigest()[:2*4]

class Logger(object):
    def __init__(self):
        self._mode = 'INFO'

    def progress(self, message):
        message = e(message)
        if not sys.stderr.isatty():
            return

        if self._mode == 'PROGRESS':
            print >>sys.stderr, '\r',
        print >>sys.stderr, message,
        self._mode = 'PROGRESS'

    def info(self, message):
        message = e(message)
        if self._mode == 'PROGRESS':
            print >>sys.stderr

        print >>sys.stderr, message
        self._mode = 'INFO'
