Apply Python 3 futurize transform libmodernize.fixes.fix_unicode_type

Refer to #256
This commit is contained in:
Eklavya Sharma 2016-03-10 23:16:39 +05:30 committed by Tim Abbott
parent b9e792c4e6
commit 01bfa2d94d
1 changed files with 13 additions and 11 deletions

View File

@ -22,6 +22,8 @@ from __future__ import unicode_literals
from __future__ import print_function
## CC_EMAIL: All review requests will be CC'd here.
from __future__ import absolute_import
import six
CC_EMAIL = 'listname@example.com'
## DOMAIN: Reviewers without an '@' will be assumed to be localparts here.
@ -118,7 +120,7 @@ def get_default_remote(repo):
except TypeError:
return 'origin'
try:
return repo.git.config('--get', ('branch.%s.remote' % unicode(str(branch), "utf-8")).encode("utf-8"))
return repo.git.config('--get', ('branch.%s.remote' % six.text_type(str(branch), "utf-8")).encode("utf-8"))
except git.exc.GitCommandError:
return 'origin'
@ -147,7 +149,7 @@ def parse_revs(repo, opts, args):
def get_current_user(repo):
ident = unicode(repo.git.var('GIT_AUTHOR_IDENT'), 'utf-8', 'replace')
ident = six.text_type(repo.git.var('GIT_AUTHOR_IDENT'), 'utf-8', 'replace')
return ident[:ident.rindex('>') + 1]
def get_current_user_email(repo):
@ -162,7 +164,7 @@ def make_header(repo, opts, revs):
(sha, name) = repo.git.name_rev(revs[-1].hexsha,
refs='refs/remotes/%s/*' % (remote,),
always=True).split()
name = unicode(name, "utf-8")
name = six.text_type(name, "utf-8")
prefix = 'remotes/' + remote + "/"
if name.startswith(prefix):
name = name[len(prefix):]
@ -171,7 +173,7 @@ def make_header(repo, opts, revs):
(_, local_name) = repo.git.name_rev(revs[-1].hexsha,
refs='refs/heads/*',
always=True).split()
local_name = unicode(local_name, "utf-8")
local_name = six.text_type(local_name, "utf-8")
if local_name == "undefined":
print("ERROR: Can't find this commit in remote or identify local branch!", file=sys.stderr)
sys.exit(1)
@ -226,22 +228,22 @@ def write_commitmsg(target, repo, opts, revs):
if opts.format == 'oneline':
for r in revs:
print(unicode(repo.git.log('-n1', '--oneline', r), 'utf-8', 'replace'), file=target)
print(six.text_type(repo.git.log('-n1', '--oneline', r), 'utf-8', 'replace'), file=target)
elif opts.format == 'message' or opts.format is None and len(revs) > 1:
for r in revs:
if opts.first_parent:
print(unicode(repo.git.log('-n1', r), 'utf-8', 'replace'), file=target)
print(unicode(repo.git.diff('--stat', str(r)+'^', r), 'utf-8', 'replace'), file=target)
print(six.text_type(repo.git.log('-n1', r), 'utf-8', 'replace'), file=target)
print(six.text_type(repo.git.diff('--stat', str(r)+'^', r), 'utf-8', 'replace'), file=target)
else:
print(unicode(repo.git.log('-n1', '--stat', r), 'utf-8', 'replace'), file=target)
print(six.text_type(repo.git.log('-n1', '--stat', r), 'utf-8', 'replace'), file=target)
print(file=target)
elif opts.format == 'patch' or opts.format is None and len(revs) == 1:
for r in revs:
if opts.first_parent:
print(unicode(repo.git.log('-n1', r), 'utf-8', 'replace'), file=target)
print(unicode(repo.git.diff('--stat', '-p', str(r)+'^', r), 'utf-8', 'replace'), file=target)
print(six.text_type(repo.git.log('-n1', r), 'utf-8', 'replace'), file=target)
print(six.text_type(repo.git.diff('--stat', '-p', str(r)+'^', r), 'utf-8', 'replace'), file=target)
else:
print(unicode(repo.git.log('-n1', '--stat', '-p', r), 'utf-8', 'replace'), file=target)
print(six.text_type(repo.git.log('-n1', '--stat', '-p', r), 'utf-8', 'replace'), file=target)
print(file=target)
else:
raise Exception("Bad format option.")