[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v20210701 06/40] tools: fix Python3.4 TypeError in format string


  • To: Marek Marczykowski-Górecki <marmarek@xxxxxxxxxxxxxxxxxxxxxx>, Olaf Hering <olaf@xxxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Fri, 2 Jul 2021 17:39:54 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PxkcVonICac42Pbf/BOtB1iAtPYZZwEMizz0Pojn5Xs=; b=dqB7GuavQ5hltphivSfSED2D6wA2NOisMq29uLOcl9grBKpIJnH955ZYO3f0o6z7pqT/RqZOYnZvytdoMpSUA3gAuU8kwGfsA3+5vgoTtqxZUavn/vtW1875i2HujBg4XO4AGlMNCFkxQOsTuS2ZaXQDJW+GSScWFxk4lVq+mefa1s9pzMndtsH3K+PC5diKEbYc512KAHmz6zLfJCUUXAITb8stcKHFeqDmGIogkuN904AWygI3nNCrVDX0JhOij6YFJQVfLNQIzS68nGch6MVYNHCN6/QMMbF5AVeNNTjNIx2itTP9nsscLNseaT3LJ/YnmPqJ3dd7LG/yWWbSsw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dGFbQr0/jn0AE2GyCa/iadBmTp0FVWMg0cx3KANoN1L9/ELG8Lo22P0IXgjRQJo8S2SSfOibPy5moFL0m4yvtGk5hz++whJ9dmR8piBdSi6QetT/t3O0Gawvt4+xZdcdiJ7JmXh8x5XtEXx8+NEiEvzvHZsd6XRndywV68t3vHzN14mxoPCLF+whPymWyKvb7EwxgFoUOEBz4OzSEEi7ZNMBksOtukxJdGPNWB5+3QBV8AD+O0Du2OAI43FJBXyH88virPlLR9pq7X3QbZfTN25iTih1RIFu5BJkdKD6IP9XiH+vPuQC2utBbflbCbMpgZq0q1v7KbdNwQ5mCK7N2g==
  • Authentication-results: esa6.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Ian Jackson <iwj@xxxxxxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Fri, 02 Jul 2021 16:40:08 +0000
  • Ironport-hdrordr: A9a23:cgiyBqPF8dnZYsBcTyr155DYdb4zR+YMi2TDiHofdfUFSKClfp 6V8cjztSWUtN4QMEtQ/exoS5PwPk80kqQFnbX5XI3SITUO3VHHEGgM1/qb/9SNIVyZygcZ79 YbT0EcMqyCMbEZt7eC3ODQKb9Jq7PmgcPY8Ns2jU0dKj2CA5sQnzuRYTzrcHGeKjM2YKbRWK Dsnfau8FGbCAUqh4mAdzU4dtmGg+eOuIPtYBYACRJiwA6SjQmw4Lq/NxSDxB8RXx5G3L9nqA H+4kLEz5Tml8v+5g7X1mfV4ZgTsNz9yuFbDMjJrsQOMD3jhiuheYwkcbyfuzIepv2p9T8R4Z bxiiZlG/42x2Laf2mzrxeo8RLnyiwS53jrzkLdqWf/oOTiLQhKSPZptMZ8SF/0+kAgtNZz3O ZgxGSCradaChvGgWDU+8XIbRd3jUC5yEBS0dL7t0YvFLf2VYUh6bD2pChuYdA99WPBmcEa+d BVfYPhDK08SyLdU5ix1VMfsuBFXRwIb1y7qwY5y5WoOgNt7QdEJn0jtYQid0c7heYAoqZ/lp L524RT5ftzp5wtHO9A7Nloe7r/NoWbe2OzDIvVGyW+KJ06
  • Ironport-sdr: AKWCZRCYTFADERGXdBnNoVgL8cG1cUINEViI9ewxcS1f3XMCLff/dXSyBI4O4fn7qtQiorhgEP ozMKJS4GPp7LRG9FIBFThXbZ/kOiAUT/ZlxjtyW/V2XUiyhApogGG+4s7L90Tu/DAb0T/8OBae nhPTMCeN2cw0T1kkeHeWf1494R2xktTLTgQBNSWrUBXKjXidY5xE9ZU3JHdnxD6WTZcuxhT2r9 8eDjvT0gBYDd7epne/8sLGMqpTn4lY/wIXE2Sh8GT1g2k+x3W1m/RJfs6hN+04BI/v+kPLj+Dt qFo=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 02/07/2021 17:19, Marek Marczykowski-Górecki wrote:
> On Thu, Jul 01, 2021 at 11:56:01AM +0200, Olaf Hering wrote:
>> Using the first element of a tuple for a format specifier fails with
>> python3.4 as included in SLE12:
>>     b = b"string/%x" % (i, )
>> TypeError: unsupported operand type(s) for %: 'bytes' and 'tuple'
>>
>> It happens to work with python 2.7 and 3.6.
>> Use a syntax that is handled by all three variants.
>>
>> Signed-off-by: Olaf Hering <olaf@xxxxxxxxx>
>> ---
>>  tools/python/scripts/convert-legacy-stream | 6 +++---
>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/tools/python/scripts/convert-legacy-stream 
>> b/tools/python/scripts/convert-legacy-stream
>> index 9003ac4f6d..235b922ff5 100755
>> --- a/tools/python/scripts/convert-legacy-stream
>> +++ b/tools/python/scripts/convert-legacy-stream
>> @@ -347,9 +347,9 @@ def read_libxl_toolstack(vm, data):
>>          if nil != 0:
>>              raise StreamError("physmap name not NUL terminated")
>>  
>> -        root = b"physmap/%x" % (phys, )
>> -        kv = [root + b"/start_addr", b"%x" % (start, ),
>> -              root + b"/size",       b"%x" % (size, ),
>> +        root = bytes(("physmap/%x" % phys).encode('utf-8'))
>> +        kv = [root + b"/start_addr", bytes(("%x" % start).encode('utf-8')),
>> +              root + b"/size",       bytes(("%x" % size).encode('utf-8')),
> Why bytes()? Encode does already return bytes type.

Yes - I've just tried this out on various version of python (including
https://www.onlinegdb.com/online_python_interpreter which is the only
place I can find Python 3.4 easily available)

.encode() does return bytes (Py3) or str (Py2) so doesn't need the
surrounding bytes().

However, the % (phys, ) with the trailing comma is deliberate to work
around a common python error, so wants to remain if you're keeping the
%-formatting.

~Andrew



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.