summaryrefslogtreecommitdiff
path: root/gbp
diff options
context:
space:
mode:
Diffstat (limited to 'gbp')
-rw-r--r--gbp/deb/changelog.py3
-rw-r--r--gbp/git/repository.py10
-rw-r--r--gbp/pkg/__init__.py4
-rw-r--r--gbp/rpm/__init__.py14
-rw-r--r--gbp/scripts/common/buildpackage.py2
-rw-r--r--gbp/scripts/common/pq.py30
6 files changed, 35 insertions, 28 deletions
diff --git a/gbp/deb/changelog.py b/gbp/deb/changelog.py
index a670332e..912c13ce 100644
--- a/gbp/deb/changelog.py
+++ b/gbp/deb/changelog.py
@@ -93,12 +93,13 @@ class ChangeLog(object):
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
- (output, errors) = cmd.communicate(self._contents.encode('utf-8'))
+ (output, errors) = cmd.communicate(self._contents.encode())
if cmd.returncode:
raise ParseChangeLogError("Failed to parse changelog. "
"dpkg-parsechangelog said:\n%s" % errors.decode().strip())
# Parse the result of dpkg-parsechangelog (which looks like
# email headers)
+ output = output.decode()
cp = email.message_from_string(output)
try:
if ':' in cp['Version']:
diff --git a/gbp/git/repository.py b/gbp/git/repository.py
index d52d5c96..cb1b041b 100644
--- a/gbp/git/repository.py
+++ b/gbp/git/repository.py
@@ -144,7 +144,7 @@ class GitRepository(object):
@param cwd: directory to swith to when running the command, defaults to I{self.path}
@type cwd: C{str}
@return: stdout, return code
- @rtype: C{tuple} of C{list} of C{str} and C{int}
+ @rtype: C{tuple} of C{list} of C{bytestr} and C{int}
@deprecated: use L{gbp.git.repository.GitRepository._git_inout} instead.
"""
@@ -178,7 +178,7 @@ class GitRepository(object):
@param capture_stderr: whether to capture stderr
@type capture_stderr: C{bool}
@return: stdout, stderr, return code
- @rtype: C{tuple} of C{str}, C{str}, C{int}
+ @rtype: C{tuple} of C{bytestr}, C{bytestr}, C{int}
"""
if not cwd:
cwd = self.path
@@ -960,7 +960,7 @@ class GitRepository(object):
# Expect to have two filenames for renames and copies
if status[0] in ['R', 'C']:
filepath = elements.pop(0) + b'\x00' + filepath
- result[status].append(filepath)
+ result[status].append(filepath.decode())
return result
@@ -1750,7 +1750,7 @@ class GitRepository(object):
while len(file_fields) and file_fields[0] != b'':
status = file_fields.pop(0).decode().strip()
path = file_fields.pop(0)
- files[status].append(path)
+ files[status].append(path.decode())
return {'id': commitish,
'author': author,
@@ -1862,7 +1862,7 @@ class GitRepository(object):
if status in ['R', 'C']:
result[status].append(filepath)
filepath = elements.pop(0)
- result[status].append(filepath)
+ result[status].append(filepath.decode())
return result
#}
diff --git a/gbp/pkg/__init__.py b/gbp/pkg/__init__.py
index 11032499..ee46ccb5 100644
--- a/gbp/pkg/__init__.py
+++ b/gbp/pkg/__init__.py
@@ -336,8 +336,6 @@ class UpstreamSource(object):
"""
topdir_files = set()
for typ, path in file_list:
- #path is byte type, not str.
- path = path.decode()
split = re.sub('^(?:./|../)*', '', path).split('/')
if len(split) == 1:
topdir_files.add((typ, path))
@@ -366,7 +364,7 @@ class UpstreamSource(object):
raise GbpError("Listing tar archive content failed")
for line in out.splitlines():
fields = line.split(None, 5)
- files.append((fields[0][0], fields[-1]))
+ files.append((fields[0][0], fields[-1].decode()))
else:
raise GbpError("Unsupported archive format %s, unable to "
"determine prefix for '%s'" %
diff --git a/gbp/rpm/__init__.py b/gbp/rpm/__init__.py
index 0affa457..54e9e6a9 100644
--- a/gbp/rpm/__init__.py
+++ b/gbp/rpm/__init__.py
@@ -485,7 +485,7 @@ class SpecFile(object):
indent_re = re.compile(r'^([a-z]+([0-9]+)?\s*:\s*)', flags=re.I)
match = indent_re.match(str(insertafter))
if not match:
- match = indent_re.match(str(insertafter.__next__))
+ match = indent_re.match(str(insertafter.next))
indent = 12 if not match else len(match.group(1))
text = '%-*s%s\n' % (indent, '%s:' % tagname, value)
if key in self._tags:
@@ -579,11 +579,11 @@ class SpecFile(object):
"which to update" % name)
line = self._special_directives[name][0]['line']
gbp.log.debug("Removing content of %s section" % name)
- while line.__next__:
- match = self.directive_re.match(str(line.__next__))
+ while line.next:
+ match = self.directive_re.match(str(line.next))
if match and match.group('name') in self.section_identifiers:
break
- self._content.delete(line.__next__)
+ self._content.delete(line.next)
else:
gbp.log.debug("Adding %s section to the end of spec file" % name)
line = self._content.append('%%%s\n' % name)
@@ -603,8 +603,8 @@ class SpecFile(object):
text = ''
if 'changelog' in self._special_directives:
line = self._special_directives['changelog'][0]['line']
- while line.__next__:
- line = line.__next__
+ while line.next:
+ line = line.next
match = self.directive_re.match(str(line))
if match and match.group('name') in self.section_identifiers:
break
@@ -631,7 +631,7 @@ class SpecFile(object):
if not macro['id'] in ignored:
macro_prev = self._delete_special_macro('patch', macro['id'])
# Remove surrounding if-else
- macro_next = macro_prev.__next__
+ macro_next = macro_prev.next
if (str(macro_prev).startswith('%if') and
str(macro_next).startswith('%endif')):
self._content.delete(macro_next)
diff --git a/gbp/scripts/common/buildpackage.py b/gbp/scripts/common/buildpackage.py
index 12eede9e..df65826e 100644
--- a/gbp/scripts/common/buildpackage.py
+++ b/gbp/scripts/common/buildpackage.py
@@ -150,7 +150,7 @@ def dump_tree(repo, export_dir, treeish, with_submodules, recursive=True):
if recursive:
paths = ''
else:
- paths = ["'%s'" % nam.decode() for _mod, typ, _sha, nam in
+ paths = ['%s' % nam.decode() for _mod, typ, _sha, nam in
repo.list_tree(treeish) if typ == 'blob']
try:
diff --git a/gbp/scripts/common/pq.py b/gbp/scripts/common/pq.py
index 05993d1d..bd49e94d 100644
--- a/gbp/scripts/common/pq.py
+++ b/gbp/scripts/common/pq.py
@@ -28,6 +28,7 @@ import time
from email.message import Message
from email.header import Header
from email.charset import Charset, QP
+from email.policy import Compat32
from gbp.git import GitRepositoryError
from gbp.git.modifier import GitModifier, GitTz
@@ -182,7 +183,6 @@ def patch_path_filter(file_status, exclude_regex=None):
include_paths = []
for file_list in list(file_status.values()):
for fname in file_list:
- fname = fname.decode()
if not re.match(exclude_regex, fname):
include_paths.append(fname)
else:
@@ -209,27 +209,35 @@ def write_patch_file(filename, commit_info, diff):
# Git compat: put name in quotes if special characters found
if re.search("[,.@()\[\]\\\:;]", name):
name = '"%s"' % name
- from_header = Header(name.encode('utf-8'), charset, 77, 'from')
- from_header.append(email.encode('utf-8'))
+ from_header = Header(header_name='from')
+ try:
+ from_header.append(name, 'us-ascii')
+ except UnicodeDecodeError:
+ from_header.append(name, charset)
+ from_header.append('<%s>' % email)
msg['From'] = from_header
date = commit_info['author'].datetime
datestr = date.strftime('%a, %-d %b %Y %H:%M:%S %z')
- msg['Date'] = Header(datestr.encode('utf-8'), charset, 77, 'date')
- msg['Subject'] = Header(commit_info['subject'].encode('utf-8'),
- charset, 77, 'subject')
+ msg['Date'] = Header(datestr, 'us-ascii', 'date')
+ subject_header = Header(header_name='subject')
+ try:
+ subject_header.append(commit_info['subject'], 'us-ascii')
+ except UnicodeDecodeError:
+ subject_header.append(commit_info['subject'], charset)
+ msg['Subject'] = subject_header
# Write message body
if commit_info['body']:
# Strip extra linefeeds
body = commit_info['body'].rstrip() + '\n'
try:
- msg.set_payload(body.encode('ascii'))
- except UnicodeDecodeError:
+ msg.set_payload(body.encode('us-ascii'))
+ except UnicodeEncodeError:
msg.set_payload(body, charset)
- patch.write(msg.as_string(unixfrom=False).encode('utf-8'))
-
+ policy = Compat32(max_line_length=77)
+ patch.write(msg.as_bytes(unixfrom=False, policy=policy))
# Write diff
patch.write(b'---\n')
- patch.write(diff.encode())
+ patch.write(diff)
except IOError as err:
raise GbpError('Unable to create patch file: %s' % err)
return filename