from repugeng.StaticClass import StaticClass
import sys

class Compat3k(StaticClass):
    @classmethod
    def str_to_bytes(cls, s):
        """Convert a string of either width to a byte string."""
        try:
            try:
                return bytes(s)
            except NameError:
                return str(s)
        except ValueError:
            pass #Not ASCII?  Not really a problem...
        except TypeError:
            pass #I didn't specify an encoding?  Oh, boo hoo...
        return s.encode("latin1") #Not utf-8, m'kay...
    @classmethod
    def prompt_user(cls, s="", file=None):
        """Substitute of py2k's raw_input()."""
        (file or sys.stderr).write(s)
        return sys.stdin.readline().rstrip("\r\n")

from repugeng.StaticClass import StaticClass
import sys

class Compat3k(StaticClass):
    @classmethod
    def str_to_bytes(cls, s):
        """Convert a string of either width to a byte string."""
        try:
            try:
                return bytes(s)
            except NameError:
                return str(s)
        except ValueError:
            pass #Not ASCII?  Not really a problem...
        except TypeError:
            pass #I didn't specify an encoding?  Oh, boo hoo...
        return s.encode("latin1") #Not utf-8, m'kay...
    @classmethod
    def prompt_user(cls, s="", file=None):
        """Substitute of py2k's raw_input()."""
        (file or sys.stderr).write(s)
        (file or sys.stderr).flush()
        return sys.stdin.readline().rstrip("\r\n")

Fix yet another 3k issue (stderr not flushing automatically).
Fix yet another 3k issue (stderr not flushing automatically).

Signed-off-by: Thomas Hori <7133b3a0da8e60bd3295f2c8559ef184054a68ed@liddicott.com>

  from repugeng.StaticClass import StaticClass
  import sys
  
  class Compat3k(StaticClass):
      @classmethod
      def str_to_bytes(cls, s):
          """Convert a string of either width to a byte string."""
          try:
              try:
                  return bytes(s)
              except NameError:
                  return str(s)
          except ValueError:
              pass #Not ASCII?  Not really a problem...
          except TypeError:
              pass #I didn't specify an encoding?  Oh, boo hoo...
          return s.encode("latin1") #Not utf-8, m'kay...
      @classmethod
      def prompt_user(cls, s="", file=None):
          """Substitute of py2k's raw_input()."""
          (file or sys.stderr).write(s)
+         (file or sys.stderr).flush()
          return sys.stdin.readline().rstrip("\r\n")
  
Fix yet another 3k issue (stderr not flushing automatically).
## Code Before:
from repugeng.StaticClass import StaticClass
import sys

class Compat3k(StaticClass):
    @classmethod
    def str_to_bytes(cls, s):
        """Convert a string of either width to a byte string."""
        try:
            try:
                return bytes(s)
            except NameError:
                return str(s)
        except ValueError:
            pass #Not ASCII?  Not really a problem...
        except TypeError:
            pass #I didn't specify an encoding?  Oh, boo hoo...
        return s.encode("latin1") #Not utf-8, m'kay...
    @classmethod
    def prompt_user(cls, s="", file=None):
        """Substitute of py2k's raw_input()."""
        (file or sys.stderr).write(s)
        return sys.stdin.readline().rstrip("\r\n")

## Instruction:
Fix yet another 3k issue (stderr not flushing automatically).
## Code After:
from repugeng.StaticClass import StaticClass
import sys

class Compat3k(StaticClass):
    @classmethod
    def str_to_bytes(cls, s):
        """Convert a string of either width to a byte string."""
        try:
            try:
                return bytes(s)
            except NameError:
                return str(s)
        except ValueError:
            pass #Not ASCII?  Not really a problem...
        except TypeError:
            pass #I didn't specify an encoding?  Oh, boo hoo...
        return s.encode("latin1") #Not utf-8, m'kay...
    @classmethod
    def prompt_user(cls, s="", file=None):
        """Substitute of py2k's raw_input()."""
        (file or sys.stderr).write(s)
        (file or sys.stderr).flush()
        return sys.stdin.readline().rstrip("\r\n")
