From 0eb35cbe5096128e4a760aca6842ecdbea5baf1a Mon Sep 17 00:00:00 2001 From: Chirayu Desai Date: Tue, 19 Nov 2013 18:46:29 +0530 Subject: [PATCH] Fix some python3 encoding issues * Add .decode('utf-8') where needed * Add 'b' to `open` where needed, and remove where unnecessary Change-Id: I0f03ecf9ed1a78e3b2f15f9469deb9aaab698657 --- git_command.py | 2 +- git_config.py | 4 ++-- git_refs.py | 2 +- project.py | 2 +- subcmds/sync.py | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/git_command.py b/git_command.py index d347dd61..51f5e3c0 100644 --- a/git_command.py +++ b/git_command.py @@ -86,7 +86,7 @@ class _GitCall(object): global _git_version if _git_version is None: - ver_str = git.version() + ver_str = git.version().decode('utf-8') if ver_str.startswith('git version '): _git_version = tuple( map(int, diff --git a/git_config.py b/git_config.py index a294a0b6..f6093a25 100644 --- a/git_config.py +++ b/git_config.py @@ -304,8 +304,8 @@ class GitConfig(object): d = self._do('--null', '--list') if d is None: return c - for line in d.rstrip('\0').split('\0'): # pylint: disable=W1401 - # Backslash is not anomalous + for line in d.decode('utf-8').rstrip('\0').split('\0'): # pylint: disable=W1401 + # Backslash is not anomalous if '\n' in line: key, val = line.split('\n', 1) else: diff --git a/git_refs.py b/git_refs.py index 4dd68769..3c266061 100644 --- a/git_refs.py +++ b/git_refs.py @@ -100,7 +100,7 @@ class GitRefs(object): def _ReadPackedRefs(self): path = os.path.join(self._gitdir, 'packed-refs') try: - fd = open(path, 'rb') + fd = open(path, 'r') mtime = os.path.getmtime(path) except IOError: return diff --git a/project.py b/project.py index dec21ab1..66316411 100644 --- a/project.py +++ b/project.py @@ -1165,7 +1165,7 @@ class Project(object): last_mine = None cnt_mine = 0 for commit in local_changes: - commit_id, committer_email = commit.split(' ', 1) + commit_id, committer_email = commit.decode('utf-8').split(' ', 1) if committer_email == self.UserEmail: last_mine = commit_id cnt_mine += 1 diff --git a/subcmds/sync.py b/subcmds/sync.py index e9d52b7b..d8aec59b 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py @@ -761,7 +761,7 @@ class _FetchTimes(object): def _Load(self): if self._times is None: try: - f = open(self._path) + f = open(self._path, 'rb') except IOError: self._times = {} return self._times