summaryrefslogtreecommitdiff
path: root/gbp/scripts/common/pq.py
diff options
context:
space:
mode:
Diffstat (limited to 'gbp/scripts/common/pq.py')
-rw-r--r--gbp/scripts/common/pq.py30
1 files changed, 19 insertions, 11 deletions
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