Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pkg/private/deb/make_deb.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,10 @@ def CreateDebControl(extrafiles=None, **kwargs):
if extrafiles:
for name, (data, mode) in extrafiles.items():
tarinfo = tarfile.TarInfo('./' + name)
data_encoded = data.encode('utf-8')
if type(data) == type(b''):
data_encoded = data
else:
data_encoded = data.encode('utf-8')
tarinfo.size = len(data_encoded)
tarinfo.mode = mode
f.addfile(tarinfo, fileobj=io.BytesIO(data_encoded))
Expand Down
50 changes: 32 additions & 18 deletions pkg/private/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def SplitNameValuePairAtSeparator(arg, sep):
# if we leave the loop, the character sep was not found unquoted
return (head, '')

def GetFlagValue(flagvalue, strip=True):
def GetFlagValue(flagvalue, strip=True, encoding='utf-8'):
"""Converts a raw flag string to a useable value.

1. Expand @filename style flags to the content of filename.
Expand All @@ -68,22 +68,36 @@ def GetFlagValue(flagvalue, strip=True):
Python2: unicode
Python3: str
"""
if flagvalue:
if sys.version_info[0] < 3:
# python2 gives us raw bytes in argv.
flagvalue = flagvalue.decode('utf-8')
# assertion: py2: flagvalue is unicode
# assertion: py3: flagvalue is str, but in weird format
if flagvalue[0] == '@':
# Subtle: We do not want to re-encode the value here, because it
# is encoded in the right format for file open operations.
with open(flagvalue[1:], 'rb') as f:
flagvalue = f.read().decode('utf-8')

if flagvalue is None:
return None

if flagvalue and (sys.version_info[0] < 3):
# python2 gives us raw bytes in argv.
flagvalue = flagvalue.decode('utf-8')

# assertion: py2: flagvalue is unicode
# assertion: py3: flagvalue is str, but in weird format

if not flagvalue:
data = b''
elif flagvalue[0] == '@':
with open(flagvalue[1:], 'rb') as f:
data = f.read()
else:
# Convert fs specific encoding back to proper unicode.
if sys.version_info[0] > 2:
data = os.fsencode(flagvalue)
else:
# convert fs specific encoding back to proper unicode.
if sys.version_info[0] > 2:
flagvalue = os.fsencode(flagvalue).decode('utf-8')
data = flagvalue.encode('utf-8')

# assertion: data is byte array.

if not encoding:
return data

value = data.decode(encoding)

if strip:
return flagvalue.strip()
return flagvalue
if strip:
return value.strip()
return value
Loading