From 9b030681893fc24a5eec13cc8b3734810fc5e9f3 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Fri, 6 Jun 2014 07:52:02 -0700 Subject: [PATCH] Remove most of five --- pre_commit/five.py | 68 --------------------------- pre_commit/prefixed_command_runner.py | 7 +-- 2 files changed, 2 insertions(+), 73 deletions(-) diff --git a/pre_commit/five.py b/pre_commit/five.py index e3bab85e..28db863f 100644 --- a/pre_commit/five.py +++ b/pre_commit/five.py @@ -8,71 +8,3 @@ if PY2: text = unicode # flake8: noqa else: text = str - - -def n(obj): - """Produce a native string. - - Similar in behavior to str(), but uses US-ASCII encoding when necessary. - """ - if isinstance(obj, str): - return obj - elif PY2 and isinstance(obj, text): - return obj.encode('US-ASCII') - elif PY3 and isinstance(obj, bytes): - return obj.decode('US-ASCII') - else: - return str(obj) - - -def u(obj): - """Produces text. - - Similar in behavior to str() in python3 or unicode() in python2, - but uses US-ASCII encoding when necessary. - """ - if isinstance(obj, text): - return obj - elif isinstance(obj, bytes): - return obj.decode('US-ASCII') - else: - return text(obj) - - -def b(obj): - """Produces bytes. - - Similar in behavior to bytes(), but uses US-ASCII encoding when necessary. - """ - if isinstance(obj, bytes): - return obj - elif isinstance(obj, text): - return obj.encode('US-ASCII') - else: - return bytes(obj) - - -def udict(*args, **kwargs): - """Similar to dict(), but keyword-keys are text.""" - kwargs = dict([ - (u(key), val) - for key, val in kwargs.items() - ]) - - return dict(*args, **kwargs) - -def ndict(*args, **kwargs): - """Similar to dict(), but keyword-keys are forced to native strings.""" - # I hate this :( - kwargs = dict([ - (n(key), val) - for key, val in kwargs.items() - ]) - - return dict(*args, **kwargs) - -def open(*args, **kwargs): - """Override the builtin open() to return text and use utf8 by default.""" - from io import open - kwargs.setdefault('encoding', 'UTF-8') - return open(*args, **kwargs) diff --git a/pre_commit/prefixed_command_runner.py b/pre_commit/prefixed_command_runner.py index 90678ddb..45acb7f1 100644 --- a/pre_commit/prefixed_command_runner.py +++ b/pre_commit/prefixed_command_runner.py @@ -2,8 +2,6 @@ import os import os.path import subprocess -from pre_commit import five - class CalledProcessError(RuntimeError): def __init__(self, returncode, cmd, expected_returncode, output=None): @@ -70,11 +68,10 @@ class PrefixedCommandRunner(object): replaced_cmd = _replace_cmd(cmd, prefix=self.prefix_dir) proc = self.__popen(replaced_cmd, **popen_kwargs) stdout, stderr = proc.communicate(stdin) - # TODO: stdout, stderr = from_bytes(stdout), from_bytes(stderr) if isinstance(stdout, bytes): - stdout = five.text(stdout, 'utf-8') + stdout = stdout.decode('UTF-8') if isinstance(stderr, bytes): - stderr = five.text(stderr, 'utf-8') + stderr = stderr.decode('UTF-8') returncode = proc.returncode if retcode is not None and retcode != returncode: